@azure/communication-chat 1.6.0-alpha.20240607.1 → 1.6.0-beta.2
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/index.js +836 -46
- package/dist/index.js.map +1 -1
- package/dist-esm/src/chatClient.js +4 -3
- package/dist-esm/src/chatClient.js.map +1 -1
- package/dist-esm/src/chatThreadClient.js +84 -4
- package/dist-esm/src/chatThreadClient.js.map +1 -1
- package/dist-esm/src/generated/src/chatApiClient.js +2 -2
- package/dist-esm/src/generated/src/chatApiClient.js.map +1 -1
- package/dist-esm/src/generated/src/models/index.js +8 -0
- package/dist-esm/src/generated/src/models/index.js.map +1 -1
- package/dist-esm/src/generated/src/models/mappers.js +298 -30
- package/dist-esm/src/generated/src/models/mappers.js.map +1 -1
- package/dist-esm/src/generated/src/models/parameters.js +73 -1
- package/dist-esm/src/generated/src/models/parameters.js.map +1 -1
- package/dist-esm/src/generated/src/operations/chatThread.js +98 -0
- package/dist-esm/src/generated/src/operations/chatThread.js.map +1 -1
- package/dist-esm/src/generated/src/operationsInterfaces/chatThread.js.map +1 -1
- package/dist-esm/src/generated/src/tracing.js +1 -1
- package/dist-esm/src/generated/src/tracing.js.map +1 -1
- package/dist-esm/src/models/mappers.js +82 -6
- package/dist-esm/src/models/mappers.js.map +1 -1
- package/dist-esm/src/models/models.js.map +1 -1
- package/dist-esm/src/models/options.js.map +1 -1
- package/dist-esm/src/xhrHttpClient.js +186 -0
- package/dist-esm/src/xhrHttpClient.js.map +1 -0
- package/package.json +4 -4
- package/types/communication-chat.d.ts +129 -4
package/dist/index.js
CHANGED
|
@@ -3,14 +3,15 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var tslib = require('tslib');
|
|
6
|
-
var communicationSignaling = require('@azure/communication-signaling');
|
|
7
6
|
var communicationCommon = require('@azure/communication-common');
|
|
8
7
|
var logger$1 = require('@azure/logger');
|
|
8
|
+
var abortController = require('@azure/abort-controller');
|
|
9
9
|
var coreRestPipeline = require('@azure/core-rest-pipeline');
|
|
10
10
|
var coreTracing = require('@azure/core-tracing');
|
|
11
11
|
var coreClient = require('@azure/core-client');
|
|
12
12
|
var events = require('events');
|
|
13
13
|
var uuid = require('uuid');
|
|
14
|
+
var communicationSignaling = require('@azure/communication-signaling');
|
|
14
15
|
|
|
15
16
|
function _interopNamespaceDefault(e) {
|
|
16
17
|
var n = Object.create(null);
|
|
@@ -55,6 +56,41 @@ const mapToAddChatParticipantsRequestRestModel = (addParticipantsRequest) => {
|
|
|
55
56
|
participants: (_a = addParticipantsRequest.participants) === null || _a === void 0 ? void 0 : _a.map((participant) => mapToChatParticipantRestModel(participant)),
|
|
56
57
|
};
|
|
57
58
|
};
|
|
59
|
+
/**
|
|
60
|
+
* @internal
|
|
61
|
+
* Mapping chat attachment SDK model to chat attachment REST model
|
|
62
|
+
*/
|
|
63
|
+
const mapToChatAttachmentRestModel = (chatAttachment) => {
|
|
64
|
+
const { attachmentType } = chatAttachment, rest = tslib.__rest(chatAttachment, ["attachmentType"]);
|
|
65
|
+
if (attachmentType === "unknown") {
|
|
66
|
+
throw new Error("'unknown' attachmentType not supported");
|
|
67
|
+
}
|
|
68
|
+
return Object.assign(Object.assign({}, rest), { attachmentType: attachmentType });
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* @internal
|
|
72
|
+
* Mapping send message request and options to send chat message request REST model
|
|
73
|
+
*/
|
|
74
|
+
const mapToSendChatMessageRequestRestModel = (sendMessageRequest, sendMessageOptions) => {
|
|
75
|
+
const { attachments } = sendMessageOptions, restOptions = tslib.__rest(sendMessageOptions, ["attachments"]);
|
|
76
|
+
let request = Object.assign(Object.assign({}, sendMessageRequest), restOptions);
|
|
77
|
+
if (attachments) {
|
|
78
|
+
request = Object.assign(Object.assign({}, request), { attachments: attachments === null || attachments === void 0 ? void 0 : attachments.map((attachment) => mapToChatAttachmentRestModel(attachment)) });
|
|
79
|
+
}
|
|
80
|
+
return request;
|
|
81
|
+
};
|
|
82
|
+
/**
|
|
83
|
+
* @internal
|
|
84
|
+
* Mapping update message options to update chat message request REST model
|
|
85
|
+
*/
|
|
86
|
+
const mapToUpdateChatMessageRequestRestModel = (updateMessageOptions) => {
|
|
87
|
+
const { attachments } = updateMessageOptions, restOptions = tslib.__rest(updateMessageOptions, ["attachments"]);
|
|
88
|
+
let request = Object.assign({}, restOptions);
|
|
89
|
+
if (attachments) {
|
|
90
|
+
request = Object.assign(Object.assign({}, request), { attachments: attachments === null || attachments === void 0 ? void 0 : attachments.map((attachment) => mapToChatAttachmentRestModel(attachment)) });
|
|
91
|
+
}
|
|
92
|
+
return request;
|
|
93
|
+
};
|
|
58
94
|
/**
|
|
59
95
|
* @internal
|
|
60
96
|
* Mapping chat participant REST model to chat participant SDK model
|
|
@@ -63,11 +99,19 @@ const mapToChatParticipantSdkModel = (chatParticipant) => {
|
|
|
63
99
|
const { communicationIdentifier } = chatParticipant, rest = tslib.__rest(chatParticipant, ["communicationIdentifier"]);
|
|
64
100
|
return Object.assign(Object.assign({}, rest), { id: communicationCommon.deserializeCommunicationIdentifier(communicationIdentifier) });
|
|
65
101
|
};
|
|
102
|
+
/**
|
|
103
|
+
* @internal
|
|
104
|
+
* Mapping chat attachment REST model to chat attachment SDK model
|
|
105
|
+
*/
|
|
106
|
+
const mapToChatAttachmentSdkModel = (chatAttachment) => {
|
|
107
|
+
const { attachmentType } = chatAttachment, rest = tslib.__rest(chatAttachment, ["attachmentType"]);
|
|
108
|
+
return Object.assign(Object.assign({}, rest), { attachmentType: attachmentType });
|
|
109
|
+
};
|
|
66
110
|
/**
|
|
67
111
|
* @internal
|
|
68
112
|
*/
|
|
69
113
|
const mapToChatContentSdkModel = (content) => {
|
|
70
|
-
const { participants, initiatorCommunicationIdentifier } = content, otherChatContents = tslib.__rest(content, ["participants", "initiatorCommunicationIdentifier"]);
|
|
114
|
+
const { participants, attachments, initiatorCommunicationIdentifier } = content, otherChatContents = tslib.__rest(content, ["participants", "attachments", "initiatorCommunicationIdentifier"]);
|
|
71
115
|
let result = Object.assign({}, otherChatContents);
|
|
72
116
|
if (initiatorCommunicationIdentifier) {
|
|
73
117
|
const initiator = communicationCommon.deserializeCommunicationIdentifier(initiatorCommunicationIdentifier);
|
|
@@ -76,6 +120,19 @@ const mapToChatContentSdkModel = (content) => {
|
|
|
76
120
|
if (participants) {
|
|
77
121
|
result = Object.assign(Object.assign({}, result), { participants: participants === null || participants === void 0 ? void 0 : participants.map((participant) => mapToChatParticipantSdkModel(participant)) });
|
|
78
122
|
}
|
|
123
|
+
if (attachments) {
|
|
124
|
+
result = Object.assign(Object.assign({}, result), { attachments: attachments === null || attachments === void 0 ? void 0 : attachments.map((attachment) => mapToChatAttachmentSdkModel(attachment)) });
|
|
125
|
+
}
|
|
126
|
+
return result;
|
|
127
|
+
};
|
|
128
|
+
/**
|
|
129
|
+
* @internal
|
|
130
|
+
*/
|
|
131
|
+
const mapToChatPolicyViolationSdkModel = (policyVolation) => {
|
|
132
|
+
const { state } = policyVolation;
|
|
133
|
+
const result = {
|
|
134
|
+
result: state,
|
|
135
|
+
};
|
|
79
136
|
return result;
|
|
80
137
|
};
|
|
81
138
|
/**
|
|
@@ -83,7 +140,7 @@ const mapToChatContentSdkModel = (content) => {
|
|
|
83
140
|
* Mapping chat message REST model to chat message SDK model
|
|
84
141
|
*/
|
|
85
142
|
const mapToChatMessageSdkModel = (chatMessage) => {
|
|
86
|
-
const { content, senderCommunicationIdentifier } = chatMessage, otherChatMessage = tslib.__rest(chatMessage, ["content", "senderCommunicationIdentifier"]);
|
|
143
|
+
const { content, senderCommunicationIdentifier, policyViolation } = chatMessage, otherChatMessage = tslib.__rest(chatMessage, ["content", "senderCommunicationIdentifier", "policyViolation"]);
|
|
87
144
|
let result = Object.assign({}, otherChatMessage);
|
|
88
145
|
if (content) {
|
|
89
146
|
result = Object.assign(Object.assign({}, result), { content: mapToChatContentSdkModel(content) });
|
|
@@ -92,20 +149,40 @@ const mapToChatMessageSdkModel = (chatMessage) => {
|
|
|
92
149
|
const sender = communicationCommon.deserializeCommunicationIdentifier(senderCommunicationIdentifier);
|
|
93
150
|
result = Object.assign(Object.assign({}, result), { sender });
|
|
94
151
|
}
|
|
152
|
+
if (policyViolation) {
|
|
153
|
+
result = Object.assign(Object.assign({}, result), { policyViolation: mapToChatPolicyViolationSdkModel(policyViolation) });
|
|
154
|
+
}
|
|
95
155
|
return result;
|
|
96
156
|
};
|
|
157
|
+
/**
|
|
158
|
+
* @internal
|
|
159
|
+
* Mapping chat retention policy REST model to chat retention policy SDK model
|
|
160
|
+
*/
|
|
161
|
+
const mapToRetentionPolicySdkModel = (retentionPolicy) => {
|
|
162
|
+
if (retentionPolicy.kind === "threadCreationDate") {
|
|
163
|
+
return retentionPolicy;
|
|
164
|
+
}
|
|
165
|
+
if (retentionPolicy.kind === "none") {
|
|
166
|
+
return retentionPolicy;
|
|
167
|
+
}
|
|
168
|
+
else {
|
|
169
|
+
throw new Error(`Retention Policy ${retentionPolicy.kind} is not supported`);
|
|
170
|
+
}
|
|
171
|
+
};
|
|
97
172
|
/**
|
|
98
173
|
* @internal
|
|
99
174
|
* Mapping chat thread REST model to chat thread SDK model
|
|
100
175
|
*/
|
|
101
176
|
const mapToChatThreadPropertiesSdkModel = (chatThread) => {
|
|
102
|
-
const { createdByCommunicationIdentifier } = chatThread, rest = tslib.__rest(chatThread, ["createdByCommunicationIdentifier"]);
|
|
177
|
+
const { createdByCommunicationIdentifier, retentionPolicy } = chatThread, rest = tslib.__rest(chatThread, ["createdByCommunicationIdentifier", "retentionPolicy"]);
|
|
178
|
+
let result = Object.assign({}, rest);
|
|
103
179
|
if (createdByCommunicationIdentifier) {
|
|
104
|
-
|
|
180
|
+
result = Object.assign(Object.assign({}, result), { createdBy: communicationCommon.deserializeCommunicationIdentifier(createdByCommunicationIdentifier) });
|
|
105
181
|
}
|
|
106
|
-
|
|
107
|
-
|
|
182
|
+
if (retentionPolicy) {
|
|
183
|
+
result = Object.assign(Object.assign({}, result), { retentionPolicy: mapToRetentionPolicySdkModel(retentionPolicy) });
|
|
108
184
|
}
|
|
185
|
+
return result;
|
|
109
186
|
};
|
|
110
187
|
/**
|
|
111
188
|
* @internal
|
|
@@ -139,7 +216,7 @@ const mapToReadReceiptSdkModel = (readReceipt) => {
|
|
|
139
216
|
const tracingClient = coreTracing.createTracingClient({
|
|
140
217
|
namespace: "Azure.Communication",
|
|
141
218
|
packageName: "@azure/communication-chat",
|
|
142
|
-
packageVersion: "1.
|
|
219
|
+
packageVersion: "1.6.0-beta.2",
|
|
143
220
|
});
|
|
144
221
|
|
|
145
222
|
/*
|
|
@@ -449,6 +526,59 @@ const SendChatMessageRequest = {
|
|
|
449
526
|
value: { type: { name: "String" } },
|
|
450
527
|
},
|
|
451
528
|
},
|
|
529
|
+
attachments: {
|
|
530
|
+
serializedName: "attachments",
|
|
531
|
+
type: {
|
|
532
|
+
name: "Sequence",
|
|
533
|
+
element: {
|
|
534
|
+
type: {
|
|
535
|
+
name: "Composite",
|
|
536
|
+
className: "ChatAttachment",
|
|
537
|
+
},
|
|
538
|
+
},
|
|
539
|
+
},
|
|
540
|
+
},
|
|
541
|
+
},
|
|
542
|
+
},
|
|
543
|
+
};
|
|
544
|
+
const ChatAttachment = {
|
|
545
|
+
type: {
|
|
546
|
+
name: "Composite",
|
|
547
|
+
className: "ChatAttachment",
|
|
548
|
+
modelProperties: {
|
|
549
|
+
id: {
|
|
550
|
+
serializedName: "id",
|
|
551
|
+
required: true,
|
|
552
|
+
type: {
|
|
553
|
+
name: "String",
|
|
554
|
+
},
|
|
555
|
+
},
|
|
556
|
+
attachmentType: {
|
|
557
|
+
serializedName: "attachmentType",
|
|
558
|
+
required: true,
|
|
559
|
+
type: {
|
|
560
|
+
name: "Enum",
|
|
561
|
+
allowedValues: ["image", "file"],
|
|
562
|
+
},
|
|
563
|
+
},
|
|
564
|
+
name: {
|
|
565
|
+
serializedName: "name",
|
|
566
|
+
type: {
|
|
567
|
+
name: "String",
|
|
568
|
+
},
|
|
569
|
+
},
|
|
570
|
+
url: {
|
|
571
|
+
serializedName: "url",
|
|
572
|
+
type: {
|
|
573
|
+
name: "String",
|
|
574
|
+
},
|
|
575
|
+
},
|
|
576
|
+
previewUrl: {
|
|
577
|
+
serializedName: "previewUrl",
|
|
578
|
+
type: {
|
|
579
|
+
name: "String",
|
|
580
|
+
},
|
|
581
|
+
},
|
|
452
582
|
},
|
|
453
583
|
},
|
|
454
584
|
};
|
|
@@ -581,6 +711,13 @@ const ChatMessage = {
|
|
|
581
711
|
value: { type: { name: "String" } },
|
|
582
712
|
},
|
|
583
713
|
},
|
|
714
|
+
policyViolation: {
|
|
715
|
+
serializedName: "policyViolation",
|
|
716
|
+
type: {
|
|
717
|
+
name: "Composite",
|
|
718
|
+
className: "PolicyViolation",
|
|
719
|
+
},
|
|
720
|
+
},
|
|
584
721
|
},
|
|
585
722
|
},
|
|
586
723
|
};
|
|
@@ -659,45 +796,27 @@ const ChatParticipant = {
|
|
|
659
796
|
name: "DateTime",
|
|
660
797
|
},
|
|
661
798
|
},
|
|
799
|
+
metadata: {
|
|
800
|
+
serializedName: "metadata",
|
|
801
|
+
type: {
|
|
802
|
+
name: "Dictionary",
|
|
803
|
+
value: { type: { name: "String" } },
|
|
804
|
+
},
|
|
805
|
+
},
|
|
662
806
|
},
|
|
663
807
|
},
|
|
664
808
|
};
|
|
665
|
-
const
|
|
809
|
+
const PolicyViolation = {
|
|
666
810
|
type: {
|
|
667
811
|
name: "Composite",
|
|
668
|
-
className: "
|
|
812
|
+
className: "PolicyViolation",
|
|
669
813
|
modelProperties: {
|
|
670
|
-
|
|
671
|
-
serializedName: "
|
|
672
|
-
required: true,
|
|
673
|
-
type: {
|
|
674
|
-
name: "String",
|
|
675
|
-
},
|
|
676
|
-
},
|
|
677
|
-
attachmentType: {
|
|
678
|
-
serializedName: "attachmentType",
|
|
814
|
+
state: {
|
|
815
|
+
serializedName: "state",
|
|
679
816
|
required: true,
|
|
680
817
|
type: {
|
|
681
818
|
name: "Enum",
|
|
682
|
-
allowedValues: ["
|
|
683
|
-
},
|
|
684
|
-
},
|
|
685
|
-
name: {
|
|
686
|
-
serializedName: "name",
|
|
687
|
-
type: {
|
|
688
|
-
name: "String",
|
|
689
|
-
},
|
|
690
|
-
},
|
|
691
|
-
url: {
|
|
692
|
-
serializedName: "url",
|
|
693
|
-
type: {
|
|
694
|
-
name: "String",
|
|
695
|
-
},
|
|
696
|
-
},
|
|
697
|
-
previewUrl: {
|
|
698
|
-
serializedName: "previewUrl",
|
|
699
|
-
type: {
|
|
700
|
-
name: "String",
|
|
819
|
+
allowedValues: ["contentBlocked", "warning"],
|
|
701
820
|
},
|
|
702
821
|
},
|
|
703
822
|
},
|
|
@@ -721,6 +840,18 @@ const UpdateChatMessageRequest = {
|
|
|
721
840
|
value: { type: { name: "String" } },
|
|
722
841
|
},
|
|
723
842
|
},
|
|
843
|
+
attachments: {
|
|
844
|
+
serializedName: "attachments",
|
|
845
|
+
type: {
|
|
846
|
+
name: "Sequence",
|
|
847
|
+
element: {
|
|
848
|
+
type: {
|
|
849
|
+
name: "Composite",
|
|
850
|
+
className: "ChatAttachment",
|
|
851
|
+
},
|
|
852
|
+
},
|
|
853
|
+
},
|
|
854
|
+
},
|
|
724
855
|
},
|
|
725
856
|
},
|
|
726
857
|
};
|
|
@@ -818,6 +949,41 @@ const CreateChatThreadRequest = {
|
|
|
818
949
|
},
|
|
819
950
|
},
|
|
820
951
|
},
|
|
952
|
+
metadata: {
|
|
953
|
+
serializedName: "metadata",
|
|
954
|
+
type: {
|
|
955
|
+
name: "Dictionary",
|
|
956
|
+
value: { type: { name: "String" } },
|
|
957
|
+
},
|
|
958
|
+
},
|
|
959
|
+
retentionPolicy: {
|
|
960
|
+
serializedName: "retentionPolicy",
|
|
961
|
+
type: {
|
|
962
|
+
name: "Composite",
|
|
963
|
+
className: "ChatRetentionPolicy",
|
|
964
|
+
},
|
|
965
|
+
},
|
|
966
|
+
},
|
|
967
|
+
},
|
|
968
|
+
};
|
|
969
|
+
const ChatRetentionPolicy = {
|
|
970
|
+
type: {
|
|
971
|
+
name: "Composite",
|
|
972
|
+
className: "ChatRetentionPolicy",
|
|
973
|
+
uberParent: "ChatRetentionPolicy",
|
|
974
|
+
polymorphicDiscriminator: {
|
|
975
|
+
serializedName: "kind",
|
|
976
|
+
clientName: "kind",
|
|
977
|
+
},
|
|
978
|
+
modelProperties: {
|
|
979
|
+
kind: {
|
|
980
|
+
serializedName: "kind",
|
|
981
|
+
required: true,
|
|
982
|
+
type: {
|
|
983
|
+
name: "Enum",
|
|
984
|
+
allowedValues: ["threadCreationDate", "none"],
|
|
985
|
+
},
|
|
986
|
+
},
|
|
821
987
|
},
|
|
822
988
|
},
|
|
823
989
|
};
|
|
@@ -888,6 +1054,41 @@ const ChatThreadProperties = {
|
|
|
888
1054
|
name: "DateTime",
|
|
889
1055
|
},
|
|
890
1056
|
},
|
|
1057
|
+
metadata: {
|
|
1058
|
+
serializedName: "metadata",
|
|
1059
|
+
type: {
|
|
1060
|
+
name: "Dictionary",
|
|
1061
|
+
value: { type: { name: "String" } },
|
|
1062
|
+
},
|
|
1063
|
+
},
|
|
1064
|
+
retentionPolicy: {
|
|
1065
|
+
serializedName: "retentionPolicy",
|
|
1066
|
+
type: {
|
|
1067
|
+
name: "Composite",
|
|
1068
|
+
className: "ChatRetentionPolicy",
|
|
1069
|
+
},
|
|
1070
|
+
},
|
|
1071
|
+
messagingPolicy: {
|
|
1072
|
+
serializedName: "messagingPolicy",
|
|
1073
|
+
type: {
|
|
1074
|
+
name: "Composite",
|
|
1075
|
+
className: "MessagingPolicy",
|
|
1076
|
+
},
|
|
1077
|
+
},
|
|
1078
|
+
},
|
|
1079
|
+
},
|
|
1080
|
+
};
|
|
1081
|
+
const MessagingPolicy = {
|
|
1082
|
+
type: {
|
|
1083
|
+
name: "Composite",
|
|
1084
|
+
className: "MessagingPolicy",
|
|
1085
|
+
modelProperties: {
|
|
1086
|
+
textOnlyChat: {
|
|
1087
|
+
serializedName: "textOnlyChat",
|
|
1088
|
+
type: {
|
|
1089
|
+
name: "Boolean",
|
|
1090
|
+
},
|
|
1091
|
+
},
|
|
891
1092
|
},
|
|
892
1093
|
},
|
|
893
1094
|
};
|
|
@@ -965,6 +1166,20 @@ const UpdateChatThreadRequest = {
|
|
|
965
1166
|
name: "String",
|
|
966
1167
|
},
|
|
967
1168
|
},
|
|
1169
|
+
metadata: {
|
|
1170
|
+
serializedName: "metadata",
|
|
1171
|
+
type: {
|
|
1172
|
+
name: "Dictionary",
|
|
1173
|
+
value: { type: { name: "String" } },
|
|
1174
|
+
},
|
|
1175
|
+
},
|
|
1176
|
+
retentionPolicy: {
|
|
1177
|
+
serializedName: "retentionPolicy",
|
|
1178
|
+
type: {
|
|
1179
|
+
name: "Composite",
|
|
1180
|
+
className: "ChatRetentionPolicy",
|
|
1181
|
+
},
|
|
1182
|
+
},
|
|
968
1183
|
},
|
|
969
1184
|
},
|
|
970
1185
|
};
|
|
@@ -982,6 +1197,136 @@ const SendTypingNotificationRequest = {
|
|
|
982
1197
|
},
|
|
983
1198
|
},
|
|
984
1199
|
};
|
|
1200
|
+
const UploadChatImageResult = {
|
|
1201
|
+
type: {
|
|
1202
|
+
name: "Composite",
|
|
1203
|
+
className: "UploadChatImageResult",
|
|
1204
|
+
modelProperties: {
|
|
1205
|
+
id: {
|
|
1206
|
+
serializedName: "id",
|
|
1207
|
+
required: true,
|
|
1208
|
+
type: {
|
|
1209
|
+
name: "String",
|
|
1210
|
+
},
|
|
1211
|
+
},
|
|
1212
|
+
attachmentType: {
|
|
1213
|
+
serializedName: "attachmentType",
|
|
1214
|
+
type: {
|
|
1215
|
+
name: "Enum",
|
|
1216
|
+
allowedValues: ["image", "file"],
|
|
1217
|
+
},
|
|
1218
|
+
},
|
|
1219
|
+
name: {
|
|
1220
|
+
serializedName: "name",
|
|
1221
|
+
type: {
|
|
1222
|
+
name: "String",
|
|
1223
|
+
},
|
|
1224
|
+
},
|
|
1225
|
+
},
|
|
1226
|
+
},
|
|
1227
|
+
};
|
|
1228
|
+
const ErrorResponse = {
|
|
1229
|
+
type: {
|
|
1230
|
+
name: "Composite",
|
|
1231
|
+
className: "ErrorResponse",
|
|
1232
|
+
modelProperties: {
|
|
1233
|
+
error: {
|
|
1234
|
+
serializedName: "error",
|
|
1235
|
+
type: {
|
|
1236
|
+
name: "Composite",
|
|
1237
|
+
className: "ErrorModel",
|
|
1238
|
+
},
|
|
1239
|
+
},
|
|
1240
|
+
},
|
|
1241
|
+
},
|
|
1242
|
+
};
|
|
1243
|
+
const ErrorModel = {
|
|
1244
|
+
type: {
|
|
1245
|
+
name: "Composite",
|
|
1246
|
+
className: "ErrorModel",
|
|
1247
|
+
modelProperties: {
|
|
1248
|
+
code: {
|
|
1249
|
+
serializedName: "code",
|
|
1250
|
+
required: true,
|
|
1251
|
+
type: {
|
|
1252
|
+
name: "String",
|
|
1253
|
+
},
|
|
1254
|
+
},
|
|
1255
|
+
message: {
|
|
1256
|
+
serializedName: "message",
|
|
1257
|
+
required: true,
|
|
1258
|
+
type: {
|
|
1259
|
+
name: "String",
|
|
1260
|
+
},
|
|
1261
|
+
},
|
|
1262
|
+
details: {
|
|
1263
|
+
serializedName: "details",
|
|
1264
|
+
type: {
|
|
1265
|
+
name: "Sequence",
|
|
1266
|
+
element: {
|
|
1267
|
+
type: {
|
|
1268
|
+
name: "Composite",
|
|
1269
|
+
className: "ErrorDetail",
|
|
1270
|
+
},
|
|
1271
|
+
},
|
|
1272
|
+
},
|
|
1273
|
+
},
|
|
1274
|
+
},
|
|
1275
|
+
},
|
|
1276
|
+
};
|
|
1277
|
+
const ErrorDetail = {
|
|
1278
|
+
type: {
|
|
1279
|
+
name: "Composite",
|
|
1280
|
+
className: "ErrorDetail",
|
|
1281
|
+
modelProperties: {
|
|
1282
|
+
code: {
|
|
1283
|
+
serializedName: "code",
|
|
1284
|
+
required: true,
|
|
1285
|
+
type: {
|
|
1286
|
+
name: "String",
|
|
1287
|
+
},
|
|
1288
|
+
},
|
|
1289
|
+
message: {
|
|
1290
|
+
serializedName: "message",
|
|
1291
|
+
required: true,
|
|
1292
|
+
type: {
|
|
1293
|
+
name: "String",
|
|
1294
|
+
},
|
|
1295
|
+
},
|
|
1296
|
+
},
|
|
1297
|
+
},
|
|
1298
|
+
};
|
|
1299
|
+
const ThreadCreationDateRetentionPolicy = {
|
|
1300
|
+
serializedName: "threadCreationDate",
|
|
1301
|
+
type: {
|
|
1302
|
+
name: "Composite",
|
|
1303
|
+
className: "ThreadCreationDateRetentionPolicy",
|
|
1304
|
+
uberParent: "ChatRetentionPolicy",
|
|
1305
|
+
polymorphicDiscriminator: ChatRetentionPolicy.type.polymorphicDiscriminator,
|
|
1306
|
+
modelProperties: Object.assign(Object.assign({}, ChatRetentionPolicy.type.modelProperties), { deleteThreadAfterDays: {
|
|
1307
|
+
serializedName: "deleteThreadAfterDays",
|
|
1308
|
+
required: true,
|
|
1309
|
+
type: {
|
|
1310
|
+
name: "Number",
|
|
1311
|
+
},
|
|
1312
|
+
} }),
|
|
1313
|
+
},
|
|
1314
|
+
};
|
|
1315
|
+
const NoneRetentionPolicy = {
|
|
1316
|
+
serializedName: "none",
|
|
1317
|
+
type: {
|
|
1318
|
+
name: "Composite",
|
|
1319
|
+
className: "NoneRetentionPolicy",
|
|
1320
|
+
uberParent: "ChatRetentionPolicy",
|
|
1321
|
+
polymorphicDiscriminator: ChatRetentionPolicy.type.polymorphicDiscriminator,
|
|
1322
|
+
modelProperties: Object.assign({}, ChatRetentionPolicy.type.modelProperties),
|
|
1323
|
+
},
|
|
1324
|
+
};
|
|
1325
|
+
let discriminators = {
|
|
1326
|
+
ChatRetentionPolicy: ChatRetentionPolicy,
|
|
1327
|
+
"ChatRetentionPolicy.threadCreationDate": ThreadCreationDateRetentionPolicy,
|
|
1328
|
+
"ChatRetentionPolicy.none": NoneRetentionPolicy,
|
|
1329
|
+
};
|
|
985
1330
|
|
|
986
1331
|
var Mappers = /*#__PURE__*/Object.freeze({
|
|
987
1332
|
__proto__: null,
|
|
@@ -996,6 +1341,7 @@ var Mappers = /*#__PURE__*/Object.freeze({
|
|
|
996
1341
|
ChatMessagesCollection: ChatMessagesCollection,
|
|
997
1342
|
ChatParticipant: ChatParticipant,
|
|
998
1343
|
ChatParticipantsCollection: ChatParticipantsCollection,
|
|
1344
|
+
ChatRetentionPolicy: ChatRetentionPolicy,
|
|
999
1345
|
ChatThreadItem: ChatThreadItem,
|
|
1000
1346
|
ChatThreadProperties: ChatThreadProperties,
|
|
1001
1347
|
ChatThreadsItemCollection: ChatThreadsItemCollection,
|
|
@@ -1004,15 +1350,24 @@ var Mappers = /*#__PURE__*/Object.freeze({
|
|
|
1004
1350
|
CommunicationUserIdentifierModel: CommunicationUserIdentifierModel,
|
|
1005
1351
|
CreateChatThreadRequest: CreateChatThreadRequest,
|
|
1006
1352
|
CreateChatThreadResult: CreateChatThreadResult,
|
|
1353
|
+
ErrorDetail: ErrorDetail,
|
|
1354
|
+
ErrorModel: ErrorModel,
|
|
1355
|
+
ErrorResponse: ErrorResponse,
|
|
1356
|
+
MessagingPolicy: MessagingPolicy,
|
|
1007
1357
|
MicrosoftTeamsAppIdentifierModel: MicrosoftTeamsAppIdentifierModel,
|
|
1008
1358
|
MicrosoftTeamsUserIdentifierModel: MicrosoftTeamsUserIdentifierModel,
|
|
1359
|
+
NoneRetentionPolicy: NoneRetentionPolicy,
|
|
1009
1360
|
PhoneNumberIdentifierModel: PhoneNumberIdentifierModel,
|
|
1361
|
+
PolicyViolation: PolicyViolation,
|
|
1010
1362
|
SendChatMessageRequest: SendChatMessageRequest,
|
|
1011
1363
|
SendChatMessageResult: SendChatMessageResult,
|
|
1012
1364
|
SendReadReceiptRequest: SendReadReceiptRequest,
|
|
1013
1365
|
SendTypingNotificationRequest: SendTypingNotificationRequest,
|
|
1366
|
+
ThreadCreationDateRetentionPolicy: ThreadCreationDateRetentionPolicy,
|
|
1014
1367
|
UpdateChatMessageRequest: UpdateChatMessageRequest,
|
|
1015
|
-
UpdateChatThreadRequest: UpdateChatThreadRequest
|
|
1368
|
+
UpdateChatThreadRequest: UpdateChatThreadRequest,
|
|
1369
|
+
UploadChatImageResult: UploadChatImageResult,
|
|
1370
|
+
discriminators: discriminators
|
|
1016
1371
|
});
|
|
1017
1372
|
|
|
1018
1373
|
/*
|
|
@@ -1075,7 +1430,7 @@ const skip = {
|
|
|
1075
1430
|
const apiVersion = {
|
|
1076
1431
|
parameterPath: "apiVersion",
|
|
1077
1432
|
mapper: {
|
|
1078
|
-
defaultValue: "2024-
|
|
1433
|
+
defaultValue: "2024-06-05-preview",
|
|
1079
1434
|
isConstant: true,
|
|
1080
1435
|
serializedName: "api-version",
|
|
1081
1436
|
type: {
|
|
@@ -1152,6 +1507,78 @@ const sendTypingNotificationRequest = {
|
|
|
1152
1507
|
parameterPath: ["options", "sendTypingNotificationRequest"],
|
|
1153
1508
|
mapper: SendTypingNotificationRequest,
|
|
1154
1509
|
};
|
|
1510
|
+
const contentType2 = {
|
|
1511
|
+
parameterPath: ["options", "contentType"],
|
|
1512
|
+
mapper: {
|
|
1513
|
+
defaultValue: "application/octet-stream",
|
|
1514
|
+
isConstant: true,
|
|
1515
|
+
serializedName: "Content-Type",
|
|
1516
|
+
type: {
|
|
1517
|
+
name: "String",
|
|
1518
|
+
},
|
|
1519
|
+
},
|
|
1520
|
+
};
|
|
1521
|
+
const chatImageFile = {
|
|
1522
|
+
parameterPath: "chatImageFile",
|
|
1523
|
+
mapper: {
|
|
1524
|
+
serializedName: "chatImageFile",
|
|
1525
|
+
required: true,
|
|
1526
|
+
type: {
|
|
1527
|
+
name: "Stream",
|
|
1528
|
+
},
|
|
1529
|
+
},
|
|
1530
|
+
};
|
|
1531
|
+
const accept1 = {
|
|
1532
|
+
parameterPath: "accept",
|
|
1533
|
+
mapper: {
|
|
1534
|
+
defaultValue: "application/json",
|
|
1535
|
+
isConstant: true,
|
|
1536
|
+
serializedName: "Accept",
|
|
1537
|
+
type: {
|
|
1538
|
+
name: "String",
|
|
1539
|
+
},
|
|
1540
|
+
},
|
|
1541
|
+
};
|
|
1542
|
+
const imageFilename = {
|
|
1543
|
+
parameterPath: ["options", "imageFilename"],
|
|
1544
|
+
mapper: {
|
|
1545
|
+
serializedName: "image-filename",
|
|
1546
|
+
type: {
|
|
1547
|
+
name: "String",
|
|
1548
|
+
},
|
|
1549
|
+
},
|
|
1550
|
+
};
|
|
1551
|
+
const accept2 = {
|
|
1552
|
+
parameterPath: "accept",
|
|
1553
|
+
mapper: {
|
|
1554
|
+
defaultValue: "application/json, image/gif, image/jpeg, image/png, image/bmp, image/tiff",
|
|
1555
|
+
isConstant: true,
|
|
1556
|
+
serializedName: "Accept",
|
|
1557
|
+
type: {
|
|
1558
|
+
name: "String",
|
|
1559
|
+
},
|
|
1560
|
+
},
|
|
1561
|
+
};
|
|
1562
|
+
const imageId = {
|
|
1563
|
+
parameterPath: "imageId",
|
|
1564
|
+
mapper: {
|
|
1565
|
+
serializedName: "imageId",
|
|
1566
|
+
required: true,
|
|
1567
|
+
type: {
|
|
1568
|
+
name: "String",
|
|
1569
|
+
},
|
|
1570
|
+
},
|
|
1571
|
+
};
|
|
1572
|
+
const imageViewType = {
|
|
1573
|
+
parameterPath: "imageViewType",
|
|
1574
|
+
mapper: {
|
|
1575
|
+
serializedName: "imageViewType",
|
|
1576
|
+
required: true,
|
|
1577
|
+
type: {
|
|
1578
|
+
name: "String",
|
|
1579
|
+
},
|
|
1580
|
+
},
|
|
1581
|
+
};
|
|
1155
1582
|
const nextLink = {
|
|
1156
1583
|
parameterPath: "nextLink",
|
|
1157
1584
|
mapper: {
|
|
@@ -1332,6 +1759,40 @@ class ChatThreadImpl {
|
|
|
1332
1759
|
return this.client.sendOperationRequest({ chatThreadId, options }, sendTypingNotificationOperationSpec);
|
|
1333
1760
|
});
|
|
1334
1761
|
}
|
|
1762
|
+
/**
|
|
1763
|
+
* Upload an image in a thread, on behalf of a user.
|
|
1764
|
+
* @param chatThreadId Thread id where the uploaded image belongs to. (Teams meeting only)
|
|
1765
|
+
* @param chatImageFile Image binary data, allowed image formats: jpeg, png, gif, heic, webp
|
|
1766
|
+
* @param options The options parameters.
|
|
1767
|
+
*/
|
|
1768
|
+
async uploadChatImage(chatThreadId, chatImageFile, options) {
|
|
1769
|
+
return tracingClient.withSpan("ChatApiClient.uploadChatImage", options !== null && options !== void 0 ? options : {}, async (options) => {
|
|
1770
|
+
return this.client.sendOperationRequest({ chatThreadId, chatImageFile, options }, uploadChatImageOperationSpec);
|
|
1771
|
+
});
|
|
1772
|
+
}
|
|
1773
|
+
/**
|
|
1774
|
+
* Get an image by view type.
|
|
1775
|
+
* @param chatThreadId The thread id to which the message was sent.
|
|
1776
|
+
* @param imageId The image id.
|
|
1777
|
+
* @param imageViewType The view type of image.
|
|
1778
|
+
* @param options The options parameters.
|
|
1779
|
+
*/
|
|
1780
|
+
async getChatImage(chatThreadId, imageId, imageViewType, options) {
|
|
1781
|
+
return tracingClient.withSpan("ChatApiClient.getChatImage", options !== null && options !== void 0 ? options : {}, async (options) => {
|
|
1782
|
+
return this.client.sendOperationRequest({ chatThreadId, imageId, imageViewType, options }, getChatImageOperationSpec);
|
|
1783
|
+
});
|
|
1784
|
+
}
|
|
1785
|
+
/**
|
|
1786
|
+
* Deletes a image.
|
|
1787
|
+
* @param chatThreadId The thread id to which the message was sent.
|
|
1788
|
+
* @param imageId The image id.
|
|
1789
|
+
* @param options The options parameters.
|
|
1790
|
+
*/
|
|
1791
|
+
async deleteChatImage(chatThreadId, imageId, options) {
|
|
1792
|
+
return tracingClient.withSpan("ChatApiClient.deleteChatImage", options !== null && options !== void 0 ? options : {}, async (options) => {
|
|
1793
|
+
return this.client.sendOperationRequest({ chatThreadId, imageId, options }, deleteChatImageOperationSpec);
|
|
1794
|
+
});
|
|
1795
|
+
}
|
|
1335
1796
|
/**
|
|
1336
1797
|
* ListChatReadReceiptsNext
|
|
1337
1798
|
* @param chatThreadId Thread id to get the chat message read receipts for.
|
|
@@ -1771,6 +2232,70 @@ const sendTypingNotificationOperationSpec = {
|
|
|
1771
2232
|
mediaType: "json",
|
|
1772
2233
|
serializer: serializer$1,
|
|
1773
2234
|
};
|
|
2235
|
+
const uploadChatImageOperationSpec = {
|
|
2236
|
+
path: "/chat/threads/{chatThreadId}/images",
|
|
2237
|
+
httpMethod: "POST",
|
|
2238
|
+
responses: {
|
|
2239
|
+
201: {
|
|
2240
|
+
bodyMapper: UploadChatImageResult,
|
|
2241
|
+
},
|
|
2242
|
+
default: {
|
|
2243
|
+
bodyMapper: ErrorResponse,
|
|
2244
|
+
},
|
|
2245
|
+
},
|
|
2246
|
+
requestBody: chatImageFile,
|
|
2247
|
+
queryParameters: [apiVersion],
|
|
2248
|
+
urlParameters: [endpoint, chatThreadId],
|
|
2249
|
+
headerParameters: [
|
|
2250
|
+
contentType2,
|
|
2251
|
+
accept1,
|
|
2252
|
+
imageFilename,
|
|
2253
|
+
],
|
|
2254
|
+
mediaType: "binary",
|
|
2255
|
+
serializer: serializer$1,
|
|
2256
|
+
};
|
|
2257
|
+
const getChatImageOperationSpec = {
|
|
2258
|
+
path: "/chat/threads/{chatThreadId}/images/{imageId}/view/{imageViewType}",
|
|
2259
|
+
httpMethod: "GET",
|
|
2260
|
+
responses: {
|
|
2261
|
+
200: {
|
|
2262
|
+
bodyMapper: {
|
|
2263
|
+
type: { name: "Stream" },
|
|
2264
|
+
serializedName: "parsedResponse",
|
|
2265
|
+
},
|
|
2266
|
+
},
|
|
2267
|
+
default: {
|
|
2268
|
+
bodyMapper: ErrorResponse,
|
|
2269
|
+
},
|
|
2270
|
+
},
|
|
2271
|
+
queryParameters: [apiVersion],
|
|
2272
|
+
urlParameters: [
|
|
2273
|
+
endpoint,
|
|
2274
|
+
chatThreadId,
|
|
2275
|
+
imageId,
|
|
2276
|
+
imageViewType,
|
|
2277
|
+
],
|
|
2278
|
+
headerParameters: [accept2],
|
|
2279
|
+
serializer: serializer$1,
|
|
2280
|
+
};
|
|
2281
|
+
const deleteChatImageOperationSpec = {
|
|
2282
|
+
path: "/chat/threads/{chatThreadId}/images/{imageId}",
|
|
2283
|
+
httpMethod: "DELETE",
|
|
2284
|
+
responses: {
|
|
2285
|
+
204: {},
|
|
2286
|
+
default: {
|
|
2287
|
+
bodyMapper: ErrorResponse,
|
|
2288
|
+
},
|
|
2289
|
+
},
|
|
2290
|
+
queryParameters: [apiVersion],
|
|
2291
|
+
urlParameters: [
|
|
2292
|
+
endpoint,
|
|
2293
|
+
chatThreadId,
|
|
2294
|
+
imageId,
|
|
2295
|
+
],
|
|
2296
|
+
headerParameters: [accept],
|
|
2297
|
+
serializer: serializer$1,
|
|
2298
|
+
};
|
|
1774
2299
|
const listChatReadReceiptsNextOperationSpec = {
|
|
1775
2300
|
path: "{nextLink}",
|
|
1776
2301
|
httpMethod: "GET",
|
|
@@ -2075,7 +2600,7 @@ class ChatApiClient extends coreClient__namespace.ServiceClient {
|
|
|
2075
2600
|
const defaults = {
|
|
2076
2601
|
requestContentType: "application/json; charset=utf-8",
|
|
2077
2602
|
};
|
|
2078
|
-
const packageDetails = `azsdk-js-communication-chat/1.
|
|
2603
|
+
const packageDetails = `azsdk-js-communication-chat/1.6.0-beta.2`;
|
|
2079
2604
|
const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix
|
|
2080
2605
|
? `${options.userAgentOptions.userAgentPrefix} ${packageDetails}`
|
|
2081
2606
|
: `${packageDetails}`;
|
|
@@ -2086,7 +2611,7 @@ class ChatApiClient extends coreClient__namespace.ServiceClient {
|
|
|
2086
2611
|
// Parameter assignments
|
|
2087
2612
|
this.endpoint = endpoint;
|
|
2088
2613
|
// Assigning values to Constant parameters
|
|
2089
|
-
this.apiVersion = options.apiVersion || "2024-
|
|
2614
|
+
this.apiVersion = options.apiVersion || "2024-06-05-preview";
|
|
2090
2615
|
this.chatThread = new ChatThreadImpl(this);
|
|
2091
2616
|
this.chat = new ChatImpl(this);
|
|
2092
2617
|
this.addCustomApiVersionPolicy(options.apiVersion);
|
|
@@ -2122,6 +2647,190 @@ class ChatApiClient extends coreClient__namespace.ServiceClient {
|
|
|
2122
2647
|
// Licensed under the MIT license.
|
|
2123
2648
|
const logger = logger$1.createClientLogger("communication-chat");
|
|
2124
2649
|
|
|
2650
|
+
// Copyright (c) Microsoft Corporation.
|
|
2651
|
+
// Licensed under the MIT license.
|
|
2652
|
+
// Temporary workaround with local copy of XhrHttpClient
|
|
2653
|
+
function isNodeReadableStream(body) {
|
|
2654
|
+
return body && typeof body.pipe === "function";
|
|
2655
|
+
}
|
|
2656
|
+
/**
|
|
2657
|
+
* Checks if the body is a Blob or Blob-like
|
|
2658
|
+
* @internal
|
|
2659
|
+
*/
|
|
2660
|
+
function isBlob(body) {
|
|
2661
|
+
// File objects count as a type of Blob, so we want to use instanceof explicitly
|
|
2662
|
+
return (typeof Blob === "function" || typeof Blob === "object") && body instanceof Blob;
|
|
2663
|
+
}
|
|
2664
|
+
/**
|
|
2665
|
+
* Checks if the body is a ReadableStream supported by browsers
|
|
2666
|
+
* @internal
|
|
2667
|
+
*/
|
|
2668
|
+
function isReadableStream(body) {
|
|
2669
|
+
return Boolean(body &&
|
|
2670
|
+
typeof body.getReader === "function" &&
|
|
2671
|
+
typeof body.tee === "function");
|
|
2672
|
+
}
|
|
2673
|
+
/**
|
|
2674
|
+
* A HttpClient implementation that uses XMLHttpRequest to send HTTP requests.
|
|
2675
|
+
* @internal
|
|
2676
|
+
*/
|
|
2677
|
+
class XhrHttpClient {
|
|
2678
|
+
/**
|
|
2679
|
+
* Makes a request over an underlying transport layer and returns the response.
|
|
2680
|
+
* @param request - The request to be made.
|
|
2681
|
+
*/
|
|
2682
|
+
async sendRequest(request) {
|
|
2683
|
+
var _a;
|
|
2684
|
+
const url = new URL(request.url);
|
|
2685
|
+
const isInsecure = url.protocol !== "https:";
|
|
2686
|
+
if (isInsecure && !request.allowInsecureConnection) {
|
|
2687
|
+
throw new Error(`Cannot connect to ${request.url} while allowInsecureConnection is false.`);
|
|
2688
|
+
}
|
|
2689
|
+
const xhr = new XMLHttpRequest();
|
|
2690
|
+
if (request.proxySettings) {
|
|
2691
|
+
throw new Error("HTTP proxy is not supported in browser environment");
|
|
2692
|
+
}
|
|
2693
|
+
const abortSignal = request.abortSignal;
|
|
2694
|
+
if (abortSignal) {
|
|
2695
|
+
if (abortSignal.aborted) {
|
|
2696
|
+
throw new abortController.AbortError("The operation was aborted.");
|
|
2697
|
+
}
|
|
2698
|
+
const listener = () => {
|
|
2699
|
+
xhr.abort();
|
|
2700
|
+
};
|
|
2701
|
+
abortSignal.addEventListener("abort", listener);
|
|
2702
|
+
xhr.addEventListener("readystatechange", () => {
|
|
2703
|
+
if (xhr.readyState === XMLHttpRequest.DONE) {
|
|
2704
|
+
abortSignal.removeEventListener("abort", listener);
|
|
2705
|
+
}
|
|
2706
|
+
});
|
|
2707
|
+
}
|
|
2708
|
+
addProgressListener(xhr.upload, request.onUploadProgress);
|
|
2709
|
+
addProgressListener(xhr, request.onDownloadProgress);
|
|
2710
|
+
xhr.open(request.method, request.url);
|
|
2711
|
+
xhr.timeout = request.timeout;
|
|
2712
|
+
xhr.withCredentials = request.withCredentials;
|
|
2713
|
+
for (const [name, value] of request.headers) {
|
|
2714
|
+
xhr.setRequestHeader(name, value);
|
|
2715
|
+
}
|
|
2716
|
+
xhr.responseType = ((_a = request.streamResponseStatusCodes) === null || _a === void 0 ? void 0 : _a.size) ? "blob" : "text";
|
|
2717
|
+
const body = typeof request.body === "function" ? request.body() : request.body;
|
|
2718
|
+
if (isNodeReadableStream(body) || isReadableStream(body)) {
|
|
2719
|
+
throw new Error("Streams are not supported by xhrHttpClient.");
|
|
2720
|
+
}
|
|
2721
|
+
xhr.send(body === undefined ? null : body);
|
|
2722
|
+
if (xhr.responseType === "blob") {
|
|
2723
|
+
return new Promise((resolve, reject) => {
|
|
2724
|
+
handleBlobResponse(xhr, request, resolve, reject);
|
|
2725
|
+
rejectOnTerminalEvent(request, xhr, reject);
|
|
2726
|
+
});
|
|
2727
|
+
}
|
|
2728
|
+
else {
|
|
2729
|
+
return new Promise(function (resolve, reject) {
|
|
2730
|
+
xhr.addEventListener("load", () => resolve({
|
|
2731
|
+
request,
|
|
2732
|
+
status: xhr.status,
|
|
2733
|
+
headers: parseHeaders(xhr),
|
|
2734
|
+
bodyAsText: xhr.responseText,
|
|
2735
|
+
}));
|
|
2736
|
+
rejectOnTerminalEvent(request, xhr, reject);
|
|
2737
|
+
});
|
|
2738
|
+
}
|
|
2739
|
+
}
|
|
2740
|
+
}
|
|
2741
|
+
function handleBlobResponse(xhr, request, res, rej) {
|
|
2742
|
+
xhr.addEventListener("readystatechange", () => {
|
|
2743
|
+
var _a, _b;
|
|
2744
|
+
// Resolve as soon as headers are loaded
|
|
2745
|
+
if (xhr.readyState === XMLHttpRequest.HEADERS_RECEIVED) {
|
|
2746
|
+
if (
|
|
2747
|
+
// Value of POSITIVE_INFINITY in streamResponseStatusCodes is considered as any status code
|
|
2748
|
+
((_a = request.streamResponseStatusCodes) === null || _a === void 0 ? void 0 : _a.has(Number.POSITIVE_INFINITY)) ||
|
|
2749
|
+
((_b = request.streamResponseStatusCodes) === null || _b === void 0 ? void 0 : _b.has(xhr.status))) {
|
|
2750
|
+
const blobBody = new Promise((resolve, reject) => {
|
|
2751
|
+
xhr.addEventListener("load", () => {
|
|
2752
|
+
resolve(xhr.response);
|
|
2753
|
+
});
|
|
2754
|
+
rejectOnTerminalEvent(request, xhr, reject);
|
|
2755
|
+
});
|
|
2756
|
+
res({
|
|
2757
|
+
request,
|
|
2758
|
+
status: xhr.status,
|
|
2759
|
+
headers: parseHeaders(xhr),
|
|
2760
|
+
blobBody,
|
|
2761
|
+
});
|
|
2762
|
+
}
|
|
2763
|
+
else {
|
|
2764
|
+
xhr.addEventListener("load", () => {
|
|
2765
|
+
// xhr.response is of Blob type if the request is sent with xhr.responseType === "blob"
|
|
2766
|
+
// but the status code is not one of the stream response status codes,
|
|
2767
|
+
// so treat it as text and convert from Blob to text
|
|
2768
|
+
if (xhr.response) {
|
|
2769
|
+
xhr.response
|
|
2770
|
+
.text()
|
|
2771
|
+
.then((text) => {
|
|
2772
|
+
res({
|
|
2773
|
+
request: request,
|
|
2774
|
+
status: xhr.status,
|
|
2775
|
+
headers: parseHeaders(xhr),
|
|
2776
|
+
bodyAsText: text,
|
|
2777
|
+
});
|
|
2778
|
+
return;
|
|
2779
|
+
})
|
|
2780
|
+
.catch((e) => {
|
|
2781
|
+
rej(e);
|
|
2782
|
+
});
|
|
2783
|
+
}
|
|
2784
|
+
else {
|
|
2785
|
+
res({
|
|
2786
|
+
request,
|
|
2787
|
+
status: xhr.status,
|
|
2788
|
+
headers: parseHeaders(xhr),
|
|
2789
|
+
});
|
|
2790
|
+
}
|
|
2791
|
+
});
|
|
2792
|
+
}
|
|
2793
|
+
}
|
|
2794
|
+
});
|
|
2795
|
+
}
|
|
2796
|
+
function addProgressListener(xhr, listener) {
|
|
2797
|
+
if (listener) {
|
|
2798
|
+
xhr.addEventListener("progress", (rawEvent) => listener({
|
|
2799
|
+
loadedBytes: rawEvent.loaded,
|
|
2800
|
+
}));
|
|
2801
|
+
}
|
|
2802
|
+
}
|
|
2803
|
+
function parseHeaders(xhr) {
|
|
2804
|
+
const responseHeaders = coreRestPipeline.createHttpHeaders();
|
|
2805
|
+
const headerLines = xhr
|
|
2806
|
+
.getAllResponseHeaders()
|
|
2807
|
+
.trim()
|
|
2808
|
+
.split(/[\r\n]+/);
|
|
2809
|
+
for (const line of headerLines) {
|
|
2810
|
+
const index = line.indexOf(":");
|
|
2811
|
+
const headerName = line.slice(0, index);
|
|
2812
|
+
const headerValue = line.slice(index + 2);
|
|
2813
|
+
responseHeaders.set(headerName, headerValue);
|
|
2814
|
+
}
|
|
2815
|
+
return responseHeaders;
|
|
2816
|
+
}
|
|
2817
|
+
function rejectOnTerminalEvent(request, xhr, reject) {
|
|
2818
|
+
xhr.addEventListener("error", () => reject(new coreRestPipeline.RestError(`Failed to send request to ${request.url}`, {
|
|
2819
|
+
code: coreRestPipeline.RestError.REQUEST_SEND_ERROR,
|
|
2820
|
+
request,
|
|
2821
|
+
})));
|
|
2822
|
+
const abortError = new abortController.AbortError("The operation was aborted.");
|
|
2823
|
+
xhr.addEventListener("abort", () => reject(abortError));
|
|
2824
|
+
xhr.addEventListener("timeout", () => reject(abortError));
|
|
2825
|
+
}
|
|
2826
|
+
/**
|
|
2827
|
+
* Create a new HttpClient instance for the browser environment.
|
|
2828
|
+
* @internal
|
|
2829
|
+
*/
|
|
2830
|
+
function createXhrHttpClient() {
|
|
2831
|
+
return new XhrHttpClient();
|
|
2832
|
+
}
|
|
2833
|
+
|
|
2125
2834
|
// Copyright (c) Microsoft Corporation.
|
|
2126
2835
|
// Licensed under the MIT license.
|
|
2127
2836
|
/**
|
|
@@ -2159,6 +2868,10 @@ class ChatThreadClient {
|
|
|
2159
2868
|
this.client = new ChatApiClient(this.endpoint, Object.assign({ endpoint: this.endpoint }, internalPipelineOptions));
|
|
2160
2869
|
const authPolicy = createCommunicationTokenCredentialPolicy(this.tokenCredential);
|
|
2161
2870
|
this.client.pipeline.addPolicy(authPolicy);
|
|
2871
|
+
if (typeof XMLHttpRequest !== "undefined") {
|
|
2872
|
+
this.xhrClient = new ChatApiClient(this.endpoint, Object.assign(Object.assign({ endpoint: this.endpoint }, internalPipelineOptions), { httpClient: createXhrHttpClient() }));
|
|
2873
|
+
this.xhrClient.pipeline.addPolicy(authPolicy);
|
|
2874
|
+
}
|
|
2162
2875
|
}
|
|
2163
2876
|
/**
|
|
2164
2877
|
* Gets a chat thread.
|
|
@@ -2181,6 +2894,15 @@ class ChatThreadClient {
|
|
|
2181
2894
|
await this.client.chatThread.updateChatThreadProperties(this.threadId, { topic: topic }, updatedOptions);
|
|
2182
2895
|
});
|
|
2183
2896
|
}
|
|
2897
|
+
/**
|
|
2898
|
+
* Updates a thread's properties.
|
|
2899
|
+
* @param options - Operation options.
|
|
2900
|
+
*/
|
|
2901
|
+
updateProperties(options = {}) {
|
|
2902
|
+
return tracingClient.withSpan("ChatThreadClient-UpdateProperties", options, async (updatedOptions) => {
|
|
2903
|
+
await this.client.chatThread.updateChatThreadProperties(this.threadId, options, updatedOptions);
|
|
2904
|
+
});
|
|
2905
|
+
}
|
|
2184
2906
|
/**
|
|
2185
2907
|
* Sends a chat message to a thread identified by threadId.
|
|
2186
2908
|
* Returns the id of the created message.
|
|
@@ -2191,7 +2913,7 @@ class ChatThreadClient {
|
|
|
2191
2913
|
return tracingClient.withSpan("ChatThreadClient-SendMessage", options, async (updatedOptions) => {
|
|
2192
2914
|
// reset typing notification clock
|
|
2193
2915
|
this.timeOfLastTypingRequest = undefined;
|
|
2194
|
-
const result = await this.client.chatThread.sendChatMessage(this.threadId,
|
|
2916
|
+
const result = await this.client.chatThread.sendChatMessage(this.threadId, mapToSendChatMessageRequestRestModel(request, options), updatedOptions);
|
|
2195
2917
|
return result;
|
|
2196
2918
|
});
|
|
2197
2919
|
}
|
|
@@ -2297,7 +3019,7 @@ class ChatThreadClient {
|
|
|
2297
3019
|
*/
|
|
2298
3020
|
async updateMessage(messageId, options = {}) {
|
|
2299
3021
|
return tracingClient.withSpan("ChatThreadClient-UpdateMessage", options, async (updatedOptions) => {
|
|
2300
|
-
await this.client.chatThread.updateChatMessage(this.threadId, messageId, options, updatedOptions);
|
|
3022
|
+
await this.client.chatThread.updateChatMessage(this.threadId, messageId, mapToUpdateChatMessageRequestRestModel(options), updatedOptions);
|
|
2301
3023
|
});
|
|
2302
3024
|
}
|
|
2303
3025
|
/**
|
|
@@ -2506,6 +3228,72 @@ class ChatThreadClient {
|
|
|
2506
3228
|
}
|
|
2507
3229
|
return true;
|
|
2508
3230
|
}
|
|
3231
|
+
async uploadImage(image, imageFilename, imageBytesLengthOrOptions, options = {}) {
|
|
3232
|
+
let uploadImageOptions = {};
|
|
3233
|
+
if (imageBytesLengthOrOptions !== undefined) {
|
|
3234
|
+
if (typeof imageBytesLengthOrOptions === "number") {
|
|
3235
|
+
uploadImageOptions = Object.assign(Object.assign({}, options), { imageBytesLength: imageBytesLengthOrOptions });
|
|
3236
|
+
}
|
|
3237
|
+
else {
|
|
3238
|
+
uploadImageOptions = Object.assign(Object.assign({}, options), imageBytesLengthOrOptions);
|
|
3239
|
+
}
|
|
3240
|
+
}
|
|
3241
|
+
return tracingClient.withSpan("ChatThreadClient-UploadImage", uploadImageOptions, async (updatedOptions) => {
|
|
3242
|
+
let result;
|
|
3243
|
+
if (this.xhrClient && // is browser
|
|
3244
|
+
((!this.supportsReadableStream() && isReadableStream(image)) || // is readable stream but no support, need to convert
|
|
3245
|
+
!isReadableStream(image))) {
|
|
3246
|
+
// use xhrClient if (to support onUploadProgress)
|
|
3247
|
+
// - is readable stream but no support => convert to ArrayBuffer (so will have content-length)
|
|
3248
|
+
// - is not readable stream
|
|
3249
|
+
result = await this.xhrClient.chatThread.uploadChatImage(this.threadId, isReadableStream(image) ? await this.getArrayBufferFromReadableStream(image) : image, Object.assign({ imageFilename }, updatedOptions));
|
|
3250
|
+
}
|
|
3251
|
+
else {
|
|
3252
|
+
// backend (node fetch client) or readable readable stream
|
|
3253
|
+
// Backend (no browser) need to convert Blob/ReadableStream to ArrayBuffer
|
|
3254
|
+
let chatImageFile = image;
|
|
3255
|
+
if (isBlob(image)) {
|
|
3256
|
+
chatImageFile = await this.getArrayBufferFromBlob(image);
|
|
3257
|
+
}
|
|
3258
|
+
else if (isReadableStream(image)) {
|
|
3259
|
+
chatImageFile = await this.getArrayBufferFromReadableStream(image);
|
|
3260
|
+
}
|
|
3261
|
+
result = await this.client.chatThread.uploadChatImage(this.threadId, chatImageFile, Object.assign({ imageFilename }, updatedOptions));
|
|
3262
|
+
}
|
|
3263
|
+
return result;
|
|
3264
|
+
});
|
|
3265
|
+
}
|
|
3266
|
+
/**
|
|
3267
|
+
* Deletes an image identified by threadId and imageId
|
|
3268
|
+
* @param imageId - The image id of the image.
|
|
3269
|
+
* @param options - Operation options.
|
|
3270
|
+
*/
|
|
3271
|
+
deleteImage(imageId, options = {}) {
|
|
3272
|
+
return tracingClient.withSpan("ChatThreadClient-DeleteImage", options, async (updatedOptions) => {
|
|
3273
|
+
await this.client.chatThread.deleteChatImage(this.threadId, imageId, updatedOptions);
|
|
3274
|
+
});
|
|
3275
|
+
}
|
|
3276
|
+
supportsReadableStream() {
|
|
3277
|
+
let duplexAccessed = false;
|
|
3278
|
+
const hasContentType = new Request("", {
|
|
3279
|
+
body: new ReadableStream(),
|
|
3280
|
+
method: "POST",
|
|
3281
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
3282
|
+
// @ts-ignore
|
|
3283
|
+
get duplex() {
|
|
3284
|
+
duplexAccessed = true;
|
|
3285
|
+
return "half";
|
|
3286
|
+
},
|
|
3287
|
+
}).headers.has("Content-Type");
|
|
3288
|
+
return duplexAccessed && !hasContentType;
|
|
3289
|
+
}
|
|
3290
|
+
async getArrayBufferFromReadableStream(body) {
|
|
3291
|
+
const arrayBuffer = await new Response(body).arrayBuffer();
|
|
3292
|
+
return new Uint8Array(arrayBuffer);
|
|
3293
|
+
}
|
|
3294
|
+
async getArrayBufferFromBlob(body) {
|
|
3295
|
+
return new Uint8Array(await body.arrayBuffer());
|
|
3296
|
+
}
|
|
2509
3297
|
}
|
|
2510
3298
|
|
|
2511
3299
|
// Copyright (c) Microsoft Corporation.
|
|
@@ -2590,6 +3378,8 @@ class ChatClient {
|
|
|
2590
3378
|
const result = await this.client.chat.createChatThread({
|
|
2591
3379
|
topic: request.topic,
|
|
2592
3380
|
participants: (_b = options.participants) === null || _b === void 0 ? void 0 : _b.map((participant) => mapToChatParticipantRestModel(participant)),
|
|
3381
|
+
metadata: options.metadata,
|
|
3382
|
+
retentionPolicy: options.retentionPolicy,
|
|
2593
3383
|
}, updatedRestModelOptions);
|
|
2594
3384
|
return mapToCreateChatThreadResultSdkModel(result);
|
|
2595
3385
|
});
|
|
@@ -2725,10 +3515,10 @@ class ChatClient {
|
|
|
2725
3515
|
throw new Error("Realtime notifications are only supported in the browser.");
|
|
2726
3516
|
}
|
|
2727
3517
|
this.signalingClient.on("connectionChanged", (payload) => {
|
|
2728
|
-
if (payload ===
|
|
3518
|
+
if (payload === 2 /* ConnectionState.Connected */) {
|
|
2729
3519
|
this.emitter.emit("realTimeNotificationConnected");
|
|
2730
3520
|
}
|
|
2731
|
-
else if (payload ===
|
|
3521
|
+
else if (payload === 3 /* ConnectionState.Disconnected */) {
|
|
2732
3522
|
this.emitter.emit("realTimeNotificationDisconnected");
|
|
2733
3523
|
}
|
|
2734
3524
|
});
|