Skip to content

Commit f7c8787

Browse files
authored
[communication-common] Add cloud property and optional full id to identfiers, lowercase kind (Azure#13306)
1 parent 7a373d0 commit f7c8787

File tree

6 files changed

+176
-65
lines changed

6 files changed

+176
-65
lines changed

sdk/communication/communication-common/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55
### Added
66

77
- Added `MicrosoftTeamsUserIdentifier` and `isMicrosoftTeamsUserIdentifier`.
8+
- Added optional `id` property to communication identifiers.
89

910
### Breaking Changes
1011

12+
- Changed identifier `kind` property to use lowerCamelCase.
1113
- Renamed `CommunicationUserCredential` to `CommunicationTokenCredential`.
1214
- Renamed `RefreshOptions` to `CommunicationTokenRefreshOptions`.
1315
- Renamed `Identifier` to `CommunicationIdentifier`.

sdk/communication/communication-common/review/communication-common.api.md

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ export class AzureCommunicationTokenCredential implements CommunicationTokenCred
1919
}
2020

2121
// @public
22-
export interface CallingApplicationIdentifier {
22+
export interface CallingApplicationIdentifier extends WithOptionalFullId {
2323
callingApplicationId: string;
2424
}
2525

2626
// @public
2727
export interface CallingApplicationKind extends CallingApplicationIdentifier {
28-
kind: "CallingApplication";
28+
kind: "callingApplication";
2929
}
3030

3131
// @public
@@ -48,13 +48,13 @@ export interface CommunicationTokenRefreshOptions {
4848
}
4949

5050
// @public
51-
export interface CommunicationUserIdentifier {
51+
export interface CommunicationUserIdentifier extends WithOptionalFullId {
5252
communicationUserId: string;
5353
}
5454

5555
// @public
5656
export interface CommunicationUserKind extends CommunicationUserIdentifier {
57-
kind: "CommunicationUser";
57+
kind: "communicationUser";
5858
}
5959

6060
// @public
@@ -94,14 +94,15 @@ export const isPhoneNumberIdentifier: (identifier: CommunicationIdentifier) => i
9494
export const isUnknownIdentifier: (identifier: CommunicationIdentifier) => identifier is UnknownIdentifier;
9595

9696
// @public
97-
export interface MicrosoftTeamsUserIdentifier {
98-
isAnonymous: boolean | undefined;
97+
export interface MicrosoftTeamsUserIdentifier extends WithOptionalFullId {
98+
cloud?: "public" | "dod" | "gcch";
99+
isAnonymous?: boolean;
99100
microsoftTeamsUserId: string;
100101
}
101102

102103
// @public
103104
export interface MicrosoftTeamsUserKind extends MicrosoftTeamsUserIdentifier {
104-
kind: "MicrosoftTeamsUser";
105+
kind: "microsoftTeamsUser";
105106
}
106107

107108
// @public
@@ -111,20 +112,24 @@ export const parseClientArguments: (connectionStringOrUrl: string, credentialOrO
111112
export const parseConnectionString: (connectionString: string) => EndpointCredential;
112113

113114
// @public
114-
export interface PhoneNumberIdentifier {
115+
export interface PhoneNumberIdentifier extends WithOptionalFullId {
115116
phoneNumber: string;
116117
}
117118

118119
// @public
119120
export interface PhoneNumberKind extends PhoneNumberIdentifier {
120-
kind: "PhoneNumber";
121+
kind: "phoneNumber";
121122
}
122123

123124
// @internal
124125
export const _serializeCommunicationIdentifier: (identifier: CommunicationIdentifier) => _SerializedCommunicationIdentifier;
125126

127+
// @internal
128+
export type _SerializedCommunicationCloudEnvironment = "public" | "dod" | "gcch";
129+
126130
// @internal
127131
export interface _SerializedCommunicationIdentifier {
132+
cloud?: _SerializedCommunicationCloudEnvironment;
128133
id?: string;
129134
isAnonymous?: boolean;
130135
kind: _SerializedCommunicationIdentifierKind;
@@ -142,7 +147,7 @@ export interface UnknownIdentifier {
142147

143148
// @public
144149
export interface UnknownIdentifierKind extends UnknownIdentifier {
145-
kind: "Unknown";
150+
kind: "unknown";
146151
}
147152

148153
// @public
@@ -151,6 +156,11 @@ export type UrlWithCredential = {
151156
credential: TokenCredential | KeyCredential;
152157
};
153158

159+
// @public (undocumented)
160+
export interface WithOptionalFullId {
161+
id?: string;
162+
}
163+
154164

155165
// (No @packageDocumentation comment for this package)
156166

sdk/communication/communication-common/src/identifierModelSerializer.ts

Lines changed: 48 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ export interface _SerializedCommunicationIdentifier {
3333
* True if the identifier is anonymous.
3434
*/
3535
isAnonymous?: boolean;
36+
/**
37+
* The cloud that the identifier belongs to.
38+
*/
39+
cloud?: _SerializedCommunicationCloudEnvironment;
3640
}
3741

3842
/**
@@ -47,6 +51,17 @@ export type _SerializedCommunicationIdentifierKind =
4751
| "callingApplication"
4852
| "microsoftTeamsUser";
4953

54+
/**
55+
* @internal
56+
* Defines values for CommunicationCloudEnvironment.
57+
* This type is the serialized format of the CommunicationCloudEnvironment used in web requests and responses.
58+
*/
59+
export type _SerializedCommunicationCloudEnvironment = "public" | "dod" | "gcch";
60+
61+
const addIdIfExisting = <T>(identifier: T, id: string | undefined): T & { id?: string } => {
62+
return id === undefined ? identifier : { ...identifier, id };
63+
};
64+
5065
/**
5166
* @internal
5267
* Translates a CommunicationIdentifier to its serialized format for sending a request.
@@ -57,19 +72,26 @@ export const _serializeCommunicationIdentifier = (
5772
): _SerializedCommunicationIdentifier => {
5873
const identifierKind = getIdentifierKind(identifier);
5974
switch (identifierKind.kind) {
60-
case "CommunicationUser":
75+
case "communicationUser":
6176
return { kind: "communicationUser", id: identifierKind.communicationUserId };
62-
case "CallingApplication":
77+
case "callingApplication":
6378
return { kind: "callingApplication", id: identifierKind.callingApplicationId };
64-
case "PhoneNumber":
65-
return { kind: "phoneNumber", phoneNumber: identifierKind.phoneNumber };
66-
case "MicrosoftTeamsUser":
67-
return {
68-
kind: "microsoftTeamsUser",
69-
microsoftTeamsUserId: identifierKind.microsoftTeamsUserId,
70-
isAnonymous: identifierKind.isAnonymous
71-
};
72-
case "Unknown":
79+
case "phoneNumber":
80+
return addIdIfExisting(
81+
{ kind: "phoneNumber", phoneNumber: identifierKind.phoneNumber },
82+
identifierKind.id
83+
);
84+
case "microsoftTeamsUser":
85+
return addIdIfExisting(
86+
{
87+
kind: "microsoftTeamsUser",
88+
microsoftTeamsUserId: identifierKind.microsoftTeamsUserId,
89+
isAnonymous: identifierKind.isAnonymous ?? false,
90+
cloud: identifierKind.cloud ?? "public"
91+
},
92+
identifierKind.id
93+
);
94+
case "unknown":
7395
return { kind: "unknown", id: identifierKind.id };
7496
default:
7597
throw new Error(`Can't serialize an identifier with kind ${(identifierKind as any).kind}`);
@@ -87,32 +109,37 @@ export const _deserializeCommunicationIdentifier = (
87109
switch (serializedIdentifier.kind) {
88110
case "communicationUser":
89111
return {
90-
kind: "CommunicationUser",
91-
communicationUserId: assertNotNullOrUndefined(serializedIdentifier, "id")
112+
kind: "communicationUser",
113+
communicationUserId: assertNotNullOrUndefined(serializedIdentifier, "id"),
114+
id: assertNotNullOrUndefined(serializedIdentifier, "id")
92115
};
93116
case "callingApplication":
94117
return {
95-
kind: "CallingApplication",
96-
callingApplicationId: assertNotNullOrUndefined(serializedIdentifier, "id")
118+
kind: "callingApplication",
119+
callingApplicationId: assertNotNullOrUndefined(serializedIdentifier, "id"),
120+
id: assertNotNullOrUndefined(serializedIdentifier, "id")
97121
};
98122
case "phoneNumber":
99123
return {
100-
kind: "PhoneNumber",
101-
phoneNumber: assertNotNullOrUndefined(serializedIdentifier, "phoneNumber")
124+
kind: "phoneNumber",
125+
phoneNumber: assertNotNullOrUndefined(serializedIdentifier, "phoneNumber"),
126+
id: assertNotNullOrUndefined(serializedIdentifier, "id")
102127
};
103128
case "microsoftTeamsUser":
104129
return {
105-
kind: "MicrosoftTeamsUser",
130+
kind: "microsoftTeamsUser",
106131
microsoftTeamsUserId: assertNotNullOrUndefined(
107132
serializedIdentifier,
108133
"microsoftTeamsUserId"
109134
),
110-
isAnonymous: assertNotNullOrUndefined(serializedIdentifier, "isAnonymous")
135+
isAnonymous: assertNotNullOrUndefined(serializedIdentifier, "isAnonymous"),
136+
cloud: assertNotNullOrUndefined(serializedIdentifier, "cloud"),
137+
id: assertNotNullOrUndefined(serializedIdentifier, "id")
111138
};
112139
case "unknown":
113-
return { kind: "Unknown", id: assertNotNullOrUndefined(serializedIdentifier, "id") };
140+
return { kind: "unknown", id: assertNotNullOrUndefined(serializedIdentifier, "id") };
114141
default:
115-
return { kind: "Unknown", id: assertNotNullOrUndefined(serializedIdentifier, "id") };
142+
return { kind: "unknown", id: assertNotNullOrUndefined(serializedIdentifier, "id") };
116143
}
117144
};
118145

sdk/communication/communication-common/src/identifierModels.ts

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,17 @@ export type CommunicationIdentifier =
1111
| MicrosoftTeamsUserIdentifier
1212
| UnknownIdentifier;
1313

14+
export interface WithOptionalFullId {
15+
/**
16+
* Optional full id of the identifier.
17+
*/
18+
id?: string;
19+
}
20+
1421
/**
1522
* An Azure Communication user.
1623
*/
17-
export interface CommunicationUserIdentifier {
24+
export interface CommunicationUserIdentifier extends WithOptionalFullId {
1825
/**
1926
* Id of the CommunicationUser as returned from the Communication Service.
2027
*/
@@ -24,7 +31,7 @@ export interface CommunicationUserIdentifier {
2431
/**
2532
* A phone number.
2633
*/
27-
export interface PhoneNumberIdentifier {
34+
export interface PhoneNumberIdentifier extends WithOptionalFullId {
2835
/**
2936
* The phone number in E.164 format.
3037
*/
@@ -34,7 +41,7 @@ export interface PhoneNumberIdentifier {
3441
/**
3542
* A calling application, i.e. a non-human participant in communication.
3643
*/
37-
export interface CallingApplicationIdentifier {
44+
export interface CallingApplicationIdentifier extends WithOptionalFullId {
3845
/**
3946
* Id of the CallingApplication.
4047
*/
@@ -44,16 +51,21 @@ export interface CallingApplicationIdentifier {
4451
/**
4552
* A Microsoft Teams user.
4653
*/
47-
export interface MicrosoftTeamsUserIdentifier {
54+
export interface MicrosoftTeamsUserIdentifier extends WithOptionalFullId {
4855
/**
4956
* Id of the Microsoft Teams user. If the user isn't anonymous, the id is the AAD object id of the user.
5057
*/
5158
microsoftTeamsUserId: string;
5259

5360
/**
54-
* True if the user is anonymous, for example when joining a meeting with a share link.
61+
* True if the user is anonymous, for example when joining a meeting with a share link. If missing, the user is not anonymous.
62+
*/
63+
isAnonymous?: boolean;
64+
65+
/**
66+
* The cloud that the Microsoft Teams user belongs to. If missing, the cloud is "public".
5567
*/
56-
isAnonymous: boolean | undefined;
68+
cloud?: "public" | "dod" | "gcch";
5769
}
5870

5971
/**
@@ -138,7 +150,7 @@ export interface CommunicationUserKind extends CommunicationUserIdentifier {
138150
/**
139151
* The identifier kind.
140152
*/
141-
kind: "CommunicationUser";
153+
kind: "communicationUser";
142154
}
143155

144156
/**
@@ -148,7 +160,7 @@ export interface PhoneNumberKind extends PhoneNumberIdentifier {
148160
/**
149161
* The identifier kind.
150162
*/
151-
kind: "PhoneNumber";
163+
kind: "phoneNumber";
152164
}
153165

154166
/**
@@ -158,7 +170,7 @@ export interface CallingApplicationKind extends CallingApplicationIdentifier {
158170
/**
159171
* The identifier kind.
160172
*/
161-
kind: "CallingApplication";
173+
kind: "callingApplication";
162174
}
163175

164176
/**
@@ -168,7 +180,7 @@ export interface MicrosoftTeamsUserKind extends MicrosoftTeamsUserIdentifier {
168180
/**
169181
* The identifier kind.
170182
*/
171-
kind: "MicrosoftTeamsUser";
183+
kind: "microsoftTeamsUser";
172184
}
173185

174186
/**
@@ -178,7 +190,7 @@ export interface UnknownIdentifierKind extends UnknownIdentifier {
178190
/**
179191
* The identifier kind.
180192
*/
181-
kind: "Unknown";
193+
kind: "unknown";
182194
}
183195

184196
/**
@@ -190,16 +202,16 @@ export const getIdentifierKind = (
190202
identifier: CommunicationIdentifier
191203
): CommunicationIdentifierKind => {
192204
if (isCommunicationUserIdentifier(identifier)) {
193-
return { ...identifier, kind: "CommunicationUser" };
205+
return { ...identifier, kind: "communicationUser" };
194206
}
195207
if (isPhoneNumberIdentifier(identifier)) {
196-
return { ...identifier, kind: "PhoneNumber" };
208+
return { ...identifier, kind: "phoneNumber" };
197209
}
198210
if (isCallingApplicationIdentifier(identifier)) {
199-
return { ...identifier, kind: "CallingApplication" };
211+
return { ...identifier, kind: "callingApplication" };
200212
}
201213
if (isMicrosoftTeamsUserIdentifier(identifier)) {
202-
return { ...identifier, kind: "MicrosoftTeamsUser" };
214+
return { ...identifier, kind: "microsoftTeamsUser" };
203215
}
204-
return { ...identifier, kind: "Unknown" };
216+
return { ...identifier, kind: "unknown" };
205217
};

0 commit comments

Comments
 (0)