@azure/communication-common 2.3.2-alpha.20250314.1 → 2.3.2-alpha.20250317.3

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.
Files changed (82) hide show
  1. package/README.md +48 -0
  2. package/dist/browser/azureCommunicationTokenCredential.d.ts +6 -0
  3. package/dist/browser/azureCommunicationTokenCredential.d.ts.map +1 -1
  4. package/dist/browser/azureCommunicationTokenCredential.js +8 -4
  5. package/dist/browser/azureCommunicationTokenCredential.js.map +1 -1
  6. package/dist/browser/entraTokenCredential.d.ts +44 -0
  7. package/dist/browser/entraTokenCredential.d.ts.map +1 -0
  8. package/dist/browser/entraTokenCredential.js +120 -0
  9. package/dist/browser/entraTokenCredential.js.map +1 -0
  10. package/dist/browser/identifierModelSerializer.d.ts +35 -1
  11. package/dist/browser/identifierModelSerializer.d.ts.map +1 -1
  12. package/dist/browser/identifierModelSerializer.js +42 -8
  13. package/dist/browser/identifierModelSerializer.js.map +1 -1
  14. package/dist/browser/identifierModels.d.ts +52 -4
  15. package/dist/browser/identifierModels.d.ts.map +1 -1
  16. package/dist/browser/identifierModels.js +60 -2
  17. package/dist/browser/identifierModels.js.map +1 -1
  18. package/dist/browser/index.d.ts +1 -1
  19. package/dist/browser/index.d.ts.map +1 -1
  20. package/dist/browser/index.js +0 -1
  21. package/dist/browser/index.js.map +1 -1
  22. package/dist/commonjs/azureCommunicationTokenCredential.d.ts +6 -0
  23. package/dist/commonjs/azureCommunicationTokenCredential.d.ts.map +1 -1
  24. package/dist/commonjs/azureCommunicationTokenCredential.js +8 -4
  25. package/dist/commonjs/azureCommunicationTokenCredential.js.map +1 -1
  26. package/dist/commonjs/entraTokenCredential.d.ts +44 -0
  27. package/dist/commonjs/entraTokenCredential.d.ts.map +1 -0
  28. package/dist/commonjs/entraTokenCredential.js +124 -0
  29. package/dist/commonjs/entraTokenCredential.js.map +1 -0
  30. package/dist/commonjs/identifierModelSerializer.d.ts +35 -1
  31. package/dist/commonjs/identifierModelSerializer.d.ts.map +1 -1
  32. package/dist/commonjs/identifierModelSerializer.js +42 -8
  33. package/dist/commonjs/identifierModelSerializer.js.map +1 -1
  34. package/dist/commonjs/identifierModels.d.ts +52 -4
  35. package/dist/commonjs/identifierModels.d.ts.map +1 -1
  36. package/dist/commonjs/identifierModels.js +62 -3
  37. package/dist/commonjs/identifierModels.js.map +1 -1
  38. package/dist/commonjs/index.d.ts +1 -1
  39. package/dist/commonjs/index.d.ts.map +1 -1
  40. package/dist/commonjs/index.js +0 -1
  41. package/dist/commonjs/index.js.map +1 -1
  42. package/dist/esm/azureCommunicationTokenCredential.d.ts +6 -0
  43. package/dist/esm/azureCommunicationTokenCredential.d.ts.map +1 -1
  44. package/dist/esm/azureCommunicationTokenCredential.js +8 -4
  45. package/dist/esm/azureCommunicationTokenCredential.js.map +1 -1
  46. package/dist/esm/entraTokenCredential.d.ts +44 -0
  47. package/dist/esm/entraTokenCredential.d.ts.map +1 -0
  48. package/dist/esm/entraTokenCredential.js +120 -0
  49. package/dist/esm/entraTokenCredential.js.map +1 -0
  50. package/dist/esm/identifierModelSerializer.d.ts +35 -1
  51. package/dist/esm/identifierModelSerializer.d.ts.map +1 -1
  52. package/dist/esm/identifierModelSerializer.js +42 -8
  53. package/dist/esm/identifierModelSerializer.js.map +1 -1
  54. package/dist/esm/identifierModels.d.ts +52 -4
  55. package/dist/esm/identifierModels.d.ts.map +1 -1
  56. package/dist/esm/identifierModels.js +60 -2
  57. package/dist/esm/identifierModels.js.map +1 -1
  58. package/dist/esm/index.d.ts +1 -1
  59. package/dist/esm/index.d.ts.map +1 -1
  60. package/dist/esm/index.js +0 -1
  61. package/dist/esm/index.js.map +1 -1
  62. package/dist/react-native/azureCommunicationTokenCredential.d.ts +6 -0
  63. package/dist/react-native/azureCommunicationTokenCredential.d.ts.map +1 -1
  64. package/dist/react-native/azureCommunicationTokenCredential.js +8 -4
  65. package/dist/react-native/azureCommunicationTokenCredential.js.map +1 -1
  66. package/dist/react-native/entraTokenCredential.d.ts +44 -0
  67. package/dist/react-native/entraTokenCredential.d.ts.map +1 -0
  68. package/dist/react-native/entraTokenCredential.js +120 -0
  69. package/dist/react-native/entraTokenCredential.js.map +1 -0
  70. package/dist/react-native/identifierModelSerializer.d.ts +35 -1
  71. package/dist/react-native/identifierModelSerializer.d.ts.map +1 -1
  72. package/dist/react-native/identifierModelSerializer.js +42 -8
  73. package/dist/react-native/identifierModelSerializer.js.map +1 -1
  74. package/dist/react-native/identifierModels.d.ts +52 -4
  75. package/dist/react-native/identifierModels.d.ts.map +1 -1
  76. package/dist/react-native/identifierModels.js +60 -2
  77. package/dist/react-native/identifierModels.js.map +1 -1
  78. package/dist/react-native/index.d.ts +1 -1
  79. package/dist/react-native/index.d.ts.map +1 -1
  80. package/dist/react-native/index.js +0 -1
  81. package/dist/react-native/index.js.map +1 -1
  82. package/package.json +5 -2
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Identifies a communication participant.
3
3
  */
4
- export type CommunicationIdentifier = CommunicationUserIdentifier | PhoneNumberIdentifier | MicrosoftTeamsUserIdentifier | MicrosoftTeamsAppIdentifier | UnknownIdentifier;
4
+ export type CommunicationIdentifier = CommunicationUserIdentifier | PhoneNumberIdentifier | MicrosoftTeamsUserIdentifier | MicrosoftTeamsAppIdentifier | TeamsExtensionUserIdentifier | UnknownIdentifier;
5
5
  /**
6
6
  * An Azure Communication user.
7
7
  */
@@ -23,6 +23,14 @@ export interface PhoneNumberIdentifier {
23
23
  * The phone number in E.164 format.
24
24
  */
25
25
  phoneNumber: string;
26
+ /**
27
+ * The asserted Id is set on a phone number that is already in the same call to distinguish from other connections made through the same number.
28
+ */
29
+ assertedId?: string;
30
+ /**
31
+ * True if the phone number is anonymous.
32
+ */
33
+ isAnonymous?: boolean;
26
34
  }
27
35
  /**
28
36
  * A Microsoft Teams user.
@@ -33,7 +41,7 @@ export interface MicrosoftTeamsUserIdentifier {
33
41
  */
34
42
  rawId?: string;
35
43
  /**
36
- * Id of the Microsoft Teams user. If the user isn't anonymous, the id is the AAD object id of the user.
44
+ * Id of the Microsoft Teams user. If the user isn't anonymous, the id is the Entra ID object id of the user.
37
45
  */
38
46
  microsoftTeamsUserId: string;
39
47
  /**
@@ -58,7 +66,32 @@ export interface MicrosoftTeamsAppIdentifier {
58
66
  */
59
67
  teamsAppId: string;
60
68
  /**
61
- * The cloud that the Microsoft Temas App belongs to. If missing, the cloud is "public".
69
+ * The cloud that the Microsoft Teams App belongs to. If missing, the cloud is "public".
70
+ */
71
+ cloud?: "public" | "dod" | "gcch";
72
+ }
73
+ /**
74
+ * A Microsoft Teams Phone user who is using the Azure Communication Services resource to extend their Teams Phone set up.
75
+ */
76
+ export interface TeamsExtensionUserIdentifier {
77
+ /**
78
+ * Optional raw id of the Microsoft Teams Extension user.
79
+ */
80
+ rawId?: string;
81
+ /**
82
+ * The Id of the Microsoft Teams Extension user, i.e. the Entra ID object Id of the user.
83
+ */
84
+ userId: string;
85
+ /**
86
+ * The tenant Id of the Microsoft Teams Extension user.
87
+ */
88
+ tenantId: string;
89
+ /**
90
+ * The Azure Communication Services resource Id.
91
+ */
92
+ resourceId: string;
93
+ /**
94
+ * The cloud that the Microsoft Teams Extension user belongs to. If missing, the cloud is "public".
62
95
  */
63
96
  cloud?: "public" | "dod" | "gcch";
64
97
  }
