@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
package/README.md CHANGED
@@ -8,6 +8,7 @@ This package contains common code for Azure Communication Service libraries.
8
8
 
9
9
  - An [Azure subscription][azure_sub].
10
10
  - An existing Communication Services resource. If you need to create the resource, you can use the [Azure Portal][azure_portal], the [Azure PowerShell][azure_powershell], or the [Azure CLI][azure_cli].
11
+ - Having the @azure/identity package installed.
11
12
 
12
13
  ### Installing
13
14
 
@@ -15,6 +16,10 @@ This package contains common code for Azure Communication Service libraries.
15
16
  npm install @azure/communication-common
16
17
  ```
17
18
 
19
+ ```bash
20
+ npm install @azure/identity
21
+ ```
22
+
18
23
  ### Browser support
19
24
 
20
25
  #### JavaScript Bundle
@@ -33,6 +38,7 @@ Depending on your scenario, you may want to initialize the `AzureCommunicationTo
33
38
 
34
39
  - a static token (suitable for short-lived clients used to e.g. send one-off Chat messages) or
35
40
  - a callback function that ensures a continuous authentication state during communications (ideal e.g. for long Calling sessions).
41
+ - a token credential capable of obtaining an Entra user token. You can provide any implementation of [TokenCredential interface](https://learn.microsoft.com/es-mx/javascript/api/@azure/core-auth/tokencredential?view=azure-node-latest). It is suitable for scenarios where Entra user access tokens are needed to authenticate with Communication Services.
36
42
 
37
43
  The tokens supplied to the `AzureCommunicationTokenCredential` either through the constructor or via the token refresher callback can be obtained using the Azure Communication Identity library.
38
44
 
@@ -105,6 +111,48 @@ const tokenCredential = new AzureCommunicationTokenCredential({
105
111
  });
106
112
  ```
107
113
 
114
+ ### Create a credential with a token credential capable of obtaining an Entra user token
115
+
116
+ For scenarios where an Entra user can be used with Communication Services, you need to initialize any implementation of [TokenCredential interface](https://learn.microsoft.com/es-mx/javascript/api/@azure/core-auth/tokencredential?view=azure-node-latest) and provide it to the ``EntraCommunicationTokenCredentialOptions``.
117
+ Along with this, you must provide the URI of the Azure Communication Services resource and the scopes required for the Entra user token. These scopes determine the permissions granted to the token.
118
+ If the scopes are not provided, by default, it sets the scopes to `https://communication.azure.com/clients/.default`.
119
+
120
+ ```typescript
121
+ const options: InteractiveBrowserCredentialInBrowserOptions = {
122
+ tenantId: "<your-tenant-id>",
123
+ clientId: "<your-client-id>",
124
+ redirectUri: "<your-redirect-uri>",
125
+ };
126
+ const entraTokenCredential = new InteractiveBrowserCredential(options);
127
+
128
+ const entraTokenCredentialOptions: EntraCommunicationTokenCredentialOptions = {
129
+ resourceEndpoint: "https://<your-resource>.communication.azure.com",
130
+ tokenCredential: entraTokenCredential,
131
+ scopes: ["https://communication.azure.com/clients/VoIP"]
132
+ };
133
+
134
+ const credential = new AzureCommunicationTokenCredential(entraTokenCredentialOptions);
135
+ ```
136
+
137
+ The same approach can be used for authorizing an Entra user with a Teams license to use Teams Phone Extensibility features through your Azure Communication Services resource.
138
+ This requires providing the `https://auth.msft.communication.azure.com/TeamsExtension.ManageCalls` scope.
139
+
140
+ ```typescript
141
+ const options: InteractiveBrowserCredentialInBrowserOptions = {
142
+ tenantId: "<your-tenant-id>",
143
+ clientId: "<your-client-id>",
144
+ redirectUri: "<your-redirect-uri>",
145
+ };
146
+ const entraTokenCredential = new InteractiveBrowserCredential(options);
147
+
148
+ const entraTokenCredentialOptions: EntraCommunicationTokenCredentialOptions = {
149
+ resourceEndpoint: "https://<your-resource>.communication.azure.com",
150
+ tokenCredential: entraTokenCredential,
151
+ scopes: ["https://auth.msft.communication.azure.com/TeamsExtension.ManageCalls"]
152
+ };
153
+
154
+ const credential = new AzureCommunicationTokenCredential(entraTokenCredentialOptions);
155
+ ```
108
156
  ## Troubleshooting
109
157
 
110
158
  - **Invalid token specified**: Make sure the token you are passing to the `AzureCommunicationTokenCredential` constructor or to the `tokenRefresher` callback is a bare JWT token string. E.g. if you're using the [Azure Communication Identity library][invalid_token_sdk] or [REST API][invalid_token_rest] to obtain the token, make sure you're passing just the `token` part of the response object.
@@ -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,iCAAi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AAI;IAKtB,OAAO,CAAC,eAAe;CAKxB"}
@@ -3,17 +3,21 @@
3
3
  import { AutoRefreshTokenCredential, } from "./autoRefreshTokenCredential.js";
4
4
  import { StaticTokenCredential } from "./staticTokenCredential.js";
5
5
  import { parseToken } from "./tokenParser.js";
6
+ import { EntraTokenCredential, } from "./entraTokenCredential.js";
6
7
  /**
7
8
  * The CommunicationTokenCredential implementation with support for proactive token refresh.
8
9
  */
9
10
  export class AzureCommunicationTokenCredential {
10
- constructor(tokenOrRefreshOptions) {
11
+ constructor(tokenOrRefreshOptionsOrEntraOptions) {
11
12
  this.disposed = false;
12
- if (typeof tokenOrRefreshOptions === "string") {
13
- this.tokenCredential = new StaticTokenCredential(parseToken(tokenOrRefreshOptions));
13
+ if (typeof tokenOrRefreshOptionsOrEntraOptions === "string") {
14
+ this.tokenCredential = new StaticTokenCredential(parseToken(tokenOrRefreshOptionsOrEntraOptions));
15
+ }
16
+ else if ("tokenRefresher" in tokenOrRefreshOptionsOrEntraOptions) {
17
+ this.tokenCredential = new AutoRefreshTokenCredential(tokenOrRefreshOptionsOrEntraOptions);
14
18
  }
15
19
  else {
16
- this.tokenCredential = new AutoRefreshTokenCredential(tokenOrRefreshOptions);
20
+ this.tokenCredential = new EntraTokenCredential(tokenOrRefreshOptionsOrEntraOptions);
17
21
  }
18
22
  }
19
23
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"azureCommunicationTokenCredential.js","sourceRoot":"","sources":["../../src/azureCommunicationTokenCredential.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EACL,0BAA0B,GAE3B,MAAM,iCAAiC,CAAC;AAOzC,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AACnE,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE9C;;GAEG;AAEH,MAAM,OAAO,iCAAiC;IAe5C,YAAY,qBAAgE;QAbpE,aAAQ,GAAG,KAAK,CAAC;QAcvB,IAAI,OAAO,qBAAqB,KAAK,QAAQ,EAAE,CAAC;YAC9C,IAAI,CAAC,eAAe,GAAG,IAAI,qBAAqB,CAAC,UAAU,CAAC,qBAAqB,CAAC,CAAC,CAAC;QACtF,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,eAAe,GAAG,IAAI,0BAA0B,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","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,OAAO,EACL,0BAA0B,GAE3B,MAAM,iCAAiC,CAAC;AAOzC,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AACnE,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAEL,oBAAoB,GACrB,MAAM,2BAA2B,CAAC;AAEnC;;GAEG;AAEH,MAAM,OAAO,iCAAiC;IAoB5C,YACE,mCAG4C;QAtBtC,aAAQ,GAAG,KAAK,CAAC;QAwBvB,IAAI,OAAO,mCAAmC,KAAK,QAAQ,EAAE,CAAC;YAC5D,IAAI,CAAC,eAAe,GAAG,IAAI,qBAAqB,CAC9C,UAAU,CAAC,mCAAmC,CAAC,CAChD,CAAC;QACJ,CAAC;aAAM,IAAI,gBAAgB,IAAI,mCAAmC,EAAE,CAAC;YACnE,IAAI,CAAC,eAAe,GAAG,IAAI,0BAA0B,CAAC,mCAAmC,CAAC,CAAC;QAC7F,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,eAAe,GAAG,IAAI,oBAAoB,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","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,120 @@
1
+ // Copyright (c) Microsoft Corporation.
2
+ // Licensed under the MIT License.
3
+ import { getClient } from "@azure-rest/core-client";
4
+ import { createDefaultHttpClient, createHttpHeaders, createPipelineRequest, } from "@azure/core-rest-pipeline";
5
+ const TeamsExtensionScopePrefix = "https://auth.msft.communication.azure.com/";
6
+ const CommunicationClientsScopePrefix = "https://communication.azure.com/clients/";
7
+ const TeamsExtensionEndpoint = "/access/teamsPhone/:exchangeAccessToken";
8
+ const TeamsExtensionApiVersion = "2025-03-02-preview";
9
+ const CommunicationClientsEndpoint = "/access/entra/:exchangeAccessToken";
10
+ const CommunicationClientsApiVersion = "2024-04-01-preview";
11
+ /**
12
+ * Represents a credential that exchanges an Entra token for an Azure Communication Services (ACS) token, enabling access to ACS resources.
13
+ */
14
+ export class EntraTokenCredential {
15
+ constructor(options) {
16
+ this.options = options;
17
+ this.result = {
18
+ entraToken: undefined,
19
+ acsToken: { token: "", expiresOnTimestamp: 0 },
20
+ };
21
+ this.client = getClient(options.resourceEndpoint);
22
+ this.httpClient = createDefaultHttpClient();
23
+ this.options = options;
24
+ this.options.scopes = this.options.scopes || [
25
+ "https://communication.azure.com/clients/.default",
26
+ ];
27
+ // immediately fetch the token to pre-warm
28
+ this.isPending = this.getToken();
29
+ }
30
+ async getToken(options) {
31
+ var _a;
32
+ if ((_a = options === null || options === void 0 ? void 0 : options.abortSignal) === null || _a === void 0 ? void 0 : _a.aborted) {
33
+ return { token: "", expiresOnTimestamp: 0 };
34
+ }
35
+ // we're awaiting the token fetch, so we don't want to start another one
36
+ // however, we're ignoring the new abortSignal, unfortunately
37
+ if (!this.isPending) {
38
+ this.isPending = this.getTokenInternal(options);
39
+ }
40
+ try {
41
+ await this.isPending;
42
+ }
43
+ finally {
44
+ this.isPending = null;
45
+ }
46
+ return this.result.acsToken;
47
+ }
48
+ async getTokenInternal(options) {
49
+ const getTokenOptions = (options === null || options === void 0 ? void 0 : options.abortSignal) ? { abortSignal: options.abortSignal } : undefined;
50
+ const token = await this.options.tokenCredential.getToken(this.options.scopes
51
+ ? this.options.scopes
52
+ : ["https://communication.azure.com/clients/.default"], getTokenOptions);
53
+ const currentDateTime = new Date();
54
+ const tokenExpiresOn = new Date(this.result.acsToken.expiresOnTimestamp);
55
+ if (token === null) {
56
+ this.result = {
57
+ entraToken: undefined,
58
+ acsToken: { token: "", expiresOnTimestamp: 0 },
59
+ };
60
+ }
61
+ else if (this.result.acsToken.token === "" ||
62
+ token.token !== this.result.entraToken ||
63
+ tokenExpiresOn < currentDateTime) {
64
+ const acsToken = await this.exchangeEntraToken(this.options.resourceEndpoint, token.token, getTokenOptions);
65
+ this.result = {
66
+ entraToken: token.token,
67
+ acsToken,
68
+ };
69
+ }
70
+ return this.result.acsToken;
71
+ }
72
+ dispose() {
73
+ this.result = {
74
+ entraToken: undefined,
75
+ acsToken: { token: "", expiresOnTimestamp: 0 },
76
+ };
77
+ }
78
+ async exchangeEntraToken(resourceEndpoint, entraToken, options) {
79
+ const request = createPipelineRequest({
80
+ url: this.createRequestUri(resourceEndpoint),
81
+ method: "POST",
82
+ headers: createHttpHeaders({
83
+ Authorization: `Bearer ${entraToken}`,
84
+ "Content-Type": "application/json",
85
+ Accept: "application/json",
86
+ }),
87
+ abortSignal: options === null || options === void 0 ? void 0 : options.abortSignal,
88
+ body: JSON.stringify({}),
89
+ });
90
+ const response = await this.client.pipeline.sendRequest(this.httpClient, request);
91
+ if (response.status !== 200 || !response.bodyAsText) {
92
+ throw new Error(`Service request failed. Status: ${response.status}, Body: ${response.bodyAsText}`);
93
+ }
94
+ const json = JSON.parse(response.bodyAsText);
95
+ return {
96
+ token: json.accessToken.token,
97
+ expiresOnTimestamp: Date.parse(json.accessToken.expiresOn),
98
+ };
99
+ }
100
+ createRequestUri(resourceEndpoint) {
101
+ const [endpoint, apiVersion] = this.determineEndpointAndApiVersion();
102
+ const requestUri = `${resourceEndpoint}${endpoint}?api-version=${apiVersion}`;
103
+ return requestUri;
104
+ }
105
+ determineEndpointAndApiVersion() {
106
+ if (!this.options.scopes || this.options.scopes.length === 0) {
107
+ throw new Error(`Scopes validation failed. Ensure all scopes start with either {TeamsExtensionScopePrefix} or {CommunicationClientsScopePrefix}.`);
108
+ }
109
+ else if (this.options.scopes.every((scope) => scope.startsWith(TeamsExtensionScopePrefix))) {
110
+ return [TeamsExtensionEndpoint, TeamsExtensionApiVersion];
111
+ }
112
+ else if (this.options.scopes.every((scope) => scope.startsWith(CommunicationClientsScopePrefix))) {
113
+ return [CommunicationClientsEndpoint, CommunicationClientsApiVersion];
114
+ }
115
+ else {
116
+ throw new Error(`Scopes validation failed. Ensure all scopes start with either {TeamsExtensionScopePrefix} or {CommunicationClientsScopePrefix}.`);
117
+ }
118
+ }
119
+ }
120
+ //# sourceMappingURL=entraTokenCredential.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"entraTokenCredential.js","sourceRoot":"","sources":["../../src/entraTokenCredential.ts"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QACJ,CAAC;IACH,CAAC;CACF","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"]}
@@ -28,6 +28,10 @@ export interface SerializedCommunicationIdentifier {
28
28
  * The Microsoft Teams App.
29
29
  */
30
30
  microsoftTeamsApp?: SerializedMicrosoftTeamsAppIdentifier;
31
+ /**
32
+ * The Microsoft Teams Extension user.
33
+ */
34
+ teamsExtensionUser?: SerializedTeamsExtensionUserIdentifier;
31
35
  }
32
36
  /**
33
37
  * @hidden
@@ -48,6 +52,14 @@ export interface SerializedPhoneNumberIdentifier {
48
52
  * The phone number in E.164 format.
49
53
  */
50
54
  value: string;
55
+ /**
56
+ * 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.
57
+ */
58
+ assertedId?: string;
59
+ /**
60
+ * True if the phone number is anonymous.
61
+ */
62
+ isAnonymous?: boolean;
51
63
  }
52
64
  /**
53
65
  * @hidden
@@ -55,7 +67,7 @@ export interface SerializedPhoneNumberIdentifier {
55
67
  */
56
68
  export interface SerializedMicrosoftTeamsUserIdentifier {
57
69
  /**
58
- * The Id of the Microsoft Teams user. If not anonymous, this is the AAD object Id of the user.
70
+ * The Id of the Microsoft Teams user. If not anonymous, this is the Entra ID object Id of the user.
59
71
  */
60
72
  userId: string;
61
73
  /**
@@ -81,6 +93,28 @@ export interface SerializedMicrosoftTeamsAppIdentifier {
81
93
  */
82
94
  cloud?: SerializedCommunicationCloudEnvironment;
83
95
  }
96
+ /**
97
+ * @hidden
98
+ * A Microsoft Teams Phone user who is using the Azure Communication Services resource to extend their Teams Phone set up.
99
+ */
100
+ export interface SerializedTeamsExtensionUserIdentifier {
101
+ /**
102
+ * The Id of the Microsoft Teams Extension user, i.e. the Entra ID object Id of the user.
103
+ */
104
+ userId: string;
105
+ /**
106
+ * The tenant Id of the Microsoft Teams Extension user.
107
+ */
108
+ tenantId: string;
109
+ /**
110
+ * The Azure Communication Services resource Id.
111
+ */
112
+ resourceId: string;
113
+ /**
114
+ * The cloud that the Microsoft Teams Extension user belongs to. If missing, the cloud is "public".
115
+ */
116
+ cloud?: SerializedCommunicationCloudEnvironment;
117
+ }
84
118
  /**
85
119
  * @hidden
86
120
  * Defines values for CommunicationCloudEnvironmentModel.
@@ -1 +1 @@
1
- {"version":3,"file":"identifierModelSerializer.d.ts","sourceRoot":"","sources":["../../src/identifierModelSerializer.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,KAAK,uBAAuB,EAC5B,KAAK,2BAA2B,EAGjC,MAAM,uBAAuB,CAAC;AAE/B;;;GAGG;AACH,MAAM,WAAW,iCAAiC;IAChD;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;OAEG;IACH,iBAAiB,CAAC,EAAE,qCAAqC,CAAC;IAC1D;;OAEG;IACH,WAAW,CAAC,EAAE,+BAA+B,CAAC;IAC9C;;OAEG;IACH,kBAAkB,CAAC,EAAE,sCAAsC,CAAC;IAC5D;;OAEG;IACH,iBAAiB,CAAC,EAAE,qCAAqC,CAAC;CAC3D;AAED;;;GAGG;AACH,MAAM,WAAW,qCAAqC;IACpD;;OAEG;IACH,EAAE,EAAE,MAAM,CAAC;CACZ;AAED;;;GAGG;AACH,MAAM,WAAW,+BAA+B;IAC9C;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;CACf;AAED;;;GAGG;AACH,MAAM,WAAW,sCAAsC;IACrD;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;IACf;;OAEG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB;;OAEG;IACH,KAAK,CAAC,EAAE,uCAAuC,CAAC;CACjD;AAED;;;GAGG;AACH,MAAM,WAAW,qCAAqC;IACpD;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IAEd;;OAEG;IACH,KAAK,CAAC,EAAE,uCAAuC,CAAC;CACjD;AAED;;;GAGG;AACH,MAAM,MAAM,uCAAuC,GAAG,QAAQ,GAAG,KAAK,GAAG,MAAM,CAAC;AAuChF;;;;GAIG;AACH,eAAO,MAAM,gCAAgC,eAC/B,uBAAuB,KAClC,iCAqCF,CAAC;AAsBF;;;;GAIG;AACH,eAAO,MAAM,kCAAkC,yBACvB,iCAAiC,KACtD,2BAyCF,CAAC"}
1
+ {"version":3,"file":"identifierModelSerializer.d.ts","sourceRoot":"","sources":["../../src/identifierModelSerializer.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,KAAK,uBAAuB,EAC5B,KAAK,2BAA2B,EAGjC,MAAM,uBAAuB,CAAC;AAE/B;;;GAGG;AACH,MAAM,WAAW,iCAAiC;IAChD;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;OAEG;IACH,iBAAiB,CAA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GAIG;AACH,eAAO,MAAM,kCAAkC,yBACvB,iCAAiC,KACtD,2BAwDF,CAAC"}
@@ -23,6 +23,9 @@ const assertMaximumOneNestedModel = (identifier) => {
23
23
  if (identifier.phoneNumber !== undefined) {
24
24
  presentProperties.push("phoneNumber");
25
25
  }
26
+ if (identifier.teamsExtensionUser !== undefined) {
27
+ presentProperties.push("teamsExtensionUser");
28
+ }
26
29
  if (presentProperties.length > 1) {
27
30
  throw new Error(`Only one of the properties in ${JSON.stringify(presentProperties)} should be present.`);
28
31
  }
@@ -33,7 +36,7 @@ const assertMaximumOneNestedModel = (identifier) => {
33
36
  * @param identifier - The CommunicationIdentifier to be serialized.
34
37
  */
35
38
  export const serializeCommunicationIdentifier = (identifier) => {
36
- var _a, _b, _c, _d, _e, _f;
39
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
37
40
  const identifierKind = getIdentifierKind(identifier);
38
41
  switch (identifierKind.kind) {
39
42
  case "communicationUser":
@@ -46,23 +49,35 @@ export const serializeCommunicationIdentifier = (identifier) => {
46
49
  rawId: (_a = identifierKind.rawId) !== null && _a !== void 0 ? _a : getIdentifierRawId(identifierKind),
47
50
  phoneNumber: {
48
51
  value: identifierKind.phoneNumber,
52
+ isAnonymous: (_b = identifierKind.isAnonymous) !== null && _b !== void 0 ? _b : false,
53
+ assertedId: identifierKind.assertedId,
49
54
  },
50
55
  };
51
56
  case "microsoftTeamsUser":
52
57
  return {
53
- rawId: (_b = identifierKind.rawId) !== null && _b !== void 0 ? _b : getIdentifierRawId(identifierKind),
58
+ rawId: (_c = identifierKind.rawId) !== null && _c !== void 0 ? _c : getIdentifierRawId(identifierKind),
54
59
  microsoftTeamsUser: {
55
60
  userId: identifierKind.microsoftTeamsUserId,
56
- isAnonymous: (_c = identifierKind.isAnonymous) !== null && _c !== void 0 ? _c : false,
57
- cloud: (_d = identifierKind.cloud) !== null && _d !== void 0 ? _d : "public",
61
+ isAnonymous: (_d = identifierKind.isAnonymous) !== null && _d !== void 0 ? _d : false,
62
+ cloud: (_e = identifierKind.cloud) !== null && _e !== void 0 ? _e : "public",
58
63
  },
59
64
  };
60
65
  case "microsoftTeamsApp":
61
66
  return {
62
- rawId: (_e = identifierKind.rawId) !== null && _e !== void 0 ? _e : getIdentifierRawId(identifierKind),
67
+ rawId: (_f = identifierKind.rawId) !== null && _f !== void 0 ? _f : getIdentifierRawId(identifierKind),
63
68
  microsoftTeamsApp: {
64
69
  appId: identifierKind.teamsAppId,
65
- cloud: (_f = identifierKind.cloud) !== null && _f !== void 0 ? _f : "public",
70
+ cloud: (_g = identifierKind.cloud) !== null && _g !== void 0 ? _g : "public",
71
+ },
72
+ };
73
+ case "teamsExtensionUser":
74
+ return {
75
+ rawId: (_h = identifierKind.rawId) !== null && _h !== void 0 ? _h : getIdentifierRawId(identifierKind),
76
+ teamsExtensionUser: {
77
+ userId: identifierKind.userId,
78
+ tenantId: identifierKind.tenantId,
79
+ resourceId: identifierKind.resourceId,
80
+ cloud: (_j = identifierKind.cloud) !== null && _j !== void 0 ? _j : "public",
66
81
  },
67
82
  };
68
83
  case "unknown":
@@ -84,6 +99,9 @@ const getKind = (serializedIdentifier) => {
84
99
  if (serializedIdentifier.microsoftTeamsApp) {
85
100
  return "microsoftTeamsApp";
86
101
  }
102
+ if (serializedIdentifier.teamsExtensionUser) {
103
+ return "teamsExtensionUser";
104
+ }
87
105
  return "unknown";
88
106
  };
89
107
  /**
@@ -92,9 +110,13 @@ const getKind = (serializedIdentifier) => {
92
110
  * @param serializedIdentifier - The SerializedCommunicationIdentifier to be deserialized.
93
111
  */
94
112
  export const deserializeCommunicationIdentifier = (serializedIdentifier) => {
95
- var _a;
113
+ var _a, _b;
96
114
  assertMaximumOneNestedModel(serializedIdentifier);
97
- const { communicationUser, microsoftTeamsUser, microsoftTeamsApp, phoneNumber } = serializedIdentifier;
115
+ const communicationUser = serializedIdentifier.communicationUser;
116
+ const microsoftTeamsUser = serializedIdentifier.microsoftTeamsUser;
117
+ const microsoftTeamsApp = serializedIdentifier.microsoftTeamsApp;
118
+ const phoneNumber = serializedIdentifier.phoneNumber;
119
+ const teamsExtensionUser = serializedIdentifier.teamsExtensionUser;
98
120
  const kind = (_a = serializedIdentifier.kind) !== null && _a !== void 0 ? _a : getKind(serializedIdentifier);
99
121
  if (kind === "communicationUser" && communicationUser) {
100
122
  return {
@@ -107,6 +129,8 @@ export const deserializeCommunicationIdentifier = (serializedIdentifier) => {
107
129
  kind: "phoneNumber",
108
130
  phoneNumber: assertNotNullOrUndefined({ phoneNumber }, "value"),
109
131
  rawId: assertNotNullOrUndefined({ phoneNumber: serializedIdentifier }, "rawId"),
132
+ isAnonymous: (_b = phoneNumber.isAnonymous) !== null && _b !== void 0 ? _b : false,
133
+ assertedId: phoneNumber.assertedId,
110
134
  };
111
135
  }
112
136
  if (kind === "microsoftTeamsUser" && microsoftTeamsUser) {
@@ -126,6 +150,16 @@ export const deserializeCommunicationIdentifier = (serializedIdentifier) => {
126
150
  rawId: assertNotNullOrUndefined({ microsoftTeamsApp: serializedIdentifier }, "rawId"),
127
151
  };
128
152
  }
153
+ if (kind === "teamsExtensionUser" && teamsExtensionUser) {
154
+ return {
155
+ kind: "teamsExtensionUser",
156
+ userId: assertNotNullOrUndefined({ teamsExtensionUser }, "userId"),
157
+ tenantId: assertNotNullOrUndefined({ teamsExtensionUser }, "tenantId"),
158
+ resourceId: assertNotNullOrUndefined({ teamsExtensionUser }, "resourceId"),
159
+ cloud: assertNotNullOrUndefined({ teamsExtensionUser }, "cloud"),
160
+ rawId: assertNotNullOrUndefined({ teamsExtensionUser: serializedIdentifier }, "rawId"),
161
+ };
162
+ }
129
163
  return {
130
164
  kind: "unknown",
131
165
  id: assertNotNullOrUndefined({ unknown: serializedIdentifier }, "rawId"),
@@ -1 +1 @@
1
- {"version":3,"file":"identifierModelSerializer.js","sourceRoot":"","sources":["../../src/identifierModelSerializer.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAGL,iB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AAE,CAAC;QACxD,OAAO;YACL,IAAI,EAAE,oBAAoB;YAC1B,oBAAoB,EAAE,wBAAwB,CAAC,EAAE,kBAAkB,EAAE,EAAE,QAAQ,CAAC;YAChF,WAAW,EAAE,wBAAwB,CAAC,EAAE,kBAAkB,EAAE,EAAE,aAAa,CAAC;YAC5E,KAAK,EAAE,wBAAwB,CAAC,EAAE,kBAAkB,EAAE,EAAE,OAAO,CAAC;YAChE,KAAK,EAAE,wBAAwB,CAAC,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,EAAE,OAAO,CAAC;SACvF,CAAC;IACJ,CAAC;IACD,IAAI,IAAI,KAAK,mBAAmB,IAAI,iBAAiB,EAAE,CAAC;QACtD,OAAO;YACL,IAAI,EAAE,mBAAmB;YACzB,UAAU,EAAE,wBAAwB,CAAC,EAAE,iBAAiB,EAAE,EAAE,OAAO,CAAC;YACpE,KAAK,EAAE,wBAAwB,CAAC,EAAE,iBAAiB,EAAE,EAAE,OAAO,CAAC;YAC/D,KAAK,EAAE,wBAAwB,CAAC,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,EAAE,OAAO,CAAC;SACtF,CAAC;IACJ,CAAC;IACD,OAAO;QACL,IAAI,EAAE,SAAS;QACf,EAAE,EAAE,wBAAwB,CAAC,EAAE,OAAO,EAAE,oBAAoB,EAAE,EAAE,OAAO,CAAC;KACzE,CAAC;AACJ,CAAC,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport {\n type CommunicationIdentifier,\n type CommunicationIdentifierKind,\n getIdentifierKind,\n getIdentifierRawId,\n} from \"./identifierModels.js\";\n\n/**\n * @hidden\n * Identifies a participant in Azure Communication services. A participant is, for example, a phone number or an Azure communication user. This model must be interpreted as a union: Apart from rawId, at most one further property may be set.\n */\nexport interface SerializedCommunicationIdentifier {\n /**\n * Kind of the identifier, optional.\n */\n kind?: string;\n /**\n * Raw Id of the identifier. Optional in requests, required in responses.\n */\n rawId?: string;\n /**\n * The communication user.\n */\n communicationUser?: SerializedCommunicationUserIdentifier;\n /**\n * The phone number.\n */\n phoneNumber?: SerializedPhoneNumberIdentifier;\n /**\n * The Microsoft Teams user.\n */\n microsoftTeamsUser?: SerializedMicrosoftTeamsUserIdentifier;\n /**\n * The Microsoft Teams App.\n */\n microsoftTeamsApp?: SerializedMicrosoftTeamsAppIdentifier;\n}\n\n/**\n * @hidden\n * A user that got created with an Azure Communication Services resource.\n */\nexport interface SerializedCommunicationUserIdentifier {\n /**\n * The Id of the communication user.\n */\n id: string;\n}\n\n/**\n * @hidden\n * A phone number.\n */\nexport interface SerializedPhoneNumberIdentifier {\n /**\n * The phone number in E.164 format.\n */\n value: string;\n}\n\n/**\n * @hidden\n * A Microsoft Teams user.\n */\nexport interface SerializedMicrosoftTeamsUserIdentifier {\n /**\n * The Id of the Microsoft Teams user. If not anonymous, this is the AAD object Id of the user.\n */\n userId: string;\n /**\n * True if the Microsoft Teams user is anonymous. By default false if missing.\n */\n isAnonymous?: boolean;\n /**\n * The cloud that the Microsoft Teams user belongs to. By default 'public' if missing.\n */\n cloud?: SerializedCommunicationCloudEnvironment;\n}\n\n/**\n * @hidden\n * A Microsoft Teams App.\n */\nexport interface SerializedMicrosoftTeamsAppIdentifier {\n /**\n * Id of the Microsoft Teams App.\n */\n appId: string;\n\n /**\n * The cloud that the Microsoft Teams App belongs to. By default 'public' if missing.\n */\n cloud?: SerializedCommunicationCloudEnvironment;\n}\n\n/**\n * @hidden\n * Defines values for CommunicationCloudEnvironmentModel.\n */\nexport type SerializedCommunicationCloudEnvironment = \"public\" | \"dod\" | \"gcch\";\n\nconst assertNotNullOrUndefined = <\n T extends Record<string, unknown>,\n P extends keyof T,\n Q extends string & keyof T[P],\n>(\n obj: T,\n prop: Q,\n): Required<Required<T>[P]>[Q] => {\n const subObjName = Object.keys(obj)[0];\n const subObj = (obj as any)[subObjName];\n if (prop in subObj) {\n return subObj[prop];\n }\n throw new Error(`Property ${prop} is required for identifier of type ${subObjName}.`);\n};\n\nconst assertMaximumOneNestedModel = (identifier: SerializedCommunicationIdentifier): void => {\n const presentProperties: string[] = [];\n if (identifier.communicationUser !== undefined) {\n presentProperties.push(\"communicationUser\");\n }\n if (identifier.microsoftTeamsUser !== undefined) {\n presentProperties.push(\"microsoftTeamsUser\");\n }\n if (identifier.microsoftTeamsApp !== undefined) {\n presentProperties.push(\"microsoftTeamsApp\");\n }\n if (identifier.phoneNumber !== undefined) {\n presentProperties.push(\"phoneNumber\");\n }\n if (presentProperties.length > 1) {\n throw new Error(\n `Only one of the properties in ${JSON.stringify(presentProperties)} should be present.`,\n );\n }\n};\n\n/**\n * @hidden\n * Translates a CommunicationIdentifier to its serialized format for sending a request.\n * @param identifier - The CommunicationIdentifier to be serialized.\n */\nexport const serializeCommunicationIdentifier = (\n identifier: CommunicationIdentifier,\n): SerializedCommunicationIdentifier => {\n const identifierKind = getIdentifierKind(identifier);\n switch (identifierKind.kind) {\n case \"communicationUser\":\n return {\n rawId: getIdentifierRawId(identifierKind),\n communicationUser: { id: identifierKind.communicationUserId },\n };\n case \"phoneNumber\":\n return {\n rawId: identifierKind.rawId ?? getIdentifierRawId(identifierKind),\n phoneNumber: {\n value: identifierKind.phoneNumber,\n },\n };\n case \"microsoftTeamsUser\":\n return {\n rawId: identifierKind.rawId ?? getIdentifierRawId(identifierKind),\n microsoftTeamsUser: {\n userId: identifierKind.microsoftTeamsUserId,\n isAnonymous: identifierKind.isAnonymous ?? false,\n cloud: identifierKind.cloud ?? \"public\",\n },\n };\n case \"microsoftTeamsApp\":\n return {\n rawId: identifierKind.rawId ?? getIdentifierRawId(identifierKind),\n microsoftTeamsApp: {\n appId: identifierKind.teamsAppId,\n cloud: identifierKind.cloud ?? \"public\",\n },\n };\n case \"unknown\":\n return { rawId: identifierKind.id };\n default:\n throw new Error(`Can't serialize an identifier with kind ${(identifierKind as any).kind}`);\n }\n};\n\nconst getKind = (serializedIdentifier: SerializedCommunicationIdentifier): string => {\n if (serializedIdentifier.communicationUser) {\n return \"communicationUser\";\n }\n\n if (serializedIdentifier.phoneNumber) {\n return \"phoneNumber\";\n }\n\n if (serializedIdentifier.microsoftTeamsUser) {\n return \"microsoftTeamsUser\";\n }\n\n if (serializedIdentifier.microsoftTeamsApp) {\n return \"microsoftTeamsApp\";\n }\n\n return \"unknown\";\n};\n\n/**\n * @hidden\n * Translates the serialized format of a communication identifier to CommunicationIdentifier.\n * @param serializedIdentifier - The SerializedCommunicationIdentifier to be deserialized.\n */\nexport const deserializeCommunicationIdentifier = (\n serializedIdentifier: SerializedCommunicationIdentifier,\n): CommunicationIdentifierKind => {\n assertMaximumOneNestedModel(serializedIdentifier);\n\n const { communicationUser, microsoftTeamsUser, microsoftTeamsApp, phoneNumber } =\n serializedIdentifier;\n const kind = serializedIdentifier.kind ?? getKind(serializedIdentifier);\n\n if (kind === \"communicationUser\" && communicationUser) {\n return {\n kind: \"communicationUser\",\n communicationUserId: assertNotNullOrUndefined({ communicationUser }, \"id\"),\n };\n }\n if (kind === \"phoneNumber\" && phoneNumber) {\n return {\n kind: \"phoneNumber\",\n phoneNumber: assertNotNullOrUndefined({ phoneNumber }, \"value\"),\n rawId: assertNotNullOrUndefined({ phoneNumber: serializedIdentifier }, \"rawId\"),\n };\n }\n if (kind === \"microsoftTeamsUser\" && microsoftTeamsUser) {\n return {\n kind: \"microsoftTeamsUser\",\n microsoftTeamsUserId: assertNotNullOrUndefined({ microsoftTeamsUser }, \"userId\"),\n isAnonymous: assertNotNullOrUndefined({ microsoftTeamsUser }, \"isAnonymous\"),\n cloud: assertNotNullOrUndefined({ microsoftTeamsUser }, \"cloud\"),\n rawId: assertNotNullOrUndefined({ microsoftTeamsUser: serializedIdentifier }, \"rawId\"),\n };\n }\n if (kind === \"microsoftTeamsApp\" && microsoftTeamsApp) {\n return {\n kind: \"microsoftTeamsApp\",\n teamsAppId: assertNotNullOrUndefined({ microsoftTeamsApp }, \"appId\"),\n cloud: assertNotNullOrUndefined({ microsoftTeamsApp }, \"cloud\"),\n rawId: assertNotNullOrUndefined({ microsoftTeamsApp: serializedIdentifier }, \"rawId\"),\n };\n }\n return {\n kind: \"unknown\",\n id: assertNotNullOrUndefined({ unknown: serializedIdentifier }, \"rawId\"),\n };\n};\n"]}
1
+ {"version":3,"file":"identifierModelSerializer.js","sourceRoot":"","sources":["../../src/identifierModelSerializer.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAGL,iBAAiB,EACjB,kBAAkB,GACnB,MAAM,uBAAuB,CAAC;AAsI/B,MAAM,wBAAwB,GAAG,CAK/B,GAAM,EACN,IAAO,EACsB,EAAE;IAC/B,MAAM,UAAU,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IACvC,MAAM,MAAM,GAAI,GAAW,CAAC,UAAU,CAAC,CAAC;IACxC,IAAI,IAAI,IAAI,MAAM,EAAE,CAAC;QACnB,OAAO,MAAM,CAAC,IAAI,CAAC,CAAC;IACtB,CAAC;IACD,MAAM,IAAI,KAAK,CAAC,YAAY,IAAI,uCAAuC,UAAU,GAAG,CAAC,CAAC;AACxF,CAAC,CAAC;AAEF,MAAM,2BAA2B,GAAG,CAAC,UAA6C,EAAQ,EAAE;IAC1F,MAAM,iBAAiB,GAAa,EAAE,CAAC;IACvC,IAAI,UAAU,CAAC,iBAAiB,KAAK,SAAS,EAAE,CAAC;QAC/C,iBAAiB,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC;IAC9C,CAAC;IACD,IAAI,UAAU,CAAC,kBAAkB,KAAK,SAAS,EAAE,CAAC;QAChD,iBAAiB,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAC;IAC/C,CAAC;IACD,IAAI,UAAU,CAAC,iBAAiB,KAAK,SAAS,EAAE,CAAC;QAC/C,iBAAiB,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC;IAC9C,CAAC;IACD,IAAI,UAAU,CAAC,WAAW,KAAK,SAAS,EAAE,CA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,OAAO,EAAE,oBAAoB,EAAE,EAAE,OAAO,CAAC;KACzE,CAAC;AACJ,CAAC,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport {\n type CommunicationIdentifier,\n type CommunicationIdentifierKind,\n getIdentifierKind,\n getIdentifierRawId,\n} from \"./identifierModels.js\";\n\n/**\n * @hidden\n * Identifies a participant in Azure Communication services. A participant is, for example, a phone number or an Azure communication user. This model must be interpreted as a union: Apart from rawId, at most one further property may be set.\n */\nexport interface SerializedCommunicationIdentifier {\n /**\n * Kind of the identifier, optional.\n */\n kind?: string;\n /**\n * Raw Id of the identifier. Optional in requests, required in responses.\n */\n rawId?: string;\n /**\n * The communication user.\n */\n communicationUser?: SerializedCommunicationUserIdentifier;\n /**\n * The phone number.\n */\n phoneNumber?: SerializedPhoneNumberIdentifier;\n /**\n * The Microsoft Teams user.\n */\n microsoftTeamsUser?: SerializedMicrosoftTeamsUserIdentifier;\n /**\n * The Microsoft Teams App.\n */\n microsoftTeamsApp?: SerializedMicrosoftTeamsAppIdentifier;\n /**\n * The Microsoft Teams Extension user.\n */\n teamsExtensionUser?: SerializedTeamsExtensionUserIdentifier;\n}\n\n/**\n * @hidden\n * A user that got created with an Azure Communication Services resource.\n */\nexport interface SerializedCommunicationUserIdentifier {\n /**\n * The Id of the communication user.\n */\n id: string;\n}\n\n/**\n * @hidden\n * A phone number.\n */\nexport interface SerializedPhoneNumberIdentifier {\n /**\n * The phone number in E.164 format.\n */\n value: string;\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 * True if the phone number is anonymous.\n */\n isAnonymous?: boolean;\n}\n\n/**\n * @hidden\n * A Microsoft Teams user.\n */\nexport interface SerializedMicrosoftTeamsUserIdentifier {\n /**\n * The Id of the Microsoft Teams user. If not anonymous, this is the Entra ID object Id of the user.\n */\n userId: string;\n /**\n * True if the Microsoft Teams user is anonymous. By default false if missing.\n */\n isAnonymous?: boolean;\n /**\n * The cloud that the Microsoft Teams user belongs to. By default 'public' if missing.\n */\n cloud?: SerializedCommunicationCloudEnvironment;\n}\n\n/**\n * @hidden\n * A Microsoft Teams App.\n */\nexport interface SerializedMicrosoftTeamsAppIdentifier {\n /**\n * Id of the Microsoft Teams App.\n */\n appId: string;\n\n /**\n * The cloud that the Microsoft Teams App belongs to. By default 'public' if missing.\n */\n cloud?: SerializedCommunicationCloudEnvironment;\n}\n\n/**\n * @hidden\n * A Microsoft Teams Phone user who is using the Azure Communication Services resource to extend their Teams Phone set up.\n */\nexport interface SerializedTeamsExtensionUserIdentifier {\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?: SerializedCommunicationCloudEnvironment;\n}\n\n/**\n * @hidden\n * Defines values for CommunicationCloudEnvironmentModel.\n */\nexport type SerializedCommunicationCloudEnvironment = \"public\" | \"dod\" | \"gcch\";\n\nconst assertNotNullOrUndefined = <\n T extends Record<string, unknown>,\n P extends keyof T,\n Q extends string & keyof T[P],\n>(\n obj: T,\n prop: Q,\n): Required<Required<T>[P]>[Q] => {\n const subObjName = Object.keys(obj)[0];\n const subObj = (obj as any)[subObjName];\n if (prop in subObj) {\n return subObj[prop];\n }\n throw new Error(`Property ${prop} is required for identifier of type ${subObjName}.`);\n};\n\nconst assertMaximumOneNestedModel = (identifier: SerializedCommunicationIdentifier): void => {\n const presentProperties: string[] = [];\n if (identifier.communicationUser !== undefined) {\n presentProperties.push(\"communicationUser\");\n }\n if (identifier.microsoftTeamsUser !== undefined) {\n presentProperties.push(\"microsoftTeamsUser\");\n }\n if (identifier.microsoftTeamsApp !== undefined) {\n presentProperties.push(\"microsoftTeamsApp\");\n }\n if (identifier.phoneNumber !== undefined) {\n presentProperties.push(\"phoneNumber\");\n }\n if (identifier.teamsExtensionUser !== undefined) {\n presentProperties.push(\"teamsExtensionUser\");\n }\n if (presentProperties.length > 1) {\n throw new Error(\n `Only one of the properties in ${JSON.stringify(presentProperties)} should be present.`,\n );\n }\n};\n\n/**\n * @hidden\n * Translates a CommunicationIdentifier to its serialized format for sending a request.\n * @param identifier - The CommunicationIdentifier to be serialized.\n */\nexport const serializeCommunicationIdentifier = (\n identifier: CommunicationIdentifier,\n): SerializedCommunicationIdentifier => {\n const identifierKind = getIdentifierKind(identifier);\n switch (identifierKind.kind) {\n case \"communicationUser\":\n return {\n rawId: getIdentifierRawId(identifierKind),\n communicationUser: { id: identifierKind.communicationUserId },\n };\n case \"phoneNumber\":\n return {\n rawId: identifierKind.rawId ?? getIdentifierRawId(identifierKind),\n phoneNumber: {\n value: identifierKind.phoneNumber,\n isAnonymous: identifierKind.isAnonymous ?? false,\n assertedId: identifierKind.assertedId,\n },\n };\n case \"microsoftTeamsUser\":\n return {\n rawId: identifierKind.rawId ?? getIdentifierRawId(identifierKind),\n microsoftTeamsUser: {\n userId: identifierKind.microsoftTeamsUserId,\n isAnonymous: identifierKind.isAnonymous ?? false,\n cloud: identifierKind.cloud ?? \"public\",\n },\n };\n case \"microsoftTeamsApp\":\n return {\n rawId: identifierKind.rawId ?? getIdentifierRawId(identifierKind),\n microsoftTeamsApp: {\n appId: identifierKind.teamsAppId,\n cloud: identifierKind.cloud ?? \"public\",\n },\n };\n case \"teamsExtensionUser\":\n return {\n rawId: identifierKind.rawId ?? getIdentifierRawId(identifierKind),\n teamsExtensionUser: {\n userId: identifierKind.userId,\n tenantId: identifierKind.tenantId,\n resourceId: identifierKind.resourceId,\n cloud: identifierKind.cloud ?? \"public\",\n },\n };\n case \"unknown\":\n return { rawId: identifierKind.id };\n default:\n throw new Error(`Can't serialize an identifier with kind ${(identifierKind as any).kind}`);\n }\n};\n\nconst getKind = (serializedIdentifier: SerializedCommunicationIdentifier): string => {\n if (serializedIdentifier.communicationUser) {\n return \"communicationUser\";\n }\n\n if (serializedIdentifier.phoneNumber) {\n return \"phoneNumber\";\n }\n\n if (serializedIdentifier.microsoftTeamsUser) {\n return \"microsoftTeamsUser\";\n }\n\n if (serializedIdentifier.microsoftTeamsApp) {\n return \"microsoftTeamsApp\";\n }\n\n if (serializedIdentifier.teamsExtensionUser) {\n return \"teamsExtensionUser\";\n }\n\n return \"unknown\";\n};\n\n/**\n * @hidden\n * Translates the serialized format of a communication identifier to CommunicationIdentifier.\n * @param serializedIdentifier - The SerializedCommunicationIdentifier to be deserialized.\n */\nexport const deserializeCommunicationIdentifier = (\n serializedIdentifier: SerializedCommunicationIdentifier,\n): CommunicationIdentifierKind => {\n assertMaximumOneNestedModel(serializedIdentifier);\n\n const communicationUser = serializedIdentifier.communicationUser;\n const microsoftTeamsUser = serializedIdentifier.microsoftTeamsUser;\n const microsoftTeamsApp = serializedIdentifier.microsoftTeamsApp;\n const phoneNumber = serializedIdentifier.phoneNumber;\n const teamsExtensionUser = serializedIdentifier.teamsExtensionUser;\n const kind = serializedIdentifier.kind ?? getKind(serializedIdentifier);\n\n if (kind === \"communicationUser\" && communicationUser) {\n return {\n kind: \"communicationUser\",\n communicationUserId: assertNotNullOrUndefined({ communicationUser }, \"id\"),\n };\n }\n if (kind === \"phoneNumber\" && phoneNumber) {\n return {\n kind: \"phoneNumber\",\n phoneNumber: assertNotNullOrUndefined({ phoneNumber }, \"value\"),\n rawId: assertNotNullOrUndefined({ phoneNumber: serializedIdentifier }, \"rawId\"),\n isAnonymous: phoneNumber.isAnonymous ?? false,\n assertedId: phoneNumber.assertedId,\n };\n }\n if (kind === \"microsoftTeamsUser\" && microsoftTeamsUser) {\n return {\n kind: \"microsoftTeamsUser\",\n microsoftTeamsUserId: assertNotNullOrUndefined({ microsoftTeamsUser }, \"userId\"),\n isAnonymous: assertNotNullOrUndefined({ microsoftTeamsUser }, \"isAnonymous\"),\n cloud: assertNotNullOrUndefined({ microsoftTeamsUser }, \"cloud\"),\n rawId: assertNotNullOrUndefined({ microsoftTeamsUser: serializedIdentifier }, \"rawId\"),\n };\n }\n if (kind === \"microsoftTeamsApp\" && microsoftTeamsApp) {\n return {\n kind: \"microsoftTeamsApp\",\n teamsAppId: assertNotNullOrUndefined({ microsoftTeamsApp }, \"appId\"),\n cloud: assertNotNullOrUndefined({ microsoftTeamsApp }, \"cloud\"),\n rawId: assertNotNullOrUndefined({ microsoftTeamsApp: serializedIdentifier }, \"rawId\"),\n };\n }\n if (kind === \"teamsExtensionUser\" && teamsExtensionUser) {\n return {\n kind: \"teamsExtensionUser\",\n userId: assertNotNullOrUndefined({ teamsExtensionUser }, \"userId\"),\n tenantId: assertNotNullOrUndefined({ teamsExtensionUser }, \"tenantId\"),\n resourceId: assertNotNullOrUndefined({ teamsExtensionUser }, \"resourceId\"),\n cloud: assertNotNullOrUndefined({ teamsExtensionUser }, \"cloud\"),\n rawId: assertNotNullOrUndefined({ teamsExtensionUser: serializedIdentifier }, \"rawId\"),\n };\n }\n return {\n kind: \"unknown\",\n id: assertNotNullOrUndefined({ unknown: serializedIdentifier }, \"rawId\"),\n };\n};\n"]}