@azure/communication-chat 1.5.0 → 1.6.0-beta.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/dist/index.js +784 -53
- 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 +262 -38
- 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 +68 -5
- 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 +2 -2
- package/types/communication-chat.d.ts +110 -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,9 @@ 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
|
+
}
|
|
79
126
|
return result;
|
|
80
127
|
};
|
|
81
128
|
/**
|
|
@@ -94,18 +141,35 @@ const mapToChatMessageSdkModel = (chatMessage) => {
|
|
|
94
141
|
}
|
|
95
142
|
return result;
|
|
96
143
|
};
|
|
144
|
+
/**
|
|
145
|
+
* @internal
|
|
146
|
+
* Mapping chat retention policy REST model to chat retention policy SDK model
|
|
147
|
+
*/
|
|
148
|
+
const mapToRetentionPolicySdkModel = (retentionPolicy) => {
|
|
149
|
+
if (retentionPolicy.kind === "threadCreationDate") {
|
|
150
|
+
return retentionPolicy;
|
|
151
|
+
}
|
|
152
|
+
if (retentionPolicy.kind === "none") {
|
|
153
|
+
return retentionPolicy;
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
156
|
+
throw new Error(`Retention Policy ${retentionPolicy.kind} is not supported`);
|
|
157
|
+
}
|
|
158
|
+
};
|
|
97
159
|
/**
|
|
98
160
|
* @internal
|
|
99
161
|
* Mapping chat thread REST model to chat thread SDK model
|
|
100
162
|
*/
|
|
101
163
|
const mapToChatThreadPropertiesSdkModel = (chatThread) => {
|
|
102
|
-
const { createdByCommunicationIdentifier } = chatThread, rest = tslib.__rest(chatThread, ["createdByCommunicationIdentifier"]);
|
|
164
|
+
const { createdByCommunicationIdentifier, retentionPolicy } = chatThread, rest = tslib.__rest(chatThread, ["createdByCommunicationIdentifier", "retentionPolicy"]);
|
|
165
|
+
let result = Object.assign({}, rest);
|
|
103
166
|
if (createdByCommunicationIdentifier) {
|
|
104
|
-
|
|
167
|
+
result = Object.assign(Object.assign({}, result), { createdBy: communicationCommon.deserializeCommunicationIdentifier(createdByCommunicationIdentifier) });
|
|
105
168
|
}
|
|
106
|
-
|
|
107
|
-
|
|
169
|
+
if (retentionPolicy) {
|
|
170
|
+
result = Object.assign(Object.assign({}, result), { retentionPolicy: mapToRetentionPolicySdkModel(retentionPolicy) });
|
|
108
171
|
}
|
|
172
|
+
return result;
|
|
109
173
|
};
|
|
110
174
|
/**
|
|
111
175
|
* @internal
|
|
@@ -139,7 +203,7 @@ const mapToReadReceiptSdkModel = (readReceipt) => {
|
|
|
139
203
|
const tracingClient = coreTracing.createTracingClient({
|
|
140
204
|
namespace: "Azure.Communication",
|
|
141
205
|
packageName: "@azure/communication-chat",
|
|
142
|
-
packageVersion: "1.
|
|
206
|
+
packageVersion: "1.6.0-beta.1",
|
|
143
207
|
});
|
|
144
208
|
|
|
145
209
|
/*
|
|
@@ -449,6 +513,59 @@ const SendChatMessageRequest = {
|
|
|
449
513
|
value: { type: { name: "String" } },
|
|
450
514
|
},
|
|
451
515
|
},
|
|
516
|
+
attachments: {
|
|
517
|
+
serializedName: "attachments",
|
|
518
|
+
type: {
|
|
519
|
+
name: "Sequence",
|
|
520
|
+
element: {
|
|
521
|
+
type: {
|
|
522
|
+
name: "Composite",
|
|
523
|
+
className: "ChatAttachment",
|
|
524
|
+
},
|
|
525
|
+
},
|
|
526
|
+
},
|
|
527
|
+
},
|
|
528
|
+
},
|
|
529
|
+
},
|
|
530
|
+
};
|
|
531
|
+
const ChatAttachment = {
|
|
532
|
+
type: {
|
|
533
|
+
name: "Composite",
|
|
534
|
+
className: "ChatAttachment",
|
|
535
|
+
modelProperties: {
|
|
536
|
+
id: {
|
|
537
|
+
serializedName: "id",
|
|
538
|
+
required: true,
|
|
539
|
+
type: {
|
|
540
|
+
name: "String",
|
|
541
|
+
},
|
|
542
|
+
},
|
|
543
|
+
attachmentType: {
|
|
544
|
+
serializedName: "attachmentType",
|
|
545
|
+
required: true,
|
|
546
|
+
type: {
|
|
547
|
+
name: "Enum",
|
|
548
|
+
allowedValues: ["image", "file"],
|
|
549
|
+
},
|
|
550
|
+
},
|
|
551
|
+
name: {
|
|
552
|
+
serializedName: "name",
|
|
553
|
+
type: {
|
|
554
|
+
name: "String",
|
|
555
|
+
},
|
|
556
|
+
},
|
|
557
|
+
url: {
|
|
558
|
+
serializedName: "url",
|
|
559
|
+
type: {
|
|
560
|
+
name: "String",
|
|
561
|
+
},
|
|
562
|
+
},
|
|
563
|
+
previewUrl: {
|
|
564
|
+
serializedName: "previewUrl",
|
|
565
|
+
type: {
|
|
566
|
+
name: "String",
|
|
567
|
+
},
|
|
568
|
+
},
|
|
452
569
|
},
|
|
453
570
|
},
|
|
454
571
|
};
|
|
@@ -659,45 +776,11 @@ const ChatParticipant = {
|
|
|
659
776
|
name: "DateTime",
|
|
660
777
|
},
|
|
661
778
|
},
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
};
|
|
665
|
-
const ChatAttachment = {
|
|
666
|
-
type: {
|
|
667
|
-
name: "Composite",
|
|
668
|
-
className: "ChatAttachment",
|
|
669
|
-
modelProperties: {
|
|
670
|
-
id: {
|
|
671
|
-
serializedName: "id",
|
|
672
|
-
required: true,
|
|
673
|
-
type: {
|
|
674
|
-
name: "String",
|
|
675
|
-
},
|
|
676
|
-
},
|
|
677
|
-
attachmentType: {
|
|
678
|
-
serializedName: "attachmentType",
|
|
679
|
-
required: true,
|
|
680
|
-
type: {
|
|
681
|
-
name: "Enum",
|
|
682
|
-
allowedValues: ["image", "file"],
|
|
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",
|
|
779
|
+
metadata: {
|
|
780
|
+
serializedName: "metadata",
|
|
699
781
|
type: {
|
|
700
|
-
name: "
|
|
782
|
+
name: "Dictionary",
|
|
783
|
+
value: { type: { name: "String" } },
|
|
701
784
|
},
|
|
702
785
|
},
|
|
703
786
|
},
|
|
@@ -721,6 +804,18 @@ const UpdateChatMessageRequest = {
|
|
|
721
804
|
value: { type: { name: "String" } },
|
|
722
805
|
},
|
|
723
806
|
},
|
|
807
|
+
attachments: {
|
|
808
|
+
serializedName: "attachments",
|
|
809
|
+
type: {
|
|
810
|
+
name: "Sequence",
|
|
811
|
+
element: {
|
|
812
|
+
type: {
|
|
813
|
+
name: "Composite",
|
|
814
|
+
className: "ChatAttachment",
|
|
815
|
+
},
|
|
816
|
+
},
|
|
817
|
+
},
|
|
818
|
+
},
|
|
724
819
|
},
|
|
725
820
|
},
|
|
726
821
|
};
|
|
@@ -818,6 +913,41 @@ const CreateChatThreadRequest = {
|
|
|
818
913
|
},
|
|
819
914
|
},
|
|
820
915
|
},
|
|
916
|
+
metadata: {
|
|
917
|
+
serializedName: "metadata",
|
|
918
|
+
type: {
|
|
919
|
+
name: "Dictionary",
|
|
920
|
+
value: { type: { name: "String" } },
|
|
921
|
+
},
|
|
922
|
+
},
|
|
923
|
+
retentionPolicy: {
|
|
924
|
+
serializedName: "retentionPolicy",
|
|
925
|
+
type: {
|
|
926
|
+
name: "Composite",
|
|
927
|
+
className: "ChatRetentionPolicy",
|
|
928
|
+
},
|
|
929
|
+
},
|
|
930
|
+
},
|
|
931
|
+
},
|
|
932
|
+
};
|
|
933
|
+
const ChatRetentionPolicy = {
|
|
934
|
+
type: {
|
|
935
|
+
name: "Composite",
|
|
936
|
+
className: "ChatRetentionPolicy",
|
|
937
|
+
uberParent: "ChatRetentionPolicy",
|
|
938
|
+
polymorphicDiscriminator: {
|
|
939
|
+
serializedName: "kind",
|
|
940
|
+
clientName: "kind",
|
|
941
|
+
},
|
|
942
|
+
modelProperties: {
|
|
943
|
+
kind: {
|
|
944
|
+
serializedName: "kind",
|
|
945
|
+
required: true,
|
|
946
|
+
type: {
|
|
947
|
+
name: "Enum",
|
|
948
|
+
allowedValues: ["threadCreationDate", "none"],
|
|
949
|
+
},
|
|
950
|
+
},
|
|
821
951
|
},
|
|
822
952
|
},
|
|
823
953
|
};
|
|
@@ -888,6 +1018,20 @@ const ChatThreadProperties = {
|
|
|
888
1018
|
name: "DateTime",
|
|
889
1019
|
},
|
|
890
1020
|
},
|
|
1021
|
+
metadata: {
|
|
1022
|
+
serializedName: "metadata",
|
|
1023
|
+
type: {
|
|
1024
|
+
name: "Dictionary",
|
|
1025
|
+
value: { type: { name: "String" } },
|
|
1026
|
+
},
|
|
1027
|
+
},
|
|
1028
|
+
retentionPolicy: {
|
|
1029
|
+
serializedName: "retentionPolicy",
|
|
1030
|
+
type: {
|
|
1031
|
+
name: "Composite",
|
|
1032
|
+
className: "ChatRetentionPolicy",
|
|
1033
|
+
},
|
|
1034
|
+
},
|
|
891
1035
|
},
|
|
892
1036
|
},
|
|
893
1037
|
};
|
|
@@ -965,6 +1109,20 @@ const UpdateChatThreadRequest = {
|
|
|
965
1109
|
name: "String",
|
|
966
1110
|
},
|
|
967
1111
|
},
|
|
1112
|
+
metadata: {
|
|
1113
|
+
serializedName: "metadata",
|
|
1114
|
+
type: {
|
|
1115
|
+
name: "Dictionary",
|
|
1116
|
+
value: { type: { name: "String" } },
|
|
1117
|
+
},
|
|
1118
|
+
},
|
|
1119
|
+
retentionPolicy: {
|
|
1120
|
+
serializedName: "retentionPolicy",
|
|
1121
|
+
type: {
|
|
1122
|
+
name: "Composite",
|
|
1123
|
+
className: "ChatRetentionPolicy",
|
|
1124
|
+
},
|
|
1125
|
+
},
|
|
968
1126
|
},
|
|
969
1127
|
},
|
|
970
1128
|
};
|
|
@@ -982,6 +1140,136 @@ const SendTypingNotificationRequest = {
|
|
|
982
1140
|
},
|
|
983
1141
|
},
|
|
984
1142
|
};
|
|
1143
|
+
const UploadChatImageResult = {
|
|
1144
|
+
type: {
|
|
1145
|
+
name: "Composite",
|
|
1146
|
+
className: "UploadChatImageResult",
|
|
1147
|
+
modelProperties: {
|
|
1148
|
+
id: {
|
|
1149
|
+
serializedName: "id",
|
|
1150
|
+
required: true,
|
|
1151
|
+
type: {
|
|
1152
|
+
name: "String",
|
|
1153
|
+
},
|
|
1154
|
+
},
|
|
1155
|
+
attachmentType: {
|
|
1156
|
+
serializedName: "attachmentType",
|
|
1157
|
+
type: {
|
|
1158
|
+
name: "Enum",
|
|
1159
|
+
allowedValues: ["image", "file"],
|
|
1160
|
+
},
|
|
1161
|
+
},
|
|
1162
|
+
name: {
|
|
1163
|
+
serializedName: "name",
|
|
1164
|
+
type: {
|
|
1165
|
+
name: "String",
|
|
1166
|
+
},
|
|
1167
|
+
},
|
|
1168
|
+
},
|
|
1169
|
+
},
|
|
1170
|
+
};
|
|
1171
|
+
const ErrorResponse = {
|
|
1172
|
+
type: {
|
|
1173
|
+
name: "Composite",
|
|
1174
|
+
className: "ErrorResponse",
|
|
1175
|
+
modelProperties: {
|
|
1176
|
+
error: {
|
|
1177
|
+
serializedName: "error",
|
|
1178
|
+
type: {
|
|
1179
|
+
name: "Composite",
|
|
1180
|
+
className: "ErrorModel",
|
|
1181
|
+
},
|
|
1182
|
+
},
|
|
1183
|
+
},
|
|
1184
|
+
},
|
|
1185
|
+
};
|
|
1186
|
+
const ErrorModel = {
|
|
1187
|
+
type: {
|
|
1188
|
+
name: "Composite",
|
|
1189
|
+
className: "ErrorModel",
|
|
1190
|
+
modelProperties: {
|
|
1191
|
+
code: {
|
|
1192
|
+
serializedName: "code",
|
|
1193
|
+
required: true,
|
|
1194
|
+
type: {
|
|
1195
|
+
name: "String",
|
|
1196
|
+
},
|
|
1197
|
+
},
|
|
1198
|
+
message: {
|
|
1199
|
+
serializedName: "message",
|
|
1200
|
+
required: true,
|
|
1201
|
+
type: {
|
|
1202
|
+
name: "String",
|
|
1203
|
+
},
|
|
1204
|
+
},
|
|
1205
|
+
details: {
|
|
1206
|
+
serializedName: "details",
|
|
1207
|
+
type: {
|
|
1208
|
+
name: "Sequence",
|
|
1209
|
+
element: {
|
|
1210
|
+
type: {
|
|
1211
|
+
name: "Composite",
|
|
1212
|
+
className: "ErrorDetail",
|
|
1213
|
+
},
|
|
1214
|
+
},
|
|
1215
|
+
},
|
|
1216
|
+
},
|
|
1217
|
+
},
|
|
1218
|
+
},
|
|
1219
|
+
};
|
|
1220
|
+
const ErrorDetail = {
|
|
1221
|
+
type: {
|
|
1222
|
+
name: "Composite",
|
|
1223
|
+
className: "ErrorDetail",
|
|
1224
|
+
modelProperties: {
|
|
1225
|
+
code: {
|
|
1226
|
+
serializedName: "code",
|
|
1227
|
+
required: true,
|
|
1228
|
+
type: {
|
|
1229
|
+
name: "String",
|
|
1230
|
+
},
|
|
1231
|
+
},
|
|
1232
|
+
message: {
|
|
1233
|
+
serializedName: "message",
|
|
1234
|
+
required: true,
|
|
1235
|
+
type: {
|
|
1236
|
+
name: "String",
|
|
1237
|
+
},
|
|
1238
|
+
},
|
|
1239
|
+
},
|
|
1240
|
+
},
|
|
1241
|
+
};
|
|
1242
|
+
const ThreadCreationDateRetentionPolicy = {
|
|
1243
|
+
serializedName: "threadCreationDate",
|
|
1244
|
+
type: {
|
|
1245
|
+
name: "Composite",
|
|
1246
|
+
className: "ThreadCreationDateRetentionPolicy",
|
|
1247
|
+
uberParent: "ChatRetentionPolicy",
|
|
1248
|
+
polymorphicDiscriminator: ChatRetentionPolicy.type.polymorphicDiscriminator,
|
|
1249
|
+
modelProperties: Object.assign(Object.assign({}, ChatRetentionPolicy.type.modelProperties), { deleteThreadAfterDays: {
|
|
1250
|
+
serializedName: "deleteThreadAfterDays",
|
|
1251
|
+
required: true,
|
|
1252
|
+
type: {
|
|
1253
|
+
name: "Number",
|
|
1254
|
+
},
|
|
1255
|
+
} }),
|
|
1256
|
+
},
|
|
1257
|
+
};
|
|
1258
|
+
const NoneRetentionPolicy = {
|
|
1259
|
+
serializedName: "none",
|
|
1260
|
+
type: {
|
|
1261
|
+
name: "Composite",
|
|
1262
|
+
className: "NoneRetentionPolicy",
|
|
1263
|
+
uberParent: "ChatRetentionPolicy",
|
|
1264
|
+
polymorphicDiscriminator: ChatRetentionPolicy.type.polymorphicDiscriminator,
|
|
1265
|
+
modelProperties: Object.assign({}, ChatRetentionPolicy.type.modelProperties),
|
|
1266
|
+
},
|
|
1267
|
+
};
|
|
1268
|
+
let discriminators = {
|
|
1269
|
+
ChatRetentionPolicy: ChatRetentionPolicy,
|
|
1270
|
+
"ChatRetentionPolicy.threadCreationDate": ThreadCreationDateRetentionPolicy,
|
|
1271
|
+
"ChatRetentionPolicy.none": NoneRetentionPolicy,
|
|
1272
|
+
};
|
|
985
1273
|
|
|
986
1274
|
var Mappers = /*#__PURE__*/Object.freeze({
|
|
987
1275
|
__proto__: null,
|
|
@@ -996,6 +1284,7 @@ var Mappers = /*#__PURE__*/Object.freeze({
|
|
|
996
1284
|
ChatMessagesCollection: ChatMessagesCollection,
|
|
997
1285
|
ChatParticipant: ChatParticipant,
|
|
998
1286
|
ChatParticipantsCollection: ChatParticipantsCollection,
|
|
1287
|
+
ChatRetentionPolicy: ChatRetentionPolicy,
|
|
999
1288
|
ChatThreadItem: ChatThreadItem,
|
|
1000
1289
|
ChatThreadProperties: ChatThreadProperties,
|
|
1001
1290
|
ChatThreadsItemCollection: ChatThreadsItemCollection,
|
|
@@ -1004,15 +1293,22 @@ var Mappers = /*#__PURE__*/Object.freeze({
|
|
|
1004
1293
|
CommunicationUserIdentifierModel: CommunicationUserIdentifierModel,
|
|
1005
1294
|
CreateChatThreadRequest: CreateChatThreadRequest,
|
|
1006
1295
|
CreateChatThreadResult: CreateChatThreadResult,
|
|
1296
|
+
ErrorDetail: ErrorDetail,
|
|
1297
|
+
ErrorModel: ErrorModel,
|
|
1298
|
+
ErrorResponse: ErrorResponse,
|
|
1007
1299
|
MicrosoftTeamsAppIdentifierModel: MicrosoftTeamsAppIdentifierModel,
|
|
1008
1300
|
MicrosoftTeamsUserIdentifierModel: MicrosoftTeamsUserIdentifierModel,
|
|
1301
|
+
NoneRetentionPolicy: NoneRetentionPolicy,
|
|
1009
1302
|
PhoneNumberIdentifierModel: PhoneNumberIdentifierModel,
|
|
1010
1303
|
SendChatMessageRequest: SendChatMessageRequest,
|
|
1011
1304
|
SendChatMessageResult: SendChatMessageResult,
|
|
1012
1305
|
SendReadReceiptRequest: SendReadReceiptRequest,
|
|
1013
1306
|
SendTypingNotificationRequest: SendTypingNotificationRequest,
|
|
1307
|
+
ThreadCreationDateRetentionPolicy: ThreadCreationDateRetentionPolicy,
|
|
1014
1308
|
UpdateChatMessageRequest: UpdateChatMessageRequest,
|
|
1015
|
-
UpdateChatThreadRequest: UpdateChatThreadRequest
|
|
1309
|
+
UpdateChatThreadRequest: UpdateChatThreadRequest,
|
|
1310
|
+
UploadChatImageResult: UploadChatImageResult,
|
|
1311
|
+
discriminators: discriminators
|
|
1016
1312
|
});
|
|
1017
1313
|
|
|
1018
1314
|
/*
|
|
@@ -1075,7 +1371,7 @@ const skip = {
|
|
|
1075
1371
|
const apiVersion = {
|
|
1076
1372
|
parameterPath: "apiVersion",
|
|
1077
1373
|
mapper: {
|
|
1078
|
-
defaultValue: "2024-03-
|
|
1374
|
+
defaultValue: "2024-03-15-preview",
|
|
1079
1375
|
isConstant: true,
|
|
1080
1376
|
serializedName: "api-version",
|
|
1081
1377
|
type: {
|
|
@@ -1152,6 +1448,78 @@ const sendTypingNotificationRequest = {
|
|
|
1152
1448
|
parameterPath: ["options", "sendTypingNotificationRequest"],
|
|
1153
1449
|
mapper: SendTypingNotificationRequest,
|
|
1154
1450
|
};
|
|
1451
|
+
const contentType2 = {
|
|
1452
|
+
parameterPath: ["options", "contentType"],
|
|
1453
|
+
mapper: {
|
|
1454
|
+
defaultValue: "application/octet-stream",
|
|
1455
|
+
isConstant: true,
|
|
1456
|
+
serializedName: "Content-Type",
|
|
1457
|
+
type: {
|
|
1458
|
+
name: "String",
|
|
1459
|
+
},
|
|
1460
|
+
},
|
|
1461
|
+
};
|
|
1462
|
+
const chatImageFile = {
|
|
1463
|
+
parameterPath: "chatImageFile",
|
|
1464
|
+
mapper: {
|
|
1465
|
+
serializedName: "chatImageFile",
|
|
1466
|
+
required: true,
|
|
1467
|
+
type: {
|
|
1468
|
+
name: "Stream",
|
|
1469
|
+
},
|
|
1470
|
+
},
|
|
1471
|
+
};
|
|
1472
|
+
const accept1 = {
|
|
1473
|
+
parameterPath: "accept",
|
|
1474
|
+
mapper: {
|
|
1475
|
+
defaultValue: "application/json",
|
|
1476
|
+
isConstant: true,
|
|
1477
|
+
serializedName: "Accept",
|
|
1478
|
+
type: {
|
|
1479
|
+
name: "String",
|
|
1480
|
+
},
|
|
1481
|
+
},
|
|
1482
|
+
};
|
|
1483
|
+
const imageFilename = {
|
|
1484
|
+
parameterPath: ["options", "imageFilename"],
|
|
1485
|
+
mapper: {
|
|
1486
|
+
serializedName: "image-filename",
|
|
1487
|
+
type: {
|
|
1488
|
+
name: "String",
|
|
1489
|
+
},
|
|
1490
|
+
},
|
|
1491
|
+
};
|
|
1492
|
+
const accept2 = {
|
|
1493
|
+
parameterPath: "accept",
|
|
1494
|
+
mapper: {
|
|
1495
|
+
defaultValue: "application/json, image/gif, image/jpeg, image/png, image/bmp, image/tiff",
|
|
1496
|
+
isConstant: true,
|
|
1497
|
+
serializedName: "Accept",
|
|
1498
|
+
type: {
|
|
1499
|
+
name: "String",
|
|
1500
|
+
},
|
|
1501
|
+
},
|
|
1502
|
+
};
|
|
1503
|
+
const imageId = {
|
|
1504
|
+
parameterPath: "imageId",
|
|
1505
|
+
mapper: {
|
|
1506
|
+
serializedName: "imageId",
|
|
1507
|
+
required: true,
|
|
1508
|
+
type: {
|
|
1509
|
+
name: "String",
|
|
1510
|
+
},
|
|
1511
|
+
},
|
|
1512
|
+
};
|
|
1513
|
+
const imageViewType = {
|
|
1514
|
+
parameterPath: "imageViewType",
|
|
1515
|
+
mapper: {
|
|
1516
|
+
serializedName: "imageViewType",
|
|
1517
|
+
required: true,
|
|
1518
|
+
type: {
|
|
1519
|
+
name: "String",
|
|
1520
|
+
},
|
|
1521
|
+
},
|
|
1522
|
+
};
|
|
1155
1523
|
const nextLink = {
|
|
1156
1524
|
parameterPath: "nextLink",
|
|
1157
1525
|
mapper: {
|
|
@@ -1332,6 +1700,40 @@ class ChatThreadImpl {
|
|
|
1332
1700
|
return this.client.sendOperationRequest({ chatThreadId, options }, sendTypingNotificationOperationSpec);
|
|
1333
1701
|
});
|
|
1334
1702
|
}
|
|
1703
|
+
/**
|
|
1704
|
+
* Upload an image in a thread, on behalf of a user.
|
|
1705
|
+
* @param chatThreadId Thread id where the uploaded image belongs to. (Teams meeting only)
|
|
1706
|
+
* @param chatImageFile Image binary data, allowed image formats: jpeg, png, gif, heic, webp
|
|
1707
|
+
* @param options The options parameters.
|
|
1708
|
+
*/
|
|
1709
|
+
async uploadChatImage(chatThreadId, chatImageFile, options) {
|
|
1710
|
+
return tracingClient.withSpan("ChatApiClient.uploadChatImage", options !== null && options !== void 0 ? options : {}, async (options) => {
|
|
1711
|
+
return this.client.sendOperationRequest({ chatThreadId, chatImageFile, options }, uploadChatImageOperationSpec);
|
|
1712
|
+
});
|
|
1713
|
+
}
|
|
1714
|
+
/**
|
|
1715
|
+
* Get an image by view type.
|
|
1716
|
+
* @param chatThreadId The thread id to which the message was sent.
|
|
1717
|
+
* @param imageId The image id.
|
|
1718
|
+
* @param imageViewType The view type of image.
|
|
1719
|
+
* @param options The options parameters.
|
|
1720
|
+
*/
|
|
1721
|
+
async getChatImage(chatThreadId, imageId, imageViewType, options) {
|
|
1722
|
+
return tracingClient.withSpan("ChatApiClient.getChatImage", options !== null && options !== void 0 ? options : {}, async (options) => {
|
|
1723
|
+
return this.client.sendOperationRequest({ chatThreadId, imageId, imageViewType, options }, getChatImageOperationSpec);
|
|
1724
|
+
});
|
|
1725
|
+
}
|
|
1726
|
+
/**
|
|
1727
|
+
* Deletes a image.
|
|
1728
|
+
* @param chatThreadId The thread id to which the message was sent.
|
|
1729
|
+
* @param imageId The image id.
|
|
1730
|
+
* @param options The options parameters.
|
|
1731
|
+
*/
|
|
1732
|
+
async deleteChatImage(chatThreadId, imageId, options) {
|
|
1733
|
+
return tracingClient.withSpan("ChatApiClient.deleteChatImage", options !== null && options !== void 0 ? options : {}, async (options) => {
|
|
1734
|
+
return this.client.sendOperationRequest({ chatThreadId, imageId, options }, deleteChatImageOperationSpec);
|
|
1735
|
+
});
|
|
1736
|
+
}
|
|
1335
1737
|
/**
|
|
1336
1738
|
* ListChatReadReceiptsNext
|
|
1337
1739
|
* @param chatThreadId Thread id to get the chat message read receipts for.
|
|
@@ -1771,6 +2173,70 @@ const sendTypingNotificationOperationSpec = {
|
|
|
1771
2173
|
mediaType: "json",
|
|
1772
2174
|
serializer: serializer$1,
|
|
1773
2175
|
};
|
|
2176
|
+
const uploadChatImageOperationSpec = {
|
|
2177
|
+
path: "/chat/threads/{chatThreadId}/images",
|
|
2178
|
+
httpMethod: "POST",
|
|
2179
|
+
responses: {
|
|
2180
|
+
201: {
|
|
2181
|
+
bodyMapper: UploadChatImageResult,
|
|
2182
|
+
},
|
|
2183
|
+
default: {
|
|
2184
|
+
bodyMapper: ErrorResponse,
|
|
2185
|
+
},
|
|
2186
|
+
},
|
|
2187
|
+
requestBody: chatImageFile,
|
|
2188
|
+
queryParameters: [apiVersion],
|
|
2189
|
+
urlParameters: [endpoint, chatThreadId],
|
|
2190
|
+
headerParameters: [
|
|
2191
|
+
contentType2,
|
|
2192
|
+
accept1,
|
|
2193
|
+
imageFilename,
|
|
2194
|
+
],
|
|
2195
|
+
mediaType: "binary",
|
|
2196
|
+
serializer: serializer$1,
|
|
2197
|
+
};
|
|
2198
|
+
const getChatImageOperationSpec = {
|
|
2199
|
+
path: "/chat/threads/{chatThreadId}/images/{imageId}/view/{imageViewType}",
|
|
2200
|
+
httpMethod: "GET",
|
|
2201
|
+
responses: {
|
|
2202
|
+
200: {
|
|
2203
|
+
bodyMapper: {
|
|
2204
|
+
type: { name: "Stream" },
|
|
2205
|
+
serializedName: "parsedResponse",
|
|
2206
|
+
},
|
|
2207
|
+
},
|
|
2208
|
+
default: {
|
|
2209
|
+
bodyMapper: ErrorResponse,
|
|
2210
|
+
},
|
|
2211
|
+
},
|
|
2212
|
+
queryParameters: [apiVersion],
|
|
2213
|
+
urlParameters: [
|
|
2214
|
+
endpoint,
|
|
2215
|
+
chatThreadId,
|
|
2216
|
+
imageId,
|
|
2217
|
+
imageViewType,
|
|
2218
|
+
],
|
|
2219
|
+
headerParameters: [accept2],
|
|
2220
|
+
serializer: serializer$1,
|
|
2221
|
+
};
|
|
2222
|
+
const deleteChatImageOperationSpec = {
|
|
2223
|
+
path: "/chat/threads/{chatThreadId}/images/{imageId}",
|
|
2224
|
+
httpMethod: "DELETE",
|
|
2225
|
+
responses: {
|
|
2226
|
+
204: {},
|
|
2227
|
+
default: {
|
|
2228
|
+
bodyMapper: ErrorResponse,
|
|
2229
|
+
},
|
|
2230
|
+
},
|
|
2231
|
+
queryParameters: [apiVersion],
|
|
2232
|
+
urlParameters: [
|
|
2233
|
+
endpoint,
|
|
2234
|
+
chatThreadId,
|
|
2235
|
+
imageId,
|
|
2236
|
+
],
|
|
2237
|
+
headerParameters: [accept],
|
|
2238
|
+
serializer: serializer$1,
|
|
2239
|
+
};
|
|
1774
2240
|
const listChatReadReceiptsNextOperationSpec = {
|
|
1775
2241
|
path: "{nextLink}",
|
|
1776
2242
|
httpMethod: "GET",
|
|
@@ -2075,7 +2541,7 @@ class ChatApiClient extends coreClient__namespace.ServiceClient {
|
|
|
2075
2541
|
const defaults = {
|
|
2076
2542
|
requestContentType: "application/json; charset=utf-8",
|
|
2077
2543
|
};
|
|
2078
|
-
const packageDetails = `azsdk-js-communication-chat/1.
|
|
2544
|
+
const packageDetails = `azsdk-js-communication-chat/1.6.0-beta.1`;
|
|
2079
2545
|
const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix
|
|
2080
2546
|
? `${options.userAgentOptions.userAgentPrefix} ${packageDetails}`
|
|
2081
2547
|
: `${packageDetails}`;
|
|
@@ -2086,7 +2552,7 @@ class ChatApiClient extends coreClient__namespace.ServiceClient {
|
|
|
2086
2552
|
// Parameter assignments
|
|
2087
2553
|
this.endpoint = endpoint;
|
|
2088
2554
|
// Assigning values to Constant parameters
|
|
2089
|
-
this.apiVersion = options.apiVersion || "2024-03-
|
|
2555
|
+
this.apiVersion = options.apiVersion || "2024-03-15-preview";
|
|
2090
2556
|
this.chatThread = new ChatThreadImpl(this);
|
|
2091
2557
|
this.chat = new ChatImpl(this);
|
|
2092
2558
|
this.addCustomApiVersionPolicy(options.apiVersion);
|
|
@@ -2122,6 +2588,190 @@ class ChatApiClient extends coreClient__namespace.ServiceClient {
|
|
|
2122
2588
|
// Licensed under the MIT license.
|
|
2123
2589
|
const logger = logger$1.createClientLogger("communication-chat");
|
|
2124
2590
|
|
|
2591
|
+
// Copyright (c) Microsoft Corporation.
|
|
2592
|
+
// Licensed under the MIT license.
|
|
2593
|
+
// Temporary workaround with local copy of XhrHttpClient
|
|
2594
|
+
function isNodeReadableStream(body) {
|
|
2595
|
+
return body && typeof body.pipe === "function";
|
|
2596
|
+
}
|
|
2597
|
+
/**
|
|
2598
|
+
* Checks if the body is a Blob or Blob-like
|
|
2599
|
+
* @internal
|
|
2600
|
+
*/
|
|
2601
|
+
function isBlob(body) {
|
|
2602
|
+
// File objects count as a type of Blob, so we want to use instanceof explicitly
|
|
2603
|
+
return (typeof Blob === "function" || typeof Blob === "object") && body instanceof Blob;
|
|
2604
|
+
}
|
|
2605
|
+
/**
|
|
2606
|
+
* Checks if the body is a ReadableStream supported by browsers
|
|
2607
|
+
* @internal
|
|
2608
|
+
*/
|
|
2609
|
+
function isReadableStream(body) {
|
|
2610
|
+
return Boolean(body &&
|
|
2611
|
+
typeof body.getReader === "function" &&
|
|
2612
|
+
typeof body.tee === "function");
|
|
2613
|
+
}
|
|
2614
|
+
/**
|
|
2615
|
+
* A HttpClient implementation that uses XMLHttpRequest to send HTTP requests.
|
|
2616
|
+
* @internal
|
|
2617
|
+
*/
|
|
2618
|
+
class XhrHttpClient {
|
|
2619
|
+
/**
|
|
2620
|
+
* Makes a request over an underlying transport layer and returns the response.
|
|
2621
|
+
* @param request - The request to be made.
|
|
2622
|
+
*/
|
|
2623
|
+
async sendRequest(request) {
|
|
2624
|
+
var _a;
|
|
2625
|
+
const url = new URL(request.url);
|
|
2626
|
+
const isInsecure = url.protocol !== "https:";
|
|
2627
|
+
if (isInsecure && !request.allowInsecureConnection) {
|
|
2628
|
+
throw new Error(`Cannot connect to ${request.url} while allowInsecureConnection is false.`);
|
|
2629
|
+
}
|
|
2630
|
+
const xhr = new XMLHttpRequest();
|
|
2631
|
+
if (request.proxySettings) {
|
|
2632
|
+
throw new Error("HTTP proxy is not supported in browser environment");
|
|
2633
|
+
}
|
|
2634
|
+
const abortSignal = request.abortSignal;
|
|
2635
|
+
if (abortSignal) {
|
|
2636
|
+
if (abortSignal.aborted) {
|
|
2637
|
+
throw new abortController.AbortError("The operation was aborted.");
|
|
2638
|
+
}
|
|
2639
|
+
const listener = () => {
|
|
2640
|
+
xhr.abort();
|
|
2641
|
+
};
|
|
2642
|
+
abortSignal.addEventListener("abort", listener);
|
|
2643
|
+
xhr.addEventListener("readystatechange", () => {
|
|
2644
|
+
if (xhr.readyState === XMLHttpRequest.DONE) {
|
|
2645
|
+
abortSignal.removeEventListener("abort", listener);
|
|
2646
|
+
}
|
|
2647
|
+
});
|
|
2648
|
+
}
|
|
2649
|
+
addProgressListener(xhr.upload, request.onUploadProgress);
|
|
2650
|
+
addProgressListener(xhr, request.onDownloadProgress);
|
|
2651
|
+
xhr.open(request.method, request.url);
|
|
2652
|
+
xhr.timeout = request.timeout;
|
|
2653
|
+
xhr.withCredentials = request.withCredentials;
|
|
2654
|
+
for (const [name, value] of request.headers) {
|
|
2655
|
+
xhr.setRequestHeader(name, value);
|
|
2656
|
+
}
|
|
2657
|
+
xhr.responseType = ((_a = request.streamResponseStatusCodes) === null || _a === void 0 ? void 0 : _a.size) ? "blob" : "text";
|
|
2658
|
+
const body = typeof request.body === "function" ? request.body() : request.body;
|
|
2659
|
+
if (isNodeReadableStream(body) || isReadableStream(body)) {
|
|
2660
|
+
throw new Error("Streams are not supported by xhrHttpClient.");
|
|
2661
|
+
}
|
|
2662
|
+
xhr.send(body === undefined ? null : body);
|
|
2663
|
+
if (xhr.responseType === "blob") {
|
|
2664
|
+
return new Promise((resolve, reject) => {
|
|
2665
|
+
handleBlobResponse(xhr, request, resolve, reject);
|
|
2666
|
+
rejectOnTerminalEvent(request, xhr, reject);
|
|
2667
|
+
});
|
|
2668
|
+
}
|
|
2669
|
+
else {
|
|
2670
|
+
return new Promise(function (resolve, reject) {
|
|
2671
|
+
xhr.addEventListener("load", () => resolve({
|
|
2672
|
+
request,
|
|
2673
|
+
status: xhr.status,
|
|
2674
|
+
headers: parseHeaders(xhr),
|
|
2675
|
+
bodyAsText: xhr.responseText,
|
|
2676
|
+
}));
|
|
2677
|
+
rejectOnTerminalEvent(request, xhr, reject);
|
|
2678
|
+
});
|
|
2679
|
+
}
|
|
2680
|
+
}
|
|
2681
|
+
}
|
|
2682
|
+
function handleBlobResponse(xhr, request, res, rej) {
|
|
2683
|
+
xhr.addEventListener("readystatechange", () => {
|
|
2684
|
+
var _a, _b;
|
|
2685
|
+
// Resolve as soon as headers are loaded
|
|
2686
|
+
if (xhr.readyState === XMLHttpRequest.HEADERS_RECEIVED) {
|
|
2687
|
+
if (
|
|
2688
|
+
// Value of POSITIVE_INFINITY in streamResponseStatusCodes is considered as any status code
|
|
2689
|
+
((_a = request.streamResponseStatusCodes) === null || _a === void 0 ? void 0 : _a.has(Number.POSITIVE_INFINITY)) ||
|
|
2690
|
+
((_b = request.streamResponseStatusCodes) === null || _b === void 0 ? void 0 : _b.has(xhr.status))) {
|
|
2691
|
+
const blobBody = new Promise((resolve, reject) => {
|
|
2692
|
+
xhr.addEventListener("load", () => {
|
|
2693
|
+
resolve(xhr.response);
|
|
2694
|
+
});
|
|
2695
|
+
rejectOnTerminalEvent(request, xhr, reject);
|
|
2696
|
+
});
|
|
2697
|
+
res({
|
|
2698
|
+
request,
|
|
2699
|
+
status: xhr.status,
|
|
2700
|
+
headers: parseHeaders(xhr),
|
|
2701
|
+
blobBody,
|
|
2702
|
+
});
|
|
2703
|
+
}
|
|
2704
|
+
else {
|
|
2705
|
+
xhr.addEventListener("load", () => {
|
|
2706
|
+
// xhr.response is of Blob type if the request is sent with xhr.responseType === "blob"
|
|
2707
|
+
// but the status code is not one of the stream response status codes,
|
|
2708
|
+
// so treat it as text and convert from Blob to text
|
|
2709
|
+
if (xhr.response) {
|
|
2710
|
+
xhr.response
|
|
2711
|
+
.text()
|
|
2712
|
+
.then((text) => {
|
|
2713
|
+
res({
|
|
2714
|
+
request: request,
|
|
2715
|
+
status: xhr.status,
|
|
2716
|
+
headers: parseHeaders(xhr),
|
|
2717
|
+
bodyAsText: text,
|
|
2718
|
+
});
|
|
2719
|
+
return;
|
|
2720
|
+
})
|
|
2721
|
+
.catch((e) => {
|
|
2722
|
+
rej(e);
|
|
2723
|
+
});
|
|
2724
|
+
}
|
|
2725
|
+
else {
|
|
2726
|
+
res({
|
|
2727
|
+
request,
|
|
2728
|
+
status: xhr.status,
|
|
2729
|
+
headers: parseHeaders(xhr),
|
|
2730
|
+
});
|
|
2731
|
+
}
|
|
2732
|
+
});
|
|
2733
|
+
}
|
|
2734
|
+
}
|
|
2735
|
+
});
|
|
2736
|
+
}
|
|
2737
|
+
function addProgressListener(xhr, listener) {
|
|
2738
|
+
if (listener) {
|
|
2739
|
+
xhr.addEventListener("progress", (rawEvent) => listener({
|
|
2740
|
+
loadedBytes: rawEvent.loaded,
|
|
2741
|
+
}));
|
|
2742
|
+
}
|
|
2743
|
+
}
|
|
2744
|
+
function parseHeaders(xhr) {
|
|
2745
|
+
const responseHeaders = coreRestPipeline.createHttpHeaders();
|
|
2746
|
+
const headerLines = xhr
|
|
2747
|
+
.getAllResponseHeaders()
|
|
2748
|
+
.trim()
|
|
2749
|
+
.split(/[\r\n]+/);
|
|
2750
|
+
for (const line of headerLines) {
|
|
2751
|
+
const index = line.indexOf(":");
|
|
2752
|
+
const headerName = line.slice(0, index);
|
|
2753
|
+
const headerValue = line.slice(index + 2);
|
|
2754
|
+
responseHeaders.set(headerName, headerValue);
|
|
2755
|
+
}
|
|
2756
|
+
return responseHeaders;
|
|
2757
|
+
}
|
|
2758
|
+
function rejectOnTerminalEvent(request, xhr, reject) {
|
|
2759
|
+
xhr.addEventListener("error", () => reject(new coreRestPipeline.RestError(`Failed to send request to ${request.url}`, {
|
|
2760
|
+
code: coreRestPipeline.RestError.REQUEST_SEND_ERROR,
|
|
2761
|
+
request,
|
|
2762
|
+
})));
|
|
2763
|
+
const abortError = new abortController.AbortError("The operation was aborted.");
|
|
2764
|
+
xhr.addEventListener("abort", () => reject(abortError));
|
|
2765
|
+
xhr.addEventListener("timeout", () => reject(abortError));
|
|
2766
|
+
}
|
|
2767
|
+
/**
|
|
2768
|
+
* Create a new HttpClient instance for the browser environment.
|
|
2769
|
+
* @internal
|
|
2770
|
+
*/
|
|
2771
|
+
function createXhrHttpClient() {
|
|
2772
|
+
return new XhrHttpClient();
|
|
2773
|
+
}
|
|
2774
|
+
|
|
2125
2775
|
// Copyright (c) Microsoft Corporation.
|
|
2126
2776
|
// Licensed under the MIT license.
|
|
2127
2777
|
/**
|
|
@@ -2159,6 +2809,10 @@ class ChatThreadClient {
|
|
|
2159
2809
|
this.client = new ChatApiClient(this.endpoint, Object.assign({ endpoint: this.endpoint }, internalPipelineOptions));
|
|
2160
2810
|
const authPolicy = createCommunicationTokenCredentialPolicy(this.tokenCredential);
|
|
2161
2811
|
this.client.pipeline.addPolicy(authPolicy);
|
|
2812
|
+
if (typeof XMLHttpRequest !== "undefined") {
|
|
2813
|
+
this.xhrClient = new ChatApiClient(this.endpoint, Object.assign(Object.assign({ endpoint: this.endpoint }, internalPipelineOptions), { httpClient: createXhrHttpClient() }));
|
|
2814
|
+
this.xhrClient.pipeline.addPolicy(authPolicy);
|
|
2815
|
+
}
|
|
2162
2816
|
}
|
|
2163
2817
|
/**
|
|
2164
2818
|
* Gets a chat thread.
|
|
@@ -2181,6 +2835,15 @@ class ChatThreadClient {
|
|
|
2181
2835
|
await this.client.chatThread.updateChatThreadProperties(this.threadId, { topic: topic }, updatedOptions);
|
|
2182
2836
|
});
|
|
2183
2837
|
}
|
|
2838
|
+
/**
|
|
2839
|
+
* Updates a thread's properties.
|
|
2840
|
+
* @param options - Operation options.
|
|
2841
|
+
*/
|
|
2842
|
+
updateProperties(options = {}) {
|
|
2843
|
+
return tracingClient.withSpan("ChatThreadClient-UpdateProperties", options, async (updatedOptions) => {
|
|
2844
|
+
await this.client.chatThread.updateChatThreadProperties(this.threadId, options, updatedOptions);
|
|
2845
|
+
});
|
|
2846
|
+
}
|
|
2184
2847
|
/**
|
|
2185
2848
|
* Sends a chat message to a thread identified by threadId.
|
|
2186
2849
|
* Returns the id of the created message.
|
|
@@ -2191,7 +2854,7 @@ class ChatThreadClient {
|
|
|
2191
2854
|
return tracingClient.withSpan("ChatThreadClient-SendMessage", options, async (updatedOptions) => {
|
|
2192
2855
|
// reset typing notification clock
|
|
2193
2856
|
this.timeOfLastTypingRequest = undefined;
|
|
2194
|
-
const result = await this.client.chatThread.sendChatMessage(this.threadId,
|
|
2857
|
+
const result = await this.client.chatThread.sendChatMessage(this.threadId, mapToSendChatMessageRequestRestModel(request, options), updatedOptions);
|
|
2195
2858
|
return result;
|
|
2196
2859
|
});
|
|
2197
2860
|
}
|
|
@@ -2297,7 +2960,7 @@ class ChatThreadClient {
|
|
|
2297
2960
|
*/
|
|
2298
2961
|
async updateMessage(messageId, options = {}) {
|
|
2299
2962
|
return tracingClient.withSpan("ChatThreadClient-UpdateMessage", options, async (updatedOptions) => {
|
|
2300
|
-
await this.client.chatThread.updateChatMessage(this.threadId, messageId, options, updatedOptions);
|
|
2963
|
+
await this.client.chatThread.updateChatMessage(this.threadId, messageId, mapToUpdateChatMessageRequestRestModel(options), updatedOptions);
|
|
2301
2964
|
});
|
|
2302
2965
|
}
|
|
2303
2966
|
/**
|
|
@@ -2506,6 +3169,72 @@ class ChatThreadClient {
|
|
|
2506
3169
|
}
|
|
2507
3170
|
return true;
|
|
2508
3171
|
}
|
|
3172
|
+
async uploadImage(image, imageFilename, imageBytesLengthOrOptions, options = {}) {
|
|
3173
|
+
let uploadImageOptions = {};
|
|
3174
|
+
if (imageBytesLengthOrOptions !== undefined) {
|
|
3175
|
+
if (typeof imageBytesLengthOrOptions === "number") {
|
|
3176
|
+
uploadImageOptions = Object.assign(Object.assign({}, options), { imageBytesLength: imageBytesLengthOrOptions });
|
|
3177
|
+
}
|
|
3178
|
+
else {
|
|
3179
|
+
uploadImageOptions = Object.assign(Object.assign({}, options), imageBytesLengthOrOptions);
|
|
3180
|
+
}
|
|
3181
|
+
}
|
|
3182
|
+
return tracingClient.withSpan("ChatThreadClient-UploadImage", uploadImageOptions, async (updatedOptions) => {
|
|
3183
|
+
let result;
|
|
3184
|
+
if (this.xhrClient && // is browser
|
|
3185
|
+
((!this.supportsReadableStream() && isReadableStream(image)) || // is readable stream but no support, need to convert
|
|
3186
|
+
!isReadableStream(image))) {
|
|
3187
|
+
// use xhrClient if (to support onUploadProgress)
|
|
3188
|
+
// - is readable stream but no support => convert to ArrayBuffer (so will have content-length)
|
|
3189
|
+
// - is not readable stream
|
|
3190
|
+
result = await this.xhrClient.chatThread.uploadChatImage(this.threadId, isReadableStream(image) ? await this.getArrayBufferFromReadableStream(image) : image, Object.assign({ imageFilename }, updatedOptions));
|
|
3191
|
+
}
|
|
3192
|
+
else {
|
|
3193
|
+
// backend (node fetch client) or readable readable stream
|
|
3194
|
+
// Backend (no browser) need to convert Blob/ReadableStream to ArrayBuffer
|
|
3195
|
+
let chatImageFile = image;
|
|
3196
|
+
if (isBlob(image)) {
|
|
3197
|
+
chatImageFile = await this.getArrayBufferFromBlob(image);
|
|
3198
|
+
}
|
|
3199
|
+
else if (isReadableStream(image)) {
|
|
3200
|
+
chatImageFile = await this.getArrayBufferFromReadableStream(image);
|
|
3201
|
+
}
|
|
3202
|
+
result = await this.client.chatThread.uploadChatImage(this.threadId, chatImageFile, Object.assign({ imageFilename }, updatedOptions));
|
|
3203
|
+
}
|
|
3204
|
+
return result;
|
|
3205
|
+
});
|
|
3206
|
+
}
|
|
3207
|
+
/**
|
|
3208
|
+
* Deletes an image identified by threadId and imageId
|
|
3209
|
+
* @param imageId - The image id of the image.
|
|
3210
|
+
* @param options - Operation options.
|
|
3211
|
+
*/
|
|
3212
|
+
deleteImage(imageId, options = {}) {
|
|
3213
|
+
return tracingClient.withSpan("ChatThreadClient-DeleteImage", options, async (updatedOptions) => {
|
|
3214
|
+
await this.client.chatThread.deleteChatImage(this.threadId, imageId, updatedOptions);
|
|
3215
|
+
});
|
|
3216
|
+
}
|
|
3217
|
+
supportsReadableStream() {
|
|
3218
|
+
let duplexAccessed = false;
|
|
3219
|
+
const hasContentType = new Request("", {
|
|
3220
|
+
body: new ReadableStream(),
|
|
3221
|
+
method: "POST",
|
|
3222
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
3223
|
+
// @ts-ignore
|
|
3224
|
+
get duplex() {
|
|
3225
|
+
duplexAccessed = true;
|
|
3226
|
+
return "half";
|
|
3227
|
+
},
|
|
3228
|
+
}).headers.has("Content-Type");
|
|
3229
|
+
return duplexAccessed && !hasContentType;
|
|
3230
|
+
}
|
|
3231
|
+
async getArrayBufferFromReadableStream(body) {
|
|
3232
|
+
const arrayBuffer = await new Response(body).arrayBuffer();
|
|
3233
|
+
return new Uint8Array(arrayBuffer);
|
|
3234
|
+
}
|
|
3235
|
+
async getArrayBufferFromBlob(body) {
|
|
3236
|
+
return new Uint8Array(await body.arrayBuffer());
|
|
3237
|
+
}
|
|
2509
3238
|
}
|
|
2510
3239
|
|
|
2511
3240
|
// Copyright (c) Microsoft Corporation.
|
|
@@ -2590,6 +3319,8 @@ class ChatClient {
|
|
|
2590
3319
|
const result = await this.client.chat.createChatThread({
|
|
2591
3320
|
topic: request.topic,
|
|
2592
3321
|
participants: (_b = options.participants) === null || _b === void 0 ? void 0 : _b.map((participant) => mapToChatParticipantRestModel(participant)),
|
|
3322
|
+
metadata: options.metadata,
|
|
3323
|
+
retentionPolicy: options.retentionPolicy,
|
|
2593
3324
|
}, updatedRestModelOptions);
|
|
2594
3325
|
return mapToCreateChatThreadResultSdkModel(result);
|
|
2595
3326
|
});
|
|
@@ -2725,10 +3456,10 @@ class ChatClient {
|
|
|
2725
3456
|
throw new Error("Realtime notifications are only supported in the browser.");
|
|
2726
3457
|
}
|
|
2727
3458
|
this.signalingClient.on("connectionChanged", (payload) => {
|
|
2728
|
-
if (payload ===
|
|
3459
|
+
if (payload === 2 /* ConnectionState.Connected */) {
|
|
2729
3460
|
this.emitter.emit("realTimeNotificationConnected");
|
|
2730
3461
|
}
|
|
2731
|
-
else if (payload ===
|
|
3462
|
+
else if (payload === 3 /* ConnectionState.Disconnected */) {
|
|
2732
3463
|
this.emitter.emit("realTimeNotificationDisconnected");
|
|
2733
3464
|
}
|
|
2734
3465
|
});
|