@@ -95,6 +128,12 @@ export declare const isMicrosoftTeamsUserIdentifier: (identifier: CommunicationI
95
128
  * @param identifier - The assumed available to be tested.
96
129
  */
97
130
  export declare const isMicrosoftTeamsAppIdentifier: (identifier: CommunicationIdentifier) => identifier is MicrosoftTeamsAppIdentifier;
131
+ /**
132
+ * Tests an Identifier to determine whether it implements TeamsExtensionUserIdentifier.
133
+ *
134
+ * @param identifier - The assumed available to be tested.
135
+ */
136
+ export declare const isTeamsExtensionUserIdentifier: (identifier: CommunicationIdentifier) => identifier is TeamsExtensionUserIdentifier;
98
137
  /**
99
138
  * Tests an Identifier to determine whether it implements UnknownIdentifier.
100
139
  *
@@ -104,7 +143,7 @@ export declare const isUnknownIdentifier: (identifier: CommunicationIdentifier)
104
143
  /**
105
144
  * The CommunicationIdentifierKind is a discriminated union that adds a property `kind` to an Identifier.
106
145
  */
107
- export type CommunicationIdentifierKind = CommunicationUserKind | PhoneNumberKind | MicrosoftTeamsUserKind | MicrosoftTeamsAppKind | UnknownIdentifierKind;
146
+ export type CommunicationIdentifierKind = CommunicationUserKind | PhoneNumberKind | MicrosoftTeamsUserKind | MicrosoftTeamsAppKind | TeamsExtensionUserKind | UnknownIdentifierKind;
108
147
  /**
109
148
  * IdentifierKind for a CommunicationUserIdentifier.
110
149
  */
@@ -141,6 +180,15 @@ export interface MicrosoftTeamsAppKind extends MicrosoftTeamsAppIdentifier {
141
180
  */
142
181
  kind: "microsoftTeamsApp";
143
182
  }
183
+ /**
184
+ * IdentifierKind for a TeamsExtensionUserIdentifier.
185
+ */
186
+ export interface TeamsExtensionUserKind extends TeamsExtensionUserIdentifier {
187
+ /**
188
+ * The identifier kind.
189
+ */
190
+ kind: "teamsExtensionUser";
191
+ }
144
192
  /**
145
193
  * IdentifierKind for UnknownIdentifier.
146
194
  */
@@ -1 +1 @@
1
- {"version":3,"file":"identifierModels.d.ts","sourceRoot":"","sources":["../../src/identifierModels.ts"],"names":[],"mappings":"AAGA;;GAEG;AACH,MAAM,MAAM,uBAAuB,GAC/B,2BAA2B,GAC3B,qBAAqB,GACrB,4BAA4B,GAC5B,2BAA2B,GAC3B,iBAAiB,CAAC;AAEtB;;GAEG;AACH,MAAM,WAAW,2BAA2B;IAC1C;;OAEG;IACH,mBAAmB,EAAE,MAAM,CAAC;CAC7B;AAED;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC;CACrB;AAED;;GAEG;AACH,MAAM,WAAW,4BAA4B;IAC3C;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf;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EG;AACH,MAAM,MAAM,2BAA2B,GACnC,qBAAqB,GACrB,eAAe,GACf,sBAAsB,GACtB,qBAAqB,GACrB,sBAAsB,GACtB,qBAAqB,CAAC;AAE1B;;GAEG;AACH,MAAM,WAAW,qBAAsB,SAAQ,2BAA2B;IACxE;;OAEG;IACH,IAAI,EAAE,mBAAmB,CAAC;CAC3B;AAED;;GAEG;AACH,MAAM,WAAW,eAAgB,SAAQ,qBAAqB;IAC5D;;OAEG;IACH,IAAI,EAAE,aAAa,CAAC;CACrB;AAED;;GAEG;AACH,MAAM,WAAW,sBAAuB,SAAQ,4BAA4B;IAC1E;;OAEG;IACH,IAAI,EAAE,oBAAoB,CAAC;CAC5B;AAED;;GAEG;AACH,MAAM,WAAW,qBAAsB,SAAQ,2BAA2B;IACxE;;OAEG;IACH,IAAI,EAAE,mBAAmB,CAAC;CAC3B;AAED;;GAEG;AACH,MAAM,WAAW,sBAAuB,SAAQ,4BAA4B;IAC1E;;OAEG;IACH,IAAI,EAAE,oBAAoB,CAAC;CAC5B;AAED;;GAEG;AACH,MAAM,WAAW,qBAAsB,SAAQ,iBAAiB;IAC9D;;OAEG;IACH,IAAI,EAAE,SAAS,CAAC;CACjB;AAED;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,eAChB,uBAAuB,KAClC,2BAiBF,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,kBAAkB,eAAgB,uBAAuB,KAAG,MAkDxE,CAAC;AA+DF;;;;GAIG;AACH,eAAO,MAAM,yBAAyB,UAAW,MAAM,KAAG,2BAsCzD,CAAC"}
@@ -32,6 +32,17 @@ export const isMicrosoftTeamsUserIdentifier = (identifier) => {
32
32
  export const isMicrosoftTeamsAppIdentifier = (identifier) => {
33
33
  return typeof identifier.teamsAppId === "string";
34
34
  };
35
+ /**
36
+ * Tests an Identifier to determine whether it implements TeamsExtensionUserIdentifier.
37
+ *
38
+ * @param identifier - The assumed available to be tested.
39
+ */
40
+ export const isTeamsExtensionUserIdentifier = (identifier) => {
41
+ const userIdExists = typeof identifier.userId === "string";
42
+ const tenantIdExists = typeof identifier.tenantId === "string";
43
+ const resourceIdExists = typeof identifier.resourceId === "string";
44
+ return userIdExists && tenantIdExists && resourceIdExists;
45
+ };
35
46
  /**
36
47
  * Tests an Identifier to determine whether it implements UnknownIdentifier.
37
48
  *
@@ -58,6 +69,9 @@ export const getIdentifierKind = (identifier) => {
58
69
  if (isMicrosoftTeamsAppIdentifier(identifier)) {
59
70
  return Object.assign(Object.assign({}, identifier), { kind: "microsoftTeamsApp" });
60
71
  }
72
+ if (isTeamsExtensionUserIdentifier(identifier)) {
73
+ return Object.assign(Object.assign({}, identifier), { kind: "teamsExtensionUser" });
74
+ }
61
75
  return Object.assign(Object.assign({}, identifier), { kind: "unknown" });
62
76
  };
63
77
  /**
@@ -104,6 +118,18 @@ export const getIdentifierRawId = (identifier) => {
104
118
  return rawId;
105
119
  return `4:${phoneNumber}`;
106
120
  }
121
+ case "teamsExtensionUser": {
122
+ const { userId, tenantId, resourceId, rawId, cloud } = identifierKind;
123
+ if (rawId)
124
+ return rawId;
125
+ switch (cloud) {
126
+ case "dod":
127
+ return `8:dod-acs:${resourceId}_${tenantId}_${userId}`;
128
+ case "gcch":
129
+ return `8:gcch-acs:${resourceId}_${tenantId}_${userId}`;
130
+ }
131
+ return `8:acs:${resourceId}_${tenantId}_${userId}`;
132
+ }
107
133
  case "unknown": {
108
134
  return identifierKind.id;
109
135
  }
@@ -124,6 +150,35 @@ const buildMicrosoftTeamsUserIdentifier = (id, cloud, isAnonymous) => {
124
150
  cloud: cloud,
125
151
  };
126
152
  };
153
+ const buildTeamsExtensionUserOrCommunicationUserIdentifier = (rawId, suffix, cloud) => {
154
+ const segments = suffix.split("_");
155
+ if (segments.length !== 3) {
156
+ return { kind: "communicationUser", communicationUserId: rawId };
157
+ }
158
+ const resourceId = segments[0];
159
+ const tenantId = segments[1];
160
+ const userId = segments[2];
161
+ return {
162
+ kind: "teamsExtensionUser",
163
+ userId: userId,
164
+ tenantId: tenantId,
165
+ resourceId: resourceId,
166
+ cloud: cloud,
167
+ };
168
+ };
169
+ const buildPhoneNumberIdentifier = (rawId) => {
170
+ const phoneNumber = rawId.substring("4:".length);
171
+ const isAnonymous = phoneNumber === "anonymous";
172
+ const assertedIdIndex = isAnonymous ? -1 : phoneNumber.lastIndexOf("_") + 1;
173
+ const hasAssertedId = assertedIdIndex > 0 && assertedIdIndex < phoneNumber.length;
174
+ const assertedId = hasAssertedId ? phoneNumber.substring(assertedIdIndex) : undefined;
175
+ return {
176
+ kind: "phoneNumber",
177
+ phoneNumber: phoneNumber,
178
+ isAnonymous: isAnonymous,
179
+ assertedId: assertedId,
180
+ };
181
+ };
127
182
  /**
128
183
  * Creates a CommunicationIdentifierKind from a given rawId. When storing rawIds use this function to restore the identifier that was encoded in the rawId.
129
184
  *
@@ -131,7 +186,7 @@ const buildMicrosoftTeamsUserIdentifier = (id, cloud, isAnonymous) => {
131
186
  */
132
187
  export const createIdentifierFromRawId = (rawId) => {
133
188
  if (rawId.startsWith("4:")) {
134
- return { kind: "phoneNumber", phoneNumber: `${rawId.substring("4:".length)}` };
189
+ return buildPhoneNumberIdentifier(rawId);
135
190
  }
136
191
  const segments = rawId.split(":");
137
192
  if (segments.length !== 3) {
@@ -149,9 +204,12 @@ export const createIdentifierFromRawId = (rawId) => {
149
204
  case "8:gcch:":
150
205
  return buildMicrosoftTeamsUserIdentifier(suffix, "gcch", false);
151
206
  case "8:acs:":
152
- case "8:spool:":
207
+ return buildTeamsExtensionUserOrCommunicationUserIdentifier(rawId, suffix, "public");
153
208
  case "8:dod-acs:":
209
+ return buildTeamsExtensionUserOrCommunicationUserIdentifier(rawId, suffix, "dod");
154
210
  case "8:gcch-acs:":
211
+ return buildTeamsExtensionUserOrCommunicationUserIdentifier(rawId, suffix, "gcch");
212
+ case "8:spool:":
155
213
  return { kind: "communicationUser", communicationUserId: rawId };
156
214
  case "28:orgid:":
157
215
  return buildMicrosoftTeamsAppIdentifier(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C;QAC1B,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,EAAE,EAAE,KAAK,EAAE,CAAC;IACxC,CAAC;IAED,MAAM,MAAM,GAAG,GAAG,QAAQ,CAAC,CAAC,CAAC,IAAI,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC;IAChD,MAAM,MAAM,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC;IAE3B,QAAQ,MAAM,EAAE,CAAC;QACf,KAAK,iBAAiB;YACpB,OAAO,EAAE,IAAI,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,MAAM,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC;QACzF,KAAK,UAAU;YACb,OAAO,iCAAiC,CAAC,MAAM,EAAE,QAAQ,EAAE,KAAK,CAAC,CAAC;QACpE,KAAK,QAAQ;YACX,OAAO,iCAAiC,CAAC,MAAM,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;QACjE,KAAK,SAAS;YACZ,OAAO,iCAAiC,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;QAClE,KAAK,QAAQ,CAAC;QACd,KAAK,UAAU,CAAC;QAChB,KAAK,YAAY,CAAC;QAClB,KAAK,aAAa;YAChB,OAAO,EAAE,IAAI,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,KAAK,EAAE,CAAC;QACnE,KAAK,WAAW;YACd,OAAO,gCAAgC,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;QAC5D,KAAK,UAAU;YACb,OAAO,gCAAgC,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QAC1D,KAAK,SAAS;YACZ,OAAO,gCAAgC,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IAC3D,CAAC;IACD,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,EAAE,EAAE,KAAK,EAAE,CAAC;AACxC,CAAC,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\n/**\n * Identifies a communication participant.\n */\nexport type CommunicationIdentifier =\n | CommunicationUserIdentifier\n | PhoneNumberIdentifier\n | MicrosoftTeamsUserIdentifier\n | MicrosoftTeamsAppIdentifier\n | UnknownIdentifier;\n\n/**\n * An Azure Communication user.\n */\nexport interface CommunicationUserIdentifier {\n /**\n * Id of the CommunicationUser as returned from the Communication Service.\n */\n communicationUserId: string;\n}\n\n/**\n * A phone number.\n */\nexport interface PhoneNumberIdentifier {\n /**\n * Optional raw id of the phone number.\n */\n rawId?: string;\n /**\n * The phone number in E.164 format.\n */\n phoneNumber: string;\n}\n\n/**\n * A Microsoft Teams user.\n */\nexport interface MicrosoftTeamsUserIdentifier {\n /**\n * Optional raw id of the Microsoft Teams user.\n */\n rawId?: string;\n\n /**\n * Id of the Microsoft Teams user. If the user isn't anonymous, the id is the AAD object id of the user.\n */\n microsoftTeamsUserId: string;\n\n /**\n * True if the user is anonymous, for example when joining a meeting with a share link. If missing, the user is not anonymous.\n */\n isAnonymous?: boolean;\n\n /**\n * The cloud that the Microsoft Teams user belongs to. If missing, the cloud is \"public\".\n */\n cloud?: \"public\" | \"dod\" | \"gcch\";\n}\n\n/**\n * A Microsoft Teams App.\n */\nexport interface MicrosoftTeamsAppIdentifier {\n /**\n * Optional raw id of the Microsoft Teams App.\n */\n rawId?: string;\n\n /**\n * The unique Microsoft Teams app ID.\n */\n teamsAppId: string;\n\n /**\n * The cloud that the Microsoft Temas App belongs to. If missing, the cloud is \"public\".\n */\n cloud?: \"public\" | \"dod\" | \"gcch\";\n}\n\n/**\n * An unknown identifier that doesn't fit any of the other identifier types.\n */\nexport interface UnknownIdentifier {\n /**\n * Id of the UnknownIdentifier.\n */\n id: string;\n}\n\n/**\n * Tests an Identifier to determine whether it implements CommunicationUserIdentifier.\n *\n * @param identifier - The assumed CommunicationUserIdentifier to be tested.\n */\nexport const isCommunicationUserIdentifier = (\n identifier: CommunicationIdentifier,\n): identifier is CommunicationUserIdentifier => {\n return typeof (identifier as any).communicationUserId === \"string\";\n};\n\n/**\n * Tests an Identifier to determine whether it implements PhoneNumberIdentifier.\n *\n * @param identifier - The assumed PhoneNumberIdentifier to be tested.\n */\nexport const isPhoneNumberIdentifier = (\n identifier: CommunicationIdentifier,\n): identifier is PhoneNumberIdentifier => {\n return typeof (identifier as any).phoneNumber === \"string\";\n};\n\n/**\n * Tests an Identifier to determine whether it implements MicrosoftTeamsUserIdentifier.\n *\n * @param identifier - The assumed available to be tested.\n */\nexport const isMicrosoftTeamsUserIdentifier = (\n identifier: CommunicationIdentifier,\n): identifier is MicrosoftTeamsUserIdentifier => {\n return typeof (identifier as any).microsoftTeamsUserId === \"string\";\n};\n\n/**\n * Tests an Identifier to determine whether it implements MicrosoftTeamsAppIdentifier.\n *\n * @param identifier - The assumed available to be tested.\n */\nexport const isMicrosoftTeamsAppIdentifier = (\n identifier: CommunicationIdentifier,\n): identifier is MicrosoftTeamsAppIdentifier => {\n return typeof (identifier as any).teamsAppId === \"string\";\n};\n\n/**\n * Tests an Identifier to determine whether it implements UnknownIdentifier.\n *\n * @param identifier - The assumed UnknownIdentifier to be tested.\n */\nexport const isUnknownIdentifier = (\n identifier: CommunicationIdentifier,\n): identifier is UnknownIdentifier => {\n return typeof (identifier as any).id === \"string\";\n};\n\n/**\n * The CommunicationIdentifierKind is a discriminated union that adds a property `kind` to an Identifier.\n */\nexport type CommunicationIdentifierKind =\n | CommunicationUserKind\n | PhoneNumberKind\n | MicrosoftTeamsUserKind\n | MicrosoftTeamsAppKind\n | UnknownIdentifierKind;\n\n/**\n * IdentifierKind for a CommunicationUserIdentifier.\n */\nexport interface CommunicationUserKind extends CommunicationUserIdentifier {\n /**\n * The identifier kind.\n */\n kind: \"communicationUser\";\n}\n\n/**\n * IdentifierKind for a PhoneNumberIdentifier.\n */\nexport interface PhoneNumberKind extends PhoneNumberIdentifier {\n /**\n * The identifier kind.\n */\n kind: \"phoneNumber\";\n}\n\n/**\n * IdentifierKind for a MicrosoftTeamsUserIdentifier.\n */\nexport interface MicrosoftTeamsUserKind extends MicrosoftTeamsUserIdentifier {\n /**\n * The identifier kind.\n */\n kind: \"microsoftTeamsUser\";\n}\n\n/**\n * IdentifierKind for a MicrosoftTeamsAppIdentifier.\n */\nexport interface MicrosoftTeamsAppKind extends MicrosoftTeamsAppIdentifier {\n /**\n * The identifier kind.\n */\n kind: \"microsoftTeamsApp\";\n}\n\n/**\n * IdentifierKind for UnknownIdentifier.\n */\nexport interface UnknownIdentifierKind extends UnknownIdentifier {\n /**\n * The identifier kind.\n */\n kind: \"unknown\";\n}\n\n/**\n * Returns the CommunicationIdentifierKind for a given CommunicationIdentifier. Returns undefined if the kind couldn't be inferred.\n *\n * @param identifier - The identifier whose kind is to be inferred.\n */\nexport const getIdentifierKind = (\n identifier: CommunicationIdentifier,\n): CommunicationIdentifierKind => {\n if (isCommunicationUserIdentifier(identifier)) {\n return { ...identifier, kind: \"communicationUser\" };\n }\n if (isPhoneNumberIdentifier(identifier)) {\n return { ...identifier, kind: \"phoneNumber\" };\n }\n if (isMicrosoftTeamsUserIdentifier(identifier)) {\n return { ...identifier, kind: \"microsoftTeamsUser\" };\n }\n if (isMicrosoftTeamsAppIdentifier(identifier)) {\n return { ...identifier, kind: \"microsoftTeamsApp\" };\n }\n return { ...identifier, kind: \"unknown\" };\n};\n\n/**\n * Returns the rawId for a given CommunicationIdentifier. You can use the rawId for encoding the identifier and then use it as a key in a database.\n *\n * @param identifier - The identifier to be translated to its rawId.\n */\nexport const getIdentifierRawId = (identifier: CommunicationIdentifier): string => {\n const identifierKind = getIdentifierKind(identifier);\n switch (identifierKind.kind) {\n case \"communicationUser\":\n return identifierKind.communicationUserId;\n case \"microsoftTeamsUser\": {\n const { microsoftTeamsUserId, rawId, cloud, isAnonymous } = identifierKind;\n if (rawId) return rawId;\n if (isAnonymous) return `8:teamsvisitor:${microsoftTeamsUserId}`;\n switch (cloud) {\n case \"dod\":\n return `8:dod:${microsoftTeamsUserId}`;\n case \"gcch\":\n return `8:gcch:${microsoftTeamsUserId}`;\n case \"public\":\n return `8:orgid:${microsoftTeamsUserId}`;\n }\n return `8:orgid:${microsoftTeamsUserId}`;\n }\n case \"microsoftTeamsApp\": {\n const { teamsAppId, rawId, cloud } = identifierKind;\n if (rawId) return rawId;\n switch (cloud) {\n case \"dod\":\n return `28:dod:${teamsAppId}`;\n case \"gcch\":\n return `28:gcch:${teamsAppId}`;\n }\n return `28:orgid:${teamsAppId}`;\n }\n case \"phoneNumber\": {\n const { phoneNumber, rawId } = identifierKind;\n if (rawId) return rawId;\n return `4:${phoneNumber}`;\n }\n case \"unknown\": {\n return identifierKind.id;\n }\n }\n};\n\nconst buildMicrosoftTeamsAppIdentifier = (\n teamsAppId: string,\n cloud: \"public\" | \"dod\" | \"gcch\",\n): CommunicationIdentifierKind => {\n return {\n kind: \"microsoftTeamsApp\",\n teamsAppId: teamsAppId,\n cloud: cloud,\n };\n};\n\nconst buildMicrosoftTeamsUserIdentifier = (\n id: string,\n cloud: \"public\" | \"dod\" | \"gcch\",\n isAnonymous: boolean,\n): CommunicationIdentifierKind => {\n return {\n kind: \"microsoftTeamsUser\",\n microsoftTeamsUserId: id,\n isAnonymous: isAnonymous,\n cloud: cloud,\n };\n};\n\n/**\n * Creates a CommunicationIdentifierKind from a given rawId. When storing rawIds use this function to restore the identifier that was encoded in the rawId.\n *\n * @param rawId - The rawId to be translated to its identifier representation.\n */\nexport const createIdentifierFromRawId = (rawId: string): CommunicationIdentifierKind => {\n if (rawId.startsWith(\"4:\")) {\n return { kind: \"phoneNumber\", phoneNumber: `${rawId.substring(\"4:\".length)}` };\n }\n\n const segments = rawId.split(\":\");\n if (segments.length !== 3) {\n return { kind: \"unknown\", id: rawId };\n }\n\n const prefix = `${segments[0]}:${segments[1]}:`;\n const suffix = segments[2];\n\n switch (prefix) {\n case \"8:teamsvisitor:\":\n return { kind: \"microsoftTeamsUser\", microsoftTeamsUserId: suffix, isAnonymous: true };\n case \"8:orgid:\":\n return buildMicrosoftTeamsUserIdentifier(suffix, \"public\", false);\n case \"8:dod:\":\n return buildMicrosoftTeamsUserIdentifier(suffix, \"dod\", false);\n case \"8:gcch:\":\n return buildMicrosoftTeamsUserIdentifier(suffix, \"gcch\", false);\n case \"8:acs:\":\n case \"8:spool:\":\n case \"8:dod-acs:\":\n case \"8:gcch-acs:\":\n return { kind: \"communicationUser\", communicationUserId: rawId };\n case \"28:orgid:\":\n return buildMicrosoftTeamsAppIdentifier(suffix, \"public\");\n case \"28:gcch:\":\n return buildMicrosoftTeamsAppIdentifier(suffix, \"gcch\");\n case \"28:dod:\":\n return buildMicrosoftTeamsAppIdentifier(suffix, \"dod\");\n }\n return { kind: \"unknown\", id: rawId };\n};\n"]}
1
+ {"version":3,"file":"identifierModels.js","sourceRoot":"","sources":["../../src/identifierModels.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAoIlC;;;;GAIG;AACH,MAAM,CAAC,MAAM,6BAA6B,GAAG,CAC3C,UAAmC,EACQ,EAAE;IAC7C,OAAO,OAAQ,UAAkB,CAAC,mBAAmB,KAAK,QAAQ,CAAC;AACrE,CAAC,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,CACrC,UAAmC,EACE,EAAE;IACvC,OAAO,OAAQ,UAAkB,CAAC,WAAW,KAAK,QAAQ,CAAC;AAC7D,CAAC,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,MAAM,8BAA8B,GAAG,CAC5C,UAAmC,EACS,EAAE;IAC9C,OAAO,OAAQ,UAAkB,CAAC,oBAAoB,KAAK,QAAQ,CAAC;AACtE,CAAC,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,MAAM,6BAA6B,GAAG,CAC3C,UAAmC,EACQ,EAAE;IAC7C,OAAO,OAAQ,UAAkB,CAAC,UAAU,KAAK,QAAQ,CAAC;AAC5D,CAAC,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,MAAM,8BAA8B,GAAG,CAC5C,UAAmC,EACS,EAAE;IAC9C,MAAM,YAAY,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gC,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IAC3D,CAAC;IACD,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,EAAE,EAAE,KAAK,EAAE,CAAC;AACxC,CAAC,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\n/**\n * Identifies a communication participant.\n */\nexport type CommunicationIdentifier =\n | CommunicationUserIdentifier\n | PhoneNumberIdentifier\n | MicrosoftTeamsUserIdentifier\n | MicrosoftTeamsAppIdentifier\n | TeamsExtensionUserIdentifier\n | UnknownIdentifier;\n\n/**\n * An Azure Communication user.\n */\nexport interface CommunicationUserIdentifier {\n /**\n * Id of the CommunicationUser as returned from the Communication Service.\n */\n communicationUserId: string;\n}\n\n/**\n * A phone number.\n */\nexport interface PhoneNumberIdentifier {\n /**\n * Optional raw id of the phone number.\n */\n rawId?: string;\n /**\n * The phone number in E.164 format.\n */\n phoneNumber: string;\n\n /**\n * The asserted Id is set on a phone number that is already in the same call to distinguish from other connections made through the same number.\n */\n assertedId?: string;\n\n /**\n * True if the phone number is anonymous.\n */\n isAnonymous?: boolean;\n}\n\n/**\n * A Microsoft Teams user.\n */\nexport interface MicrosoftTeamsUserIdentifier {\n /**\n * Optional raw id of the Microsoft Teams user.\n */\n rawId?: string;\n\n /**\n * Id of the Microsoft Teams user. If the user isn't anonymous, the id is the Entra ID object id of the user.\n */\n microsoftTeamsUserId: string;\n\n /**\n * True if the user is anonymous, for example when joining a meeting with a share link. If missing, the user is not anonymous.\n */\n isAnonymous?: boolean;\n\n /**\n * The cloud that the Microsoft Teams user belongs to. If missing, the cloud is \"public\".\n */\n cloud?: \"public\" | \"dod\" | \"gcch\";\n}\n\n/**\n * A Microsoft Teams App.\n */\nexport interface MicrosoftTeamsAppIdentifier {\n /**\n * Optional raw id of the Microsoft Teams App.\n */\n rawId?: string;\n\n /**\n * The unique Microsoft Teams app ID.\n */\n teamsAppId: string;\n\n /**\n * The cloud that the Microsoft Teams App belongs to. If missing, the cloud is \"public\".\n */\n cloud?: \"public\" | \"dod\" | \"gcch\";\n}\n\n/**\n * A Microsoft Teams Phone user who is using the Azure Communication Services resource to extend their Teams Phone set up.\n */\nexport interface TeamsExtensionUserIdentifier {\n /**\n * Optional raw id of the Microsoft Teams Extension user.\n */\n rawId?: string;\n\n /**\n * The Id of the Microsoft Teams Extension user, i.e. the Entra ID object Id of the user.\n */\n userId: string;\n\n /**\n * The tenant Id of the Microsoft Teams Extension user.\n */\n tenantId: string;\n\n /**\n * The Azure Communication Services resource Id.\n */\n resourceId: string;\n\n /**\n * The cloud that the Microsoft Teams Extension user belongs to. If missing, the cloud is \"public\".\n */\n cloud?: \"public\" | \"dod\" | \"gcch\";\n}\n\n/**\n * An unknown identifier that doesn't fit any of the other identifier types.\n */\nexport interface UnknownIdentifier {\n /**\n * Id of the UnknownIdentifier.\n */\n id: string;\n}\n\n/**\n * Tests an Identifier to determine whether it implements CommunicationUserIdentifier.\n *\n * @param identifier - The assumed CommunicationUserIdentifier to be tested.\n */\nexport const isCommunicationUserIdentifier = (\n identifier: CommunicationIdentifier,\n): identifier is CommunicationUserIdentifier => {\n return typeof (identifier as any).communicationUserId === \"string\";\n};\n\n/**\n * Tests an Identifier to determine whether it implements PhoneNumberIdentifier.\n *\n * @param identifier - The assumed PhoneNumberIdentifier to be tested.\n */\nexport const isPhoneNumberIdentifier = (\n identifier: CommunicationIdentifier,\n): identifier is PhoneNumberIdentifier => {\n return typeof (identifier as any).phoneNumber === \"string\";\n};\n\n/**\n * Tests an Identifier to determine whether it implements MicrosoftTeamsUserIdentifier.\n *\n * @param identifier - The assumed available to be tested.\n */\nexport const isMicrosoftTeamsUserIdentifier = (\n identifier: CommunicationIdentifier,\n): identifier is MicrosoftTeamsUserIdentifier => {\n return typeof (identifier as any).microsoftTeamsUserId === \"string\";\n};\n\n/**\n * Tests an Identifier to determine whether it implements MicrosoftTeamsAppIdentifier.\n *\n * @param identifier - The assumed available to be tested.\n */\nexport const isMicrosoftTeamsAppIdentifier = (\n identifier: CommunicationIdentifier,\n): identifier is MicrosoftTeamsAppIdentifier => {\n return typeof (identifier as any).teamsAppId === \"string\";\n};\n\n/**\n * Tests an Identifier to determine whether it implements TeamsExtensionUserIdentifier.\n *\n * @param identifier - The assumed available to be tested.\n */\nexport const isTeamsExtensionUserIdentifier = (\n identifier: CommunicationIdentifier,\n): identifier is TeamsExtensionUserIdentifier => {\n const userIdExists = typeof (identifier as any).userId === \"string\";\n const tenantIdExists = typeof (identifier as any).tenantId === \"string\";\n const resourceIdExists = typeof (identifier as any).resourceId === \"string\";\n return userIdExists && tenantIdExists && resourceIdExists;\n};\n\n/**\n * Tests an Identifier to determine whether it implements UnknownIdentifier.\n *\n * @param identifier - The assumed UnknownIdentifier to be tested.\n */\nexport const isUnknownIdentifier = (\n identifier: CommunicationIdentifier,\n): identifier is UnknownIdentifier => {\n return typeof (identifier as any).id === \"string\";\n};\n\n/**\n * The CommunicationIdentifierKind is a discriminated union that adds a property `kind` to an Identifier.\n */\nexport type CommunicationIdentifierKind =\n | CommunicationUserKind\n | PhoneNumberKind\n | MicrosoftTeamsUserKind\n | MicrosoftTeamsAppKind\n | TeamsExtensionUserKind\n | UnknownIdentifierKind;\n\n/**\n * IdentifierKind for a CommunicationUserIdentifier.\n */\nexport interface CommunicationUserKind extends CommunicationUserIdentifier {\n /**\n * The identifier kind.\n */\n kind: \"communicationUser\";\n}\n\n/**\n * IdentifierKind for a PhoneNumberIdentifier.\n */\nexport interface PhoneNumberKind extends PhoneNumberIdentifier {\n /**\n * The identifier kind.\n */\n kind: \"phoneNumber\";\n}\n\n/**\n * IdentifierKind for a MicrosoftTeamsUserIdentifier.\n */\nexport interface MicrosoftTeamsUserKind extends MicrosoftTeamsUserIdentifier {\n /**\n * The identifier kind.\n */\n kind: \"microsoftTeamsUser\";\n}\n\n/**\n * IdentifierKind for a MicrosoftTeamsAppIdentifier.\n */\nexport interface MicrosoftTeamsAppKind extends MicrosoftTeamsAppIdentifier {\n /**\n * The identifier kind.\n */\n kind: \"microsoftTeamsApp\";\n}\n\n/**\n * IdentifierKind for a TeamsExtensionUserIdentifier.\n */\nexport interface TeamsExtensionUserKind extends TeamsExtensionUserIdentifier {\n /**\n * The identifier kind.\n */\n kind: \"teamsExtensionUser\";\n}\n\n/**\n * IdentifierKind for UnknownIdentifier.\n */\nexport interface UnknownIdentifierKind extends UnknownIdentifier {\n /**\n * The identifier kind.\n */\n kind: \"unknown\";\n}\n\n/**\n * Returns the CommunicationIdentifierKind for a given CommunicationIdentifier. Returns undefined if the kind couldn't be inferred.\n *\n * @param identifier - The identifier whose kind is to be inferred.\n */\nexport const getIdentifierKind = (\n identifier: CommunicationIdentifier,\n): CommunicationIdentifierKind => {\n if (isCommunicationUserIdentifier(identifier)) {\n return { ...identifier, kind: \"communicationUser\" };\n }\n if (isPhoneNumberIdentifier(identifier)) {\n return { ...identifier, kind: \"phoneNumber\" };\n }\n if (isMicrosoftTeamsUserIdentifier(identifier)) {\n return { ...identifier, kind: \"microsoftTeamsUser\" };\n }\n if (isMicrosoftTeamsAppIdentifier(identifier)) {\n return { ...identifier, kind: \"microsoftTeamsApp\" };\n }\n if (isTeamsExtensionUserIdentifier(identifier)) {\n return { ...identifier, kind: \"teamsExtensionUser\" };\n }\n return { ...identifier, kind: \"unknown\" };\n};\n\n/**\n * Returns the rawId for a given CommunicationIdentifier. You can use the rawId for encoding the identifier and then use it as a key in a database.\n *\n * @param identifier - The identifier to be translated to its rawId.\n */\nexport const getIdentifierRawId = (identifier: CommunicationIdentifier): string => {\n const identifierKind = getIdentifierKind(identifier);\n switch (identifierKind.kind) {\n case \"communicationUser\":\n return identifierKind.communicationUserId;\n case \"microsoftTeamsUser\": {\n const { microsoftTeamsUserId, rawId, cloud, isAnonymous } = identifierKind;\n if (rawId) return rawId;\n if (isAnonymous) return `8:teamsvisitor:${microsoftTeamsUserId}`;\n switch (cloud) {\n case \"dod\":\n return `8:dod:${microsoftTeamsUserId}`;\n case \"gcch\":\n return `8:gcch:${microsoftTeamsUserId}`;\n case \"public\":\n return `8:orgid:${microsoftTeamsUserId}`;\n }\n return `8:orgid:${microsoftTeamsUserId}`;\n }\n case \"microsoftTeamsApp\": {\n const { teamsAppId, rawId, cloud } = identifierKind;\n if (rawId) return rawId;\n switch (cloud) {\n case \"dod\":\n return `28:dod:${teamsAppId}`;\n case \"gcch\":\n return `28:gcch:${teamsAppId}`;\n }\n return `28:orgid:${teamsAppId}`;\n }\n case \"phoneNumber\": {\n const { phoneNumber, rawId } = identifierKind;\n if (rawId) return rawId;\n return `4:${phoneNumber}`;\n }\n case \"teamsExtensionUser\": {\n const { userId, tenantId, resourceId, rawId, cloud } = identifierKind;\n if (rawId) return rawId;\n switch (cloud) {\n case \"dod\":\n return `8:dod-acs:${resourceId}_${tenantId}_${userId}`;\n case \"gcch\":\n return `8:gcch-acs:${resourceId}_${tenantId}_${userId}`;\n }\n return `8:acs:${resourceId}_${tenantId}_${userId}`;\n }\n case \"unknown\": {\n return identifierKind.id;\n }\n }\n};\n\nconst buildMicrosoftTeamsAppIdentifier = (\n teamsAppId: string,\n cloud: \"public\" | \"dod\" | \"gcch\",\n): CommunicationIdentifierKind => {\n return {\n kind: \"microsoftTeamsApp\",\n teamsAppId: teamsAppId,\n cloud: cloud,\n };\n};\n\nconst buildMicrosoftTeamsUserIdentifier = (\n id: string,\n cloud: \"public\" | \"dod\" | \"gcch\",\n isAnonymous: boolean,\n): CommunicationIdentifierKind => {\n return {\n kind: \"microsoftTeamsUser\",\n microsoftTeamsUserId: id,\n isAnonymous: isAnonymous,\n cloud: cloud,\n };\n};\n\nconst buildTeamsExtensionUserOrCommunicationUserIdentifier = (\n rawId: string,\n suffix: string,\n cloud: \"public\" | \"dod\" | \"gcch\",\n): CommunicationIdentifierKind => {\n const segments = suffix.split(\"_\");\n if (segments.length !== 3) {\n return { kind: \"communicationUser\", communicationUserId: rawId };\n }\n\n const resourceId = segments[0];\n const tenantId = segments[1];\n const userId = segments[2];\n return {\n kind: \"teamsExtensionUser\",\n userId: userId,\n tenantId: tenantId,\n resourceId: resourceId,\n cloud: cloud,\n };\n};\n\nconst buildPhoneNumberIdentifier = (rawId: string): CommunicationIdentifierKind => {\n const phoneNumber = rawId.substring(\"4:\".length);\n const isAnonymous = phoneNumber === \"anonymous\";\n const assertedIdIndex = isAnonymous ? -1 : phoneNumber.lastIndexOf(\"_\") + 1;\n const hasAssertedId = assertedIdIndex > 0 && assertedIdIndex < phoneNumber.length;\n const assertedId = hasAssertedId ? phoneNumber.substring(assertedIdIndex) : undefined;\n\n return {\n kind: \"phoneNumber\",\n phoneNumber: phoneNumber,\n isAnonymous: isAnonymous,\n assertedId: assertedId,\n };\n};\n\n/**\n * Creates a CommunicationIdentifierKind from a given rawId. When storing rawIds use this function to restore the identifier that was encoded in the rawId.\n *\n * @param rawId - The rawId to be translated to its identifier representation.\n */\nexport const createIdentifierFromRawId = (rawId: string): CommunicationIdentifierKind => {\n if (rawId.startsWith(\"4:\")) {\n return buildPhoneNumberIdentifier(rawId);\n }\n\n const segments = rawId.split(\":\");\n if (segments.length !== 3) {\n return { kind: \"unknown\", id: rawId };\n }\n\n const prefix = `${segments[0]}:${segments[1]}:`;\n const suffix = segments[2];\n\n switch (prefix) {\n case \"8:teamsvisitor:\":\n return { kind: \"microsoftTeamsUser\", microsoftTeamsUserId: suffix, isAnonymous: true };\n case \"8:orgid:\":\n return buildMicrosoftTeamsUserIdentifier(suffix, \"public\", false);\n case \"8:dod:\":\n return buildMicrosoftTeamsUserIdentifier(suffix, \"dod\", false);\n case \"8:gcch:\":\n return buildMicrosoftTeamsUserIdentifier(suffix, \"gcch\", false);\n case \"8:acs:\":\n return buildTeamsExtensionUserOrCommunicationUserIdentifier(rawId, suffix, \"public\");\n case \"8:dod-acs:\":\n return buildTeamsExtensionUserOrCommunicationUserIdentifier(rawId, suffix, \"dod\");\n case \"8:gcch-acs:\":\n return buildTeamsExtensionUserOrCommunicationUserIdentifier(rawId, suffix, \"gcch\");\n case \"8:spool:\":\n return { kind: \"communicationUser\", communicationUserId: rawId };\n case \"28:orgid:\":\n return buildMicrosoftTeamsAppIdentifier(suffix, \"public\");\n case \"28:gcch:\":\n return buildMicrosoftTeamsAppIdentifier(suffix, \"gcch\");\n case \"28:dod:\":\n return buildMicrosoftTeamsAppIdentifier(suffix, \"dod\");\n }\n return { kind: \"unknown\", id: rawId };\n};\n"]}
@@ -1,7 +1,7 @@
1
1
  export { CommunicationTokenCredential, CommunicationGetTokenOptions, } from "./communicationTokenCredential.js";
2
2
  export { AzureCommunicationTokenCredential } from "./azureCommunicationTokenCredential.js";
3
- export * from "./credential/index.js";
4
3
  export { CommunicationTokenRefreshOptions } from "./autoRefreshTokenCredential.js";
4
+ export { EntraCommunicationTokenCredentialOptions } from "./entraTokenCredential.js";
5
5
  export * from "./credential/index.js";
6
6
  export * from "./identifierModels.js";
7
7
  export * from "./identifierModelSerializer.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,4BAA4B,EAC5B,4BAA4B,GAC7B,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EAAE,iCAAiC,EAAE,MAAM,wCAAwC,CAAC;AAC3F,cAAc,uBAAuB,CAAC;AACtC,OAAO,EAAE,gCAAgC,EAAE,MAAM,iCAAiC,CAAC;AACnF,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC;AACtC,cAAc,gCAAgC,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,4BAA4B,EAC5B,4BAA4B,GAC7B,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EAAE,iCAAiC,EAAE,MAAM,wCAAwC,CAAC;AAC3F,OAAO,EAAE,gCAAgC,EAAE,MAAM,iCAAiC,CAAC;AACnF,OAAO,EAAE,wCAAwC,EAAE,MAAM,2BAA2B,CAAC;AACrF,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC;AACtC,cAAc,gCAAgC,CAAC"}
@@ -2,7 +2,6 @@
2
2
  // Licensed under the MIT License.
3
3
  export { AzureCommunicationTokenCredential } from "./azureCommunicationTokenCredential.js";
4
4
  export * from "./credential/index.js";
5
- export * from "./credential/index.js";
6
5
  export * from "./identifierModels.js";
7
6
  export * from "./identifierModelSerializer.js";
8
7
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAMlC,OAAO,EAAE,iCAAiC,EAAE,MAAM,wCAAwC,CAAC;AAC3F,cAAc,uBAAuB,CAAC;AAEtC,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC;AACtC,cAAc,gCAAgC,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nexport {\n CommunicationTokenCredential,\n CommunicationGetTokenOptions,\n} from \"./communicationTokenCredential.js\";\nexport { AzureCommunicationTokenCredential } from \"./azureCommunicationTokenCredential.js\";\nexport * from \"./credential/index.js\";\nexport { CommunicationTokenRefreshOptions } from \"./autoRefreshTokenCredential.js\";\nexport * from \"./credential/index.js\";\nexport * from \"./identifierModels.js\";\nexport * from \"./identifierModelSerializer.js\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAMlC,OAAO,EAAE,iCAAiC,EAAE,MAAM,wCAAwC,CAAC;AAG3F,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC;AACtC,cAAc,gCAAgC,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nexport {\n CommunicationTokenCredential,\n CommunicationGetTokenOptions,\n} from \"./communicationTokenCredential.js\";\nexport { AzureCommunicationTokenCredential } from \"./azureCommunicationTokenCredential.js\";\nexport { CommunicationTokenRefreshOptions } from \"./autoRefreshTokenCredential.js\";\nexport { EntraCommunicationTokenCredentialOptions } from \"./entraTokenCredential.js\";\nexport * from \"./credential/index.js\";\nexport * from \"./identifierModels.js\";\nexport * from \"./identifierModelSerializer.js\";\n"]}
@@ -1,6 +1,7 @@
1
1
  import { type CommunicationTokenRefreshOptions } from "./autoRefreshTokenCredential.js";
2
2
  import type { CommunicationGetTokenOptions, CommunicationTokenCredential } from "./communicationTokenCredential.js";
3
3
  import type { AccessToken } from "@azure/core-auth";
4
+ import { type EntraCommunicationTokenCredentialOptions } from "./entraTokenCredential.js";
4
5
  /**
5
6
  * The CommunicationTokenCredential implementation with support for proactive token refresh.
6
7
  */
@@ -18,6 +19,11 @@ export declare class AzureCommunicationTokenCredential implements CommunicationT
18
19
  * @param refreshOptions - Options to configure refresh and opt-in to proactive refreshing.
19
20
  */
20
21
  constructor(refreshOptions: CommunicationTokenRefreshOptions);
22
+ /**
23
+ * Creates an instance of CommunicationTokenCredential with an Entra ID token credential. In most cases, you might want to use InteractiveBrowserCredential to sign in your user.
24
+ * @param entraOptions - Options to configure the Entra ID token credential.
25
+ */
26
+ constructor(entraOptions: EntraCommunicationTokenCredentialOptions);
21
27
  /**
22
28
  * Gets an `AccessToken` for the user. Throws if already disposed.
23
29
  * @param abortSignal - An implementation of `AbortSignalLike` to cancel the operation.
@@ -1 +1 @@
1
- {"version":3,"file":"azureCommunicationTokenCredential.d.ts","sourceRoot":"","sources":["../../src/azureCommunicationTokenCredential.ts"],"names":[],"mappings":"AAGA,OAAO,EAEL,KAAK,gCAAgC,EACtC,MAAM,iCAAiC,CAAC;AACzC,OAAO,KAAK,EACV,4BAA4B,EAC5B,4BAA4B,EAE7B,MAAM,mCAAmC,CAAC;AAC3C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAIpD;;GAEG;AAEH,qBAAa,iCAAkC,YAAW,4BAA4B;IACpF,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAkB;IAClD,OAAO,CAAC,QAAQ,CAAS;IAEzB;;;OAGG;gBACS,KAAK,EAAE,MAAM;IACzB;;;;OAIG;gBACS,cAAc,EAAE,gCAAgC;IAS5D;;;OAGG;IACU,QAAQ,CAAC,OAAO,CAAC,EAAE,4BAA4B,GAAG,OAAO,CAAC,WAAW,CAAC;IAOnF;;OAEG;IACI,OAAO,IAAI,IAAI;IAKtB,OAAO,CAAC,eAAe;CAKxB"}
1
+ {"version":3,"file":"azureCommunicationTokenCredential.d.ts","sourceRoot":"","sources":["../../src/azureCommunicationTokenCredential.ts"],"names":[],"mappings":"AAGA,OAAO,EAEL,KAAK,gCAAgC,EACtC,MAAM,iCAAiC,CAAC;AACzC,OAAO,KAAK,EACV,4BAA4B,EAC5B,4BAA4B,EAE7B,MAAM,mCAAmC,CAAC;AAC3C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAGpD,OAAO,EACL,KAAK,wCAAwC,EAE9C,MAAM,2BAA2B,CAAC;AAEnC;;GAEG;AAEH,qBAAa,iCAAkC,YAAW,4BAA4B;IACpF,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAkB;IAClD,OAAO,CAAC,QAAQ,CAAS;IAEzB;;;OAGG;gBACS,KAAK,EAAE,MAAM;IACzB;;;;OAIG;gBACS,cAAc,EAAE,gCAAgC;IAC5D;;;OAGG;gBACS,YAAY,EAAE,wCAAwC;IAkBlE;;;OAGG;IACU,QAAQ,CAAC,OAAO,CAAC,EAAE,4BAA4B,GAAG,OAAO,CAAC,WAAW,CAAC;IAOnF;;OAEG;IACI,OAAO,IAAI,IAAI;IAKtB,OAAO,CAAC,eAAe;CAKxB"}
@@ -6,17 +6,21 @@ exports.AzureCommunicationTokenCredential = void 0;
6
6
  const autoRefreshTokenCredential_js_1 = require("./autoRefreshTokenCredential.js");
7
7
  const staticTokenCredential_js_1 = require("./staticTokenCredential.js");
8
8
  const tokenParser_js_1 = require("./tokenParser.js");
9
+ const entraTokenCredential_js_1 = require("./entraTokenCredential.js");
9
10
  /**
10
11
  * The CommunicationTokenCredential implementation with support for proactive token refresh.
11
12
  */
12
13
  class AzureCommunicationTokenCredential {
13
- constructor(tokenOrRefreshOptions) {
14
+ constructor(tokenOrRefreshOptionsOrEntraOptions) {
14
15
  this.disposed = false;
15
- if (typeof tokenOrRefreshOptions === "string") {
16
- this.tokenCredential = new staticTokenCredential_js_1.StaticTokenCredential((0, tokenParser_js_1.parseToken)(tokenOrRefreshOptions));
16
+ if (typeof tokenOrRefreshOptionsOrEntraOptions === "string") {
17
+ this.tokenCredential = new staticTokenCredential_js_1.StaticTokenCredential((0, tokenParser_js_1.parseToken)(tokenOrRefreshOptionsOrEntraOptions));
18
+ }
19
+ else if ("tokenRefresher" in tokenOrRefreshOptionsOrEntraOptions) {
20
+ this.tokenCredential = new autoRefreshTokenCredential_js_1.AutoRefreshTokenCredential(tokenOrRefreshOptionsOrEntraOptions);
17
21
  }
18
22
  else {
19
- this.tokenCredential = new autoRefreshTokenCredential_js_1.AutoRefreshTokenCredential(tokenOrRefreshOptions);
23
+ this.tokenCredential = new entraTokenCredential_js_1.EntraTokenCredential(tokenOrRefreshOptionsOrEntraOptions);
20
24
  }
21
25
  }
22
26
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"azureCommunicationTokenCredential.js","sourceRoot":"","sources":["../../src/azureCommunicationTokenCredential.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AAElC,mFAGyC;AAOzC,yEAAmE;AACnE,qDAA8C;AAE9C;;GAEG;AAEH,MAAa,iCAAiC;IAe5C,YAAY,qBAAgE;QAbpE,aAAQ,GAAG,KAAK,CAAC;QAcvB,IAAI,OAAO,qBAAqB,KAAK,QAAQ,EAAE,CAAC;YAC9C,IAAI,CAAC,eAAe,GAAG,IAAI,gDAAqB,CAAC,IAAA,2BAAU,EAAC,qBAAqB,CAAC,CAAC,CAAC;QACtF,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,eAAe,GAAG,IAAI,0DAA0B,CAAC,qBAAqB,CAAC,CAAC;QAC/E,CAAC;IACH,CAAC;IAED;;;OAGG;IACI,KAAK,CAAC,QAAQ,CAAC,OAAsC;QAC1D,IAAI,CAAC,eAAe,EAAE,CAAC;QACvB,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,eAAe,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;QAC3D,IAAI,CAAC,eAAe,EAAE,CAAC;QACvB,OAAO,KAAK,CAAC;IACf,CAAC;IAED;;OAEG;IACI,OAAO;QACZ,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;QACrB,IAAI,CAAC,eAAe,CAAC,OAAO,EAAE,CAAC;IACjC,CAAC;IAEO,eAAe;QACrB,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;YAClB,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAC;QACjD,CAAC;IACH,CAAC;CACF;AA/CD,8EA+CC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport {\n AutoRefreshTokenCredential,\n type CommunicationTokenRefreshOptions,\n} from \"./autoRefreshTokenCredential.js\";\nimport type {\n CommunicationGetTokenOptions,\n CommunicationTokenCredential,\n TokenCredential,\n} from \"./communicationTokenCredential.js\";\nimport type { AccessToken } from \"@azure/core-auth\";\nimport { StaticTokenCredential } from \"./staticTokenCredential.js\";\nimport { parseToken } from \"./tokenParser.js\";\n\n/**\n * The CommunicationTokenCredential implementation with support for proactive token refresh.\n */\n\nexport class AzureCommunicationTokenCredential implements CommunicationTokenCredential {\n private readonly tokenCredential: TokenCredential;\n private disposed = false;\n\n /**\n * Creates an instance of CommunicationTokenCredential with a static token and no proactive refreshing.\n * @param token - A user access token issued by Communication Services.\n */\n constructor(token: string);\n /**\n * Creates an instance of CommunicationTokenCredential with a lambda to get a token and options\n * to configure proactive refreshing.\n * @param refreshOptions - Options to configure refresh and opt-in to proactive refreshing.\n */\n constructor(refreshOptions: CommunicationTokenRefreshOptions);\n constructor(tokenOrRefreshOptions: string | CommunicationTokenRefreshOptions) {\n if (typeof tokenOrRefreshOptions === \"string\") {\n this.tokenCredential = new StaticTokenCredential(parseToken(tokenOrRefreshOptions));\n } else {\n this.tokenCredential = new AutoRefreshTokenCredential(tokenOrRefreshOptions);\n }\n }\n\n /**\n * Gets an `AccessToken` for the user. Throws if already disposed.\n * @param abortSignal - An implementation of `AbortSignalLike` to cancel the operation.\n */\n public async getToken(options?: CommunicationGetTokenOptions): Promise<AccessToken> {\n this.throwIfDisposed();\n const token = await this.tokenCredential.getToken(options);\n this.throwIfDisposed();\n return token;\n }\n\n /**\n * Disposes the CommunicationTokenCredential and cancels any internal auto-refresh operation.\n */\n public dispose(): void {\n this.disposed = true;\n this.tokenCredential.dispose();\n }\n\n private throwIfDisposed(): void {\n if (this.disposed) {\n throw new Error(\"User credential is disposed\");\n }\n }\n}\n"]}
1
+ {"version":3,"file":"azureCommunicationTokenCredential.js","sourceRoot":"","sources":["../../src/azureCommunicationTokenCredential.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AAElC,mFAGyC;AAOzC,yEAAmE;AACnE,qDAA8C;AAC9C,uEAGmC;AAEnC;;GAEG;AAEH,MAAa,iCAAiC;IAoB5C,YACE,mCAG4C;QAtBtC,aAAQ,GAAG,KAAK,CAAC;QAwBvB,IAAI,OAAO,mCAAmC,KAAK,QAAQ,EAAE,CAAC;YAC5D,IAAI,CAAC,eAAe,GAAG,IAAI,gDAAqB,CAC9C,IAAA,2BAAU,EAAC,mCAAmC,CAAC,CAChD,CAAC;QACJ,CAAC;aAAM,IAAI,gBAAgB,IAAI,mCAAmC,EAAE,CAAC;YACnE,IAAI,CAAC,eAAe,GAAG,IAAI,0DAA0B,CAAC,mCAAmC,CAAC,CAAC;QAC7F,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,eAAe,GAAG,IAAI,8CAAoB,CAAC,mCAAmC,CAAC,CAAC;QACvF,CAAC;IACH,CAAC;IAED;;;OAGG;IACI,KAAK,CAAC,QAAQ,CAAC,OAAsC;QAC1D,IAAI,CAAC,eAAe,EAAE,CAAC;QACvB,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,eAAe,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;QAC3D,IAAI,CAAC,eAAe,EAAE,CAAC;QACvB,OAAO,KAAK,CAAC;IACf,CAAC;IAED;;OAEG;IACI,OAAO;QACZ,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;QACrB,IAAI,CAAC,eAAe,CAAC,OAAO,EAAE,CAAC;IACjC,CAAC;IAEO,eAAe;QACrB,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;YAClB,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAC;QACjD,CAAC;IACH,CAAC;CACF;AA7DD,8EA6DC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport {\n AutoRefreshTokenCredential,\n type CommunicationTokenRefreshOptions,\n} from \"./autoRefreshTokenCredential.js\";\nimport type {\n CommunicationGetTokenOptions,\n CommunicationTokenCredential,\n TokenCredential,\n} from \"./communicationTokenCredential.js\";\nimport type { AccessToken } from \"@azure/core-auth\";\nimport { StaticTokenCredential } from \"./staticTokenCredential.js\";\nimport { parseToken } from \"./tokenParser.js\";\nimport {\n type EntraCommunicationTokenCredentialOptions,\n EntraTokenCredential,\n} from \"./entraTokenCredential.js\";\n\n/**\n * The CommunicationTokenCredential implementation with support for proactive token refresh.\n */\n\nexport class AzureCommunicationTokenCredential implements CommunicationTokenCredential {\n private readonly tokenCredential: TokenCredential;\n private disposed = false;\n\n /**\n * Creates an instance of CommunicationTokenCredential with a static token and no proactive refreshing.\n * @param token - A user access token issued by Communication Services.\n */\n constructor(token: string);\n /**\n * Creates an instance of CommunicationTokenCredential with a lambda to get a token and options\n * to configure proactive refreshing.\n * @param refreshOptions - Options to configure refresh and opt-in to proactive refreshing.\n */\n constructor(refreshOptions: CommunicationTokenRefreshOptions);\n /**\n * Creates an instance of CommunicationTokenCredential with an Entra ID token credential. In most cases, you might want to use InteractiveBrowserCredential to sign in your user.\n * @param entraOptions - Options to configure the Entra ID token credential.\n */\n constructor(entraOptions: EntraCommunicationTokenCredentialOptions);\n constructor(\n tokenOrRefreshOptionsOrEntraOptions:\n | string\n | CommunicationTokenRefreshOptions\n | EntraCommunicationTokenCredentialOptions,\n ) {\n if (typeof tokenOrRefreshOptionsOrEntraOptions === \"string\") {\n this.tokenCredential = new StaticTokenCredential(\n parseToken(tokenOrRefreshOptionsOrEntraOptions),\n );\n } else if (\"tokenRefresher\" in tokenOrRefreshOptionsOrEntraOptions) {\n this.tokenCredential = new AutoRefreshTokenCredential(tokenOrRefreshOptionsOrEntraOptions);\n } else {\n this.tokenCredential = new EntraTokenCredential(tokenOrRefreshOptionsOrEntraOptions);\n }\n }\n\n /**\n * Gets an `AccessToken` for the user. Throws if already disposed.\n * @param abortSignal - An implementation of `AbortSignalLike` to cancel the operation.\n */\n public async getToken(options?: CommunicationGetTokenOptions): Promise<AccessToken> {\n this.throwIfDisposed();\n const token = await this.tokenCredential.getToken(options);\n this.throwIfDisposed();\n return token;\n }\n\n /**\n * Disposes the CommunicationTokenCredential and cancels any internal auto-refresh operation.\n */\n public dispose(): void {\n this.disposed = true;\n this.tokenCredential.dispose();\n }\n\n private throwIfDisposed(): void {\n if (this.disposed) {\n throw new Error(\"User credential is disposed\");\n }\n }\n}\n"]}
@@ -0,0 +1,44 @@
1
+ import { type AccessToken, type TokenCredential } from "@azure/core-auth";
2
+ import { type TokenCredential as AcsTokenCredential, type CommunicationGetTokenOptions } from "./communicationTokenCredential.js";
3
+ export interface ExchangeTokenResponse {
4
+ identity: string;
5
+ accessToken: {
6
+ token: string;
7
+ expiresOn: string;
8
+ };
9
+ }
10
+ /**
11
+ * The Entra Communication Token Options.
12
+ */
13
+ export interface EntraCommunicationTokenCredentialOptions {
14
+ /**
15
+ * The Azure Communication Service resource endpoint URL, e.g. https://myResource.communication.azure.com.
16
+ */
17
+ resourceEndpoint: string;
18
+ /**
19
+ * The Entra ID token credential.
20
+ */
21
+ tokenCredential: TokenCredential;
22
+ /**
23
+ * The scopes for retrieving the Entra ID access token.
24
+ */
25
+ scopes?: string[];
26
+ }
27
+ /**
28
+ * Represents a credential that exchanges an Entra token for an Azure Communication Services (ACS) token, enabling access to ACS resources.
29
+ */
30
+ export declare class EntraTokenCredential implements AcsTokenCredential {
31
+ private options;
32
+ private isPending;
33
+ private result;
34
+ private client;
35
+ private httpClient;
36
+ constructor(options: EntraCommunicationTokenCredentialOptions);
37
+ getToken(options?: CommunicationGetTokenOptions): Promise<AccessToken>;
38
+ private getTokenInternal;
39
+ dispose(): void;
40
+ private exchangeEntraToken;
41
+ private createRequestUri;
42
+ private determineEndpointAndApiVersion;
43
+ }
44
+ //# sourceMappingURL=entraTokenCredential.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"entraTokenCredential.d.ts","sourceRoot":"","sources":["../../src/entraTokenCredential.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,WAAW,EAAE,KAAK,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAC1E,OAAO,EACL,KAAK,eAAe,IAAI,kBAAkB,EAC1C,KAAK,4BAA4B,EAClC,MAAM,mCAAmC,CAAC;AAiB3C,MAAM,WAAW,qBAAqB;IACpC,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE;QACX,KAAK,EAAE,MAAM,CAAC;QACd,SAAS,EAAE,MAAM,CAAC;KACnB,CAAC;CACH;AAED;;GAEG;AACH,MAAM,WAAW,wCAAwC;IACvD;;OAEG;IACH,gBAAgB,EAAE,MAAM,CAAC;IACzB;;OAEG;IACH,eAAe,EAAE,eAAe,CAAC;IACjC;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;CACnB;AAED;;GAEG;AACH,qBAAa,oBAAqB,YAAW,kBAAkB;IASjD,OAAO,CAAC,OAAO;IAR3B,OAAO,CAAC,SAAS,CAA8B;IAC/C,OAAO,CAAC,MAAM,CAGZ;IACF,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,UAAU,CAAa;gBAEX,OAAO,EAAE,wCAAwC;IAYxD,QAAQ,CAAC,OAAO,CAAC,EAAE,4BAA4B,GAAG,OAAO,CAAC,WAAW,CAAC;YAoBrE,gBAAgB;IAmCvB,OAAO,IAAI,IAAI;YAOR,kBAAkB;IA8BhC,OAAO,CAAC,gBAAgB;IAMxB,OAAO,CAAC,8BAA8B;CAiBvC"}
@@ -0,0 +1,124 @@
1
+ "use strict";
2
+ // Copyright (c) Microsoft Corporation.
3
+ // Licensed under the MIT License.
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.EntraTokenCredential = void 0;
6
+ const core_client_1 = require("@azure-rest/core-client");
7
+ const core_rest_pipeline_1 = require("@azure/core-rest-pipeline");
8
+ const TeamsExtensionScopePrefix = "https://auth.msft.communication.azure.com/";
9
+ const CommunicationClientsScopePrefix = "https://communication.azure.com/clients/";
10
+ const TeamsExtensionEndpoint = "/access/teamsPhone/:exchangeAccessToken";
11
+ const TeamsExtensionApiVersion = "2025-03-02-preview";
12
+ const CommunicationClientsEndpoint = "/access/entra/:exchangeAccessToken";
13
+ const CommunicationClientsApiVersion = "2024-04-01-preview";
14
+ /**
15
+ * Represents a credential that exchanges an Entra token for an Azure Communication Services (ACS) token, enabling access to ACS resources.
16
+ */
17
+ class EntraTokenCredential {
18
+ constructor(options) {
19
+ this.options = options;
20
+ this.result = {
21
+ entraToken: undefined,
22
+ acsToken: { token: "", expiresOnTimestamp: 0 },
23
+ };
24
+ this.client = (0, core_client_1.getClient)(options.resourceEndpoint);
25
+ this.httpClient = (0, core_rest_pipeline_1.createDefaultHttpClient)();
26
+ this.options = options;
27
+ this.options.scopes = this.options.scopes || [
28
+ "https://communication.azure.com/clients/.default",
29
+ ];
30
+ // immediately fetch the token to pre-warm
31
+ this.isPending = this.getToken();
32
+ }
33
+ async getToken(options) {
34
+ var _a;
35
+ if ((_a = options === null || options === void 0 ? void 0 : options.abortSignal) === null || _a === void 0 ? void 0 : _a.aborted) {
36
+ return { token: "", expiresOnTimestamp: 0 };
37
+ }
38
+ // we're awaiting the token fetch, so we don't want to start another one
39
+ // however, we're ignoring the new abortSignal, unfortunately
40
+ if (!this.isPending) {
41
+ this.isPending = this.getTokenInternal(options);
42
+ }
43
+ try {
44
+ await this.isPending;
45
+ }
46
+ finally {
47
+ this.isPending = null;
48
+ }
49
+ return this.result.acsToken;
50
+ }
51
+ async getTokenInternal(options) {
52
+ const getTokenOptions = (options === null || options === void 0 ? void 0 : options.abortSignal) ? { abortSignal: options.abortSignal } : undefined;
53
+ const token = await this.options.tokenCredential.getToken(this.options.scopes
54
+ ? this.options.scopes
55
+ : ["https://communication.azure.com/clients/.default"], getTokenOptions);
56
+ const currentDateTime = new Date();
57
+ const tokenExpiresOn = new Date(this.result.acsToken.expiresOnTimestamp);
58
+ if (token === null) {
59
+ this.result = {
60
+ entraToken: undefined,
61
+ acsToken: { token: "", expiresOnTimestamp: 0 },
62
+ };
63
+ }
64
+ else if (this.result.acsToken.token === "" ||
65
+ token.token !== this.result.entraToken ||
66
+ tokenExpiresOn < currentDateTime) {
67
+ const acsToken = await this.exchangeEntraToken(this.options.resourceEndpoint, token.token, getTokenOptions);
68
+ this.result = {
69
+ entraToken: token.token,
70
+ acsToken,
71
+ };
72
+ }
73
+ return this.result.acsToken;
74
+ }
75
+ dispose() {
76
+ this.result = {
77
+ entraToken: undefined,
78
+ acsToken: { token: "", expiresOnTimestamp: 0 },
79
+ };
80
+ }
81
+ async exchangeEntraToken(resourceEndpoint, entraToken, options) {
82
+ const request = (0, core_rest_pipeline_1.createPipelineRequest)({
83
+ url: this.createRequestUri(resourceEndpoint),
84
+ method: "POST",
85
+ headers: (0, core_rest_pipeline_1.createHttpHeaders)({
86
+ Authorization: `Bearer ${entraToken}`,
87
+ "Content-Type": "application/json",
88
+ Accept: "application/json",
89
+ }),
90
+ abortSignal: options === null || options === void 0 ? void 0 : options.abortSignal,
91
+ body: JSON.stringify({}),
92
+ });
93
+ const response = await this.client.pipeline.sendRequest(this.httpClient, request);
94
+ if (response.status !== 200 || !response.bodyAsText) {
95
+ throw new Error(`Service request failed. Status: ${response.status}, Body: ${response.bodyAsText}`);
96
+ }
97
+ const json = JSON.parse(response.bodyAsText);
98
+ return {
99
+ token: json.accessToken.token,
100
+ expiresOnTimestamp: Date.parse(json.accessToken.expiresOn),
101
+ };
102
+ }
103
+ createRequestUri(resourceEndpoint) {
104
+ const [endpoint, apiVersion] = this.determineEndpointAndApiVersion();
105
+ const requestUri = `${resourceEndpoint}${endpoint}?api-version=${apiVersion}`;
106
+ return requestUri;
107
+ }
108
+ determineEndpointAndApiVersion() {
109
+ if (!this.options.scopes || this.options.scopes.length === 0) {
110
+ throw new Error(`Scopes validation failed. Ensure all scopes start with either {TeamsExtensionScopePrefix} or {CommunicationClientsScopePrefix}.`);
111
+ }
112
+ else if (this.options.scopes.every((scope) => scope.startsWith(TeamsExtensionScopePrefix))) {
113
+ return [TeamsExtensionEndpoint, TeamsExtensionApiVersion];
114
+ }
115
+ else if (this.options.scopes.every((scope) => scope.startsWith(CommunicationClientsScopePrefix))) {
116
+ return [CommunicationClientsEndpoint, CommunicationClientsApiVersion];
117
+ }
118
+ else {
119
+ throw new Error(`Scopes validation failed. Ensure all scopes start with either {TeamsExtensionScopePrefix} or {CommunicationClientsScopePrefix}.`);
120
+ }
121
+ }
122
+ }
123
+ exports.EntraTokenCredential = EntraTokenCredential;
124
+ //# sourceMappingURL=entraTokenCredential.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"entraTokenCredential.js","sourceRoot":"","sources":["../../src/entraTokenCredential.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AAQlC,yDAAiE;AACjE,kEAKmC;AAEnC,MAAM,yBAAyB,GAAG,4CAA4C,C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AC,WAAW,CAAC,KAAK;YAC7B,kBAAkB,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC;SAC3D,CAAC;IACJ,CAAC;IAEO,gBAAgB,CAAC,gBAAwB;QAC/C,MAAM,CAAC,QAAQ,EAAE,UAAU,CAAC,GAAG,IAAI,CAAC,8BAA8B,EAAE,CAAC;QACrE,MAAM,UAAU,GAAG,GAAG,gBAAgB,GAAG,QAAQ,gBAAgB,UAAU,EAAE,CAAC;QAC9E,OAAO,UAAU,CAAC;IACpB,CAAC;IAEO,8BAA8B;QACpC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,IAAI,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC7D,MAAM,IAAI,KAAK,CACb,iIAAiI,CAClI,CAAC;QACJ,CAAC;aAAM,IAAI,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,UAAU,CAAC,yBAAyB,CAAC,CAAC,EAAE,CAAC;YAC7F,OAAO,CAAC,sBAAsB,EAAE,wBAAwB,CAAC,CAAC;QAC5D,CAAC;aAAM,IACL,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,UAAU,CAAC,+BAA+B,CAAC,CAAC,EACvF,CAAC;YACD,OAAO,CAAC,4BAA4B,EAAE,8BAA8B,CAAC,CAAC;QACxE,CAAC;aAAM,CAAC;YACN,MAAM,IAAI,KAAK,CACb,iIAAiI,CAClI,CAAC;QACJ,CAAC;IACH,CAAC;CACF;AAxID,oDAwIC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport { type AccessToken, type TokenCredential } from \"@azure/core-auth\";\nimport {\n type TokenCredential as AcsTokenCredential,\n type CommunicationGetTokenOptions,\n} from \"./communicationTokenCredential.js\";\nimport { type AbortSignalLike } from \"@azure/abort-controller\";\nimport { type Client, getClient } from \"@azure-rest/core-client\";\nimport {\n type HttpClient,\n createDefaultHttpClient,\n createHttpHeaders,\n createPipelineRequest,\n} from \"@azure/core-rest-pipeline\";\n\nconst TeamsExtensionScopePrefix = \"https://auth.msft.communication.azure.com/\";\nconst CommunicationClientsScopePrefix = \"https://communication.azure.com/clients/\";\nconst TeamsExtensionEndpoint = \"/access/teamsPhone/:exchangeAccessToken\";\nconst TeamsExtensionApiVersion = \"2025-03-02-preview\";\nconst CommunicationClientsEndpoint = \"/access/entra/:exchangeAccessToken\";\nconst CommunicationClientsApiVersion = \"2024-04-01-preview\";\n\nexport interface ExchangeTokenResponse {\n identity: string;\n accessToken: {\n token: string;\n expiresOn: string;\n };\n}\n\n/**\n * The Entra Communication Token Options.\n */\nexport interface EntraCommunicationTokenCredentialOptions {\n /**\n * The Azure Communication Service resource endpoint URL, e.g. https://myResource.communication.azure.com.\n */\n resourceEndpoint: string;\n /**\n * The Entra ID token credential.\n */\n tokenCredential: TokenCredential;\n /**\n * The scopes for retrieving the Entra ID access token.\n */\n scopes?: string[];\n}\n\n/**\n * Represents a credential that exchanges an Entra token for an Azure Communication Services (ACS) token, enabling access to ACS resources.\n */\nexport class EntraTokenCredential implements AcsTokenCredential {\n private isPending: Promise<AccessToken> | null;\n private result = {\n entraToken: undefined as string | undefined,\n acsToken: { token: \"\", expiresOnTimestamp: 0 },\n };\n private client: Client;\n private httpClient: HttpClient;\n\n constructor(private options: EntraCommunicationTokenCredentialOptions) {\n this.client = getClient(options.resourceEndpoint);\n this.httpClient = createDefaultHttpClient();\n this.options = options;\n this.options.scopes = this.options.scopes || [\n \"https://communication.azure.com/clients/.default\",\n ];\n\n // immediately fetch the token to pre-warm\n this.isPending = this.getToken();\n }\n\n public async getToken(options?: CommunicationGetTokenOptions): Promise<AccessToken> {\n if (options?.abortSignal?.aborted) {\n return { token: \"\", expiresOnTimestamp: 0 };\n }\n\n // we're awaiting the token fetch, so we don't want to start another one\n // however, we're ignoring the new abortSignal, unfortunately\n if (!this.isPending) {\n this.isPending = this.getTokenInternal(options);\n }\n\n try {\n await this.isPending;\n } finally {\n this.isPending = null;\n }\n\n return this.result.acsToken;\n }\n\n private async getTokenInternal(options?: CommunicationGetTokenOptions): Promise<AccessToken> {\n const getTokenOptions = options?.abortSignal ? { abortSignal: options.abortSignal } : undefined;\n const token = await this.options.tokenCredential.getToken(\n this.options.scopes\n ? this.options.scopes\n : [\"https://communication.azure.com/clients/.default\"],\n getTokenOptions,\n );\n const currentDateTime = new Date();\n const tokenExpiresOn = new Date(this.result.acsToken.expiresOnTimestamp);\n\n if (token === null) {\n this.result = {\n entraToken: undefined,\n acsToken: { token: \"\", expiresOnTimestamp: 0 },\n };\n } else if (\n this.result.acsToken.token === \"\" ||\n token.token !== this.result.entraToken ||\n tokenExpiresOn < currentDateTime\n ) {\n const acsToken = await this.exchangeEntraToken(\n this.options.resourceEndpoint,\n token.token,\n getTokenOptions,\n );\n this.result = {\n entraToken: token.token,\n acsToken,\n };\n }\n\n return this.result.acsToken;\n }\n\n public dispose(): void {\n this.result = {\n entraToken: undefined,\n acsToken: { token: \"\", expiresOnTimestamp: 0 },\n };\n }\n\n private async exchangeEntraToken(\n resourceEndpoint: string,\n entraToken: string,\n options?: { abortSignal: AbortSignalLike },\n ): Promise<AccessToken> {\n const request = createPipelineRequest({\n url: this.createRequestUri(resourceEndpoint),\n method: \"POST\",\n headers: createHttpHeaders({\n Authorization: `Bearer ${entraToken}`,\n \"Content-Type\": \"application/json\",\n Accept: \"application/json\",\n }),\n abortSignal: options?.abortSignal,\n body: JSON.stringify({}),\n });\n const response = await this.client.pipeline.sendRequest(this.httpClient, request);\n\n if (response.status !== 200 || !response.bodyAsText) {\n throw new Error(\n `Service request failed. Status: ${response.status}, Body: ${response.bodyAsText}`,\n );\n }\n const json = JSON.parse(response.bodyAsText) as ExchangeTokenResponse;\n return {\n token: json.accessToken.token,\n expiresOnTimestamp: Date.parse(json.accessToken.expiresOn),\n };\n }\n\n private createRequestUri(resourceEndpoint: string): string {\n const [endpoint, apiVersion] = this.determineEndpointAndApiVersion();\n const requestUri = `${resourceEndpoint}${endpoint}?api-version=${apiVersion}`;\n return requestUri;\n }\n\n private determineEndpointAndApiVersion(): [string, string] {\n if (!this.options.scopes || this.options.scopes.length === 0) {\n throw new Error(\n `Scopes validation failed. Ensure all scopes start with either {TeamsExtensionScopePrefix} or {CommunicationClientsScopePrefix}.`,\n );\n } else if (this.options.scopes.every((scope) => scope.startsWith(TeamsExtensionScopePrefix))) {\n return [TeamsExtensionEndpoint, TeamsExtensionApiVersion];\n } else if (\n this.options.scopes.every((scope) => scope.startsWith(CommunicationClientsScopePrefix))\n ) {\n return [CommunicationClientsEndpoint, CommunicationClientsApiVersion];\n } else {\n throw new Error(\n `Scopes validation failed. Ensure all scopes start with either {TeamsExtensionScopePrefix} or {CommunicationClientsScopePrefix}.`,\n );\n }\n }\n}\n"]}