@azure/communication-common 2.1.1-alpha.20221020.2 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -506,28 +506,42 @@ const serializeCommunicationIdentifier = (identifier) => {
506
506
  throw new Error(`Can't serialize an identifier with kind ${identifierKind.kind}`);
507
507
  }
508
508
  };
509
+ const getKind = (serializedIdentifier) => {
510
+ if (serializedIdentifier.communicationUser) {
511
+ return "communicationUser";
512
+ }
513
+ if (serializedIdentifier.phoneNumber) {
514
+ return "phoneNumber";
515
+ }
516
+ if (serializedIdentifier.microsoftTeamsUser) {
517
+ return "microsoftTeamsUser";
518
+ }
519
+ return "unknown";
520
+ };
509
521
  /**
510
522
  * @hidden
511
523
  * Translates the serialized format of a communication identifier to CommunicationIdentifier.
512
524
  * @param serializedIdentifier - The SerializedCommunicationIdentifier to be deserialized.
513
525
  */
514
526
  const deserializeCommunicationIdentifier = (serializedIdentifier) => {
527
+ var _a;
515
528
  assertMaximumOneNestedModel(serializedIdentifier);
516
529
  const { communicationUser, microsoftTeamsUser, phoneNumber } = serializedIdentifier;
517
- if (communicationUser) {
530
+ const kind = (_a = serializedIdentifier.kind) !== null && _a !== void 0 ? _a : getKind(serializedIdentifier);
531
+ if (kind === "communicationUser" && communicationUser) {
518
532
  return {
519
533
  kind: "communicationUser",
520
534
  communicationUserId: assertNotNullOrUndefined({ communicationUser }, "id"),
521
535
  };
522
536
  }
523
- if (phoneNumber) {
537
+ if (kind === "phoneNumber" && phoneNumber) {
524
538
  return {
525
539
  kind: "phoneNumber",
526
540
  phoneNumber: assertNotNullOrUndefined({ phoneNumber }, "value"),
527
541
  rawId: assertNotNullOrUndefined({ phoneNumber: serializedIdentifier }, "rawId"),
528
542
  };
529
543
  }
530
- if (microsoftTeamsUser) {
544
+ if (kind === "microsoftTeamsUser" && microsoftTeamsUser) {
531
545
  return {
532
546
  kind: "microsoftTeamsUser",
533
547
  microsoftTeamsUserId: assertNotNullOrUndefined({ microsoftTeamsUser }, "userId"),
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../src/tokenParser.ts","../src/autoRefreshTokenCredential.ts","../src/staticTokenCredential.ts","../src/azureCommunicationTokenCredential.ts","../src/credential/cryptoUtils.ts","../src/credential/communicationAccessKeyCredentialPolicy.ts","../src/credential/communicationAuthPolicy.ts","../src/credential/connectionString.ts","../src/credential/clientArguments.ts","../src/identifierModels.ts","../src/identifierModelSerializer.ts"],"sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { AccessToken } from \"@azure/core-auth\";\nimport jwtDecode from \"jwt-decode\";\n\ninterface JwtToken {\n exp: number;\n}\n\nexport const parseToken = (token: string): AccessToken => {\n const { exp } = jwtDecode<JwtToken>(token);\n return {\n token,\n expiresOnTimestamp: exp * 1000,\n };\n};\n","// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { CommunicationGetTokenOptions, TokenCredential } from \"./communicationTokenCredential\";\nimport { AbortSignalLike } from \"@azure/abort-controller\";\nimport { AccessToken } from \"@azure/core-auth\";\nimport { parseToken } from \"./tokenParser\";\n\n/**\n * Options for auto-refreshing a Communication Token credential.\n */\nexport interface CommunicationTokenRefreshOptions {\n /**\n * Callback function that returns a string JWT token acquired from the Communication Identity API.\n * The returned token must be valid (expiration date must be in the future).\n */\n tokenRefresher: (abortSignal?: AbortSignalLike) => Promise<string>;\n\n /**\n * Optional token to initialize.\n */\n token?: string;\n\n /**\n * Indicates whether the token should be proactively renewed prior to expiry or only renew on demand.\n * By default false.\n */\n refreshProactively?: boolean;\n}\n\nconst expiredToken = { token: \"\", expiresOnTimestamp: -10 };\nconst minutesToMs = (minutes: number): number => minutes * 1000 * 60;\nconst defaultExpiringSoonInterval = minutesToMs(10);\nconst defaultRefreshAfterLifetimePercentage = 0.5;\n\nexport class AutoRefreshTokenCredential implements TokenCredential {\n private readonly refresh: (abortSignal?: AbortSignalLike) => Promise<string>;\n private readonly refreshProactively: boolean;\n private readonly expiringSoonIntervalInMs: number = defaultExpiringSoonInterval;\n private readonly refreshAfterLifetimePercentage = defaultRefreshAfterLifetimePercentage;\n\n private currentToken: AccessToken;\n private activeTimeout: ReturnType<typeof setTimeout> | undefined;\n private activeTokenFetching: Promise<string> | null = null;\n private activeTokenUpdating: Promise<void> | null = null;\n private disposed = false;\n\n constructor(refreshArgs: CommunicationTokenRefreshOptions) {\n const { tokenRefresher, token, refreshProactively } = refreshArgs;\n\n this.refresh = tokenRefresher;\n this.currentToken = token ? parseToken(token) : expiredToken;\n this.refreshProactively = refreshProactively ?? false;\n\n if (this.refreshProactively) {\n this.scheduleRefresh();\n }\n }\n\n public async getToken(options?: CommunicationGetTokenOptions): Promise<AccessToken> {\n if (!this.isTokenExpiringSoon(this.currentToken)) {\n return this.currentToken;\n }\n\n if (!this.isTokenValid(this.currentToken)) {\n const updatePromise = this.updateTokenAndReschedule(options?.abortSignal);\n await updatePromise;\n }\n\n return this.currentToken;\n }\n\n public dispose(): void {\n this.disposed = true;\n this.activeTokenFetching = null;\n this.activeTokenUpdating = null;\n this.currentToken = expiredToken;\n if (this.activeTimeout) {\n clearTimeout(this.activeTimeout);\n }\n }\n\n private async updateTokenAndReschedule(abortSignal?: AbortSignalLike): Promise<void> {\n if (this.activeTokenUpdating) {\n return this.activeTokenUpdating;\n }\n this.activeTokenUpdating = this.refreshTokenAndReschedule(abortSignal);\n try {\n await this.activeTokenUpdating;\n } finally {\n this.activeTokenUpdating = null;\n }\n }\n\n private async refreshTokenAndReschedule(abortSignal?: AbortSignalLike): Promise<void> {\n const newToken = await this.refreshToken(abortSignal);\n\n if (!this.isTokenValid(newToken)) {\n throw new Error(\"The token returned from the tokenRefresher is expired.\");\n }\n\n this.currentToken = newToken;\n if (this.refreshProactively) {\n this.scheduleRefresh();\n }\n }\n\n private async refreshToken(abortSignal?: AbortSignalLike): Promise<AccessToken> {\n try {\n if (!this.activeTokenFetching) {\n this.activeTokenFetching = this.refresh(abortSignal);\n }\n return parseToken(await this.activeTokenFetching);\n } finally {\n this.activeTokenFetching = null;\n }\n }\n\n private scheduleRefresh(): void {\n if (this.disposed) {\n return;\n }\n if (this.activeTimeout) {\n clearTimeout(this.activeTimeout);\n }\n const tokenTtlInMs = this.currentToken.expiresOnTimestamp - Date.now();\n let timespanInMs = null;\n\n if (this.isTokenExpiringSoon(this.currentToken)) {\n // Schedule the next refresh for when it reaches a certain percentage of the remaining lifetime.\n timespanInMs = tokenTtlInMs * this.refreshAfterLifetimePercentage;\n } else {\n // Schedule the next refresh for when it gets in to the soon-to-expire window.\n timespanInMs = tokenTtlInMs - this.expiringSoonIntervalInMs;\n }\n\n this.activeTimeout = setTimeout(() => this.updateTokenAndReschedule(), timespanInMs);\n }\n\n private isTokenValid(token: AccessToken): boolean {\n return token && Date.now() < token.expiresOnTimestamp;\n }\n\n private isTokenExpiringSoon(token: AccessToken): boolean {\n return !token || Date.now() >= token.expiresOnTimestamp - this.expiringSoonIntervalInMs;\n }\n}\n","// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { AccessToken } from \"@azure/core-auth\";\nimport { TokenCredential } from \"./communicationTokenCredential\";\n\n/**\n * StaticTokenCredential\n */\nexport class StaticTokenCredential implements TokenCredential {\n constructor(private readonly token: AccessToken) {}\n\n public async getToken(): Promise<AccessToken> {\n return this.token;\n }\n\n public dispose(): void {\n /* intentionally empty */\n }\n}\n","// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport {\n AutoRefreshTokenCredential,\n CommunicationTokenRefreshOptions,\n} from \"./autoRefreshTokenCredential\";\nimport {\n CommunicationGetTokenOptions,\n CommunicationTokenCredential,\n TokenCredential,\n} from \"./communicationTokenCredential\";\nimport { AccessToken } from \"@azure/core-auth\";\nimport { StaticTokenCredential } from \"./staticTokenCredential\";\nimport { parseToken } from \"./tokenParser\";\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","// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { createHash, createHmac } from \"crypto\";\n\nexport const shaHash = async (content: string): Promise<string> =>\n createHash(\"sha256\").update(content).digest(\"base64\");\n\nexport const shaHMAC = async (secret: string, content: string): Promise<string> => {\n const decodedSecret = Buffer.from(secret, \"base64\");\n\n return createHmac(\"sha256\", decodedSecret).update(content).digest(\"base64\");\n};\n","// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport {\n PipelinePolicy,\n PipelineRequest,\n PipelineResponse,\n SendRequest,\n} from \"@azure/core-rest-pipeline\";\nimport { shaHMAC, shaHash } from \"./cryptoUtils\";\nimport { KeyCredential } from \"@azure/core-auth\";\nimport { isNode } from \"@azure/core-util\";\n\n/**\n * CommunicationKeyCredentialPolicy provides a means of signing requests made through\n * the SmsClient.\n */\nconst communicationAccessKeyCredentialPolicy = \"CommunicationAccessKeyCredentialPolicy\";\n\n/**\n * Creates an HTTP pipeline policy to authenticate a request using a `KeyCredential`.\n * @hidden\n *\n * @param credential - The key credential.\n */\nexport function createCommunicationAccessKeyCredentialPolicy(\n credential: KeyCredential\n): PipelinePolicy {\n return {\n name: communicationAccessKeyCredentialPolicy,\n async sendRequest(request: PipelineRequest, next: SendRequest): Promise<PipelineResponse> {\n const verb = request.method.toUpperCase();\n const utcNow = new Date().toUTCString();\n const contentHash = await shaHash(request.body?.toString() || \"\");\n const dateHeader = \"x-ms-date\";\n const signedHeaders = `${dateHeader};host;x-ms-content-sha256`;\n\n const url = new URL(request.url);\n const query = url.searchParams;\n const urlPathAndQuery = query ? `${url.pathname}?${query}` : url.pathname;\n const port = url.port;\n const hostAndPort = port ? `${url.host}:${port}` : url.host;\n\n const stringToSign = `${verb}\\n${urlPathAndQuery}\\n${utcNow};${hostAndPort};${contentHash}`;\n const signature = await shaHMAC(credential.key, stringToSign);\n\n if (isNode) {\n request.headers.set(\"Host\", hostAndPort || \"\");\n }\n\n request.headers.set(dateHeader, utcNow);\n request.headers.set(\"x-ms-content-sha256\", contentHash);\n request.headers.set(\n \"Authorization\",\n `HMAC-SHA256 SignedHeaders=${signedHeaders}&Signature=${signature}`\n );\n return next(request);\n },\n };\n}\n","// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport {\n BearerTokenAuthenticationPolicyOptions,\n PipelinePolicy,\n bearerTokenAuthenticationPolicy,\n} from \"@azure/core-rest-pipeline\";\nimport { KeyCredential, TokenCredential, isTokenCredential } from \"@azure/core-auth\";\nimport { createCommunicationAccessKeyCredentialPolicy } from \"./communicationAccessKeyCredentialPolicy\";\n/**\n * Creates a pipeline policy to authenticate request based\n * on the credential passed in.\n * @hidden\n *\n * @param credential - The KeyCredential or TokenCredential.\n */\nexport function createCommunicationAuthPolicy(\n credential: KeyCredential | TokenCredential\n): PipelinePolicy {\n if (isTokenCredential(credential)) {\n const policyOptions: BearerTokenAuthenticationPolicyOptions = {\n credential: credential,\n scopes: [\"https://communication.azure.com//.default\"],\n };\n return bearerTokenAuthenticationPolicy(policyOptions);\n } else {\n return createCommunicationAccessKeyCredentialPolicy(credential);\n }\n}\n","// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { AzureKeyCredential, KeyCredential } from \"@azure/core-auth\";\n/**\n * Represents different properties of connection string\n * using format \"/endpoint=(.*);accesskey=(.*)\".\n * @hidden\n */\nexport interface EndpointCredential {\n /**\n * The endpoint as string\n */\n endpoint: string;\n /**\n * The access key represented as a KeyCredential object\n */\n credential: KeyCredential;\n}\n\n// TODO: update when connection string format is finalized\nconst CONNECTION_STRING_REGEX = /endpoint=(.*);accesskey=(.*)/i;\n\nconst tryParseConnectionString = (s: string): EndpointCredential | undefined => {\n const match = s.match(CONNECTION_STRING_REGEX);\n if (match?.[1] && match[2]) {\n return { endpoint: match[1], credential: new AzureKeyCredential(match[2]) };\n }\n return undefined;\n};\n/**\n * Returns an EndpointCredential to easily access properties of the connection string.\n * @hidden\n *\n * @param connectionString - The connection string to parse\n * @returns Object to access the endpoint and the credentials\n */\nexport const parseConnectionString = (connectionString: string): EndpointCredential => {\n const parsedConnectionString = tryParseConnectionString(connectionString);\n if (parsedConnectionString) {\n return parsedConnectionString;\n } else {\n throw new Error(`Invalid connection string ${connectionString}`);\n }\n};\n","// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { KeyCredential, TokenCredential, isTokenCredential } from \"@azure/core-auth\";\nimport { parseConnectionString } from \"./connectionString\";\n\nconst isValidEndpoint = (host: string): boolean => {\n const url = new URL(host);\n\n return (\n !!url.protocol?.match(/^http[s]?/) &&\n url.host !== undefined &&\n url.host !== \"\" &&\n (url.pathname === undefined || url.pathname === \"\" || url.pathname === \"/\")\n );\n};\n\nconst assertValidEndpoint = (host: string): void => {\n if (!isValidEndpoint(host)) {\n throw new Error(`Invalid endpoint url ${host}`);\n }\n};\n\n/**\n * Checks whether a value is a KeyCredential.\n *\n * @param credential - The credential being checked.\n */\nexport const isKeyCredential = (credential: unknown): credential is KeyCredential => {\n const castCredential = credential as {\n key: unknown;\n getToken: unknown;\n };\n return (\n castCredential &&\n typeof castCredential.key === \"string\" &&\n castCredential.getToken === undefined\n );\n};\n\n/**\n * The URL and credential from parsing the arguments of a communication client.\n * @hidden\n */\nexport type UrlWithCredential = {\n url: string;\n credential: TokenCredential | KeyCredential;\n};\n\n/**\n * Parses arguments passed to a communication client.\n * @hidden\n */\nexport const parseClientArguments = (\n connectionStringOrUrl: string,\n credentialOrOptions?: unknown\n): UrlWithCredential => {\n if (isKeyCredential(credentialOrOptions) || isTokenCredential(credentialOrOptions)) {\n assertValidEndpoint(connectionStringOrUrl);\n return { url: connectionStringOrUrl, credential: credentialOrOptions };\n } else {\n const { endpoint: host, credential } = parseConnectionString(connectionStringOrUrl);\n assertValidEndpoint(host);\n return { url: host, credential };\n }\n};\n","// 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 | 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 * 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 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 | 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 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 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 \"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\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) return { kind: \"unknown\", id: rawId };\n\n const prefix = `${segments[0]}:${segments[1]}:`;\n const suffix = rawId.substring(prefix.length);\n\n switch (prefix) {\n case \"8:teamsvisitor:\":\n return { kind: \"microsoftTeamsUser\", microsoftTeamsUserId: suffix, isAnonymous: true };\n case \"8:orgid:\":\n return {\n kind: \"microsoftTeamsUser\",\n microsoftTeamsUserId: suffix,\n isAnonymous: false,\n cloud: \"public\",\n };\n case \"8:dod:\":\n return {\n kind: \"microsoftTeamsUser\",\n microsoftTeamsUserId: suffix,\n isAnonymous: false,\n cloud: \"dod\",\n };\n case \"8:gcch:\":\n return {\n kind: \"microsoftTeamsUser\",\n microsoftTeamsUserId: suffix,\n isAnonymous: false,\n cloud: \"gcch\",\n };\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 }\n return { kind: \"unknown\", id: rawId };\n};\n","// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport {\n CommunicationIdentifier,\n CommunicationIdentifierKind,\n getIdentifierKind,\n getIdentifierRawId,\n} from \"./identifierModels\";\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 * 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\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 * 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 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.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 \"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\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, phoneNumber } = serializedIdentifier;\n if (communicationUser) {\n return {\n kind: \"communicationUser\",\n communicationUserId: assertNotNullOrUndefined({ communicationUser }, \"id\"),\n };\n }\n if (phoneNumber) {\n return {\n kind: \"phoneNumber\",\n phoneNumber: assertNotNullOrUndefined({ phoneNumber }, \"value\"),\n rawId: assertNotNullOrUndefined({ phoneNumber: serializedIdentifier }, \"rawId\"),\n };\n }\n if (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 return {\n kind: \"unknown\",\n id: assertNotNullOrUndefined({ unknown: serializedIdentifier }, \"rawId\"),\n };\n};\n"],"names":["jwtDecode","createHash","createHmac","isNode","isTokenCredential","bearerTokenAuthenticationPolicy","AzureKeyCredential"],"mappings":";;;;;;;;;;;;;;AAAA;AAUO,MAAM,UAAU,GAAG,CAAC,KAAa,KAAiB;IACvD,MAAM,EAAE,GAAG,EAAE,GAAGA,6BAAS,CAAW,KAAK,CAAC,CAAC;IAC3C,OAAO;QACL,KAAK;QACL,kBAAkB,EAAE,GAAG,GAAG,IAAI;KAC/B,CAAC;AACJ,CAAC;;AChBD;AA8BA,MAAM,YAAY,GAAG,EAAE,KAAK,EAAE,EAAE,EAAE,kBAAkB,EAAE,CAAC,EAAE,EAAE,CAAC;AAC5D,MAAM,WAAW,GAAG,CAAC,OAAe,KAAa,OAAO,GAAG,IAAI,GAAG,EAAE,CAAC;AACrE,MAAM,2BAA2B,GAAG,WAAW,CAAC,EAAE,CAAC,CAAC;AACpD,MAAM,qCAAqC,GAAG,GAAG,CAAC;MAErC,0BAA0B,CAAA;AAYrC,IAAA,WAAA,CAAY,WAA6C,EAAA;QATxC,IAAwB,CAAA,wBAAA,GAAW,2BAA2B,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,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,WAAW,EAAE,GAAG,oBAAoB,CAAC;AACpF,IAAA,IAAI,iBAAiB,EAAE;QACrB,OAAO;AACL,YAAA,IAAI,EAAE,mBAAmB;YACzB,mBAAmB,EAAE,wBAAwB,CAAC,EAAE,iBAAiB,EAAE,EAAE,IAAI,CAAC;SAC3E,CAAC;AACH,KAAA;AACD,IAAA,IAAI,WAAW,EAAE;QACf,OAAO;AACL,YAAA,IAAI,EAAE,aAAa;YACnB,WAAW,EAAE,wBAAwB,CAAC,EAAE,WAAW,EAAE,EAAE,OAAO,CAAC;YAC/D,KAAK,EAAE,wBAAwB,CAAC,EAAE,WAAW,EAAE,oBAAoB,EAAE,EAAE,OAAO,CAAC;SAChF,CAAC;AACH,KAAA;AACD,IAAA,IAAI,kBAAkB,EAAE;QACtB,OAAO;AACL,YAAA,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;AACH,KAAA;IACD,OAAO;AACL,QAAA,IAAI,EAAE,SAAS;QACf,EAAE,EAAE,wBAAwB,CAAC,EAAE,OAAO,EAAE,oBAAoB,EAAE,EAAE,OAAO,CAAC;KACzE,CAAC;AACJ;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.js","sources":["../src/tokenParser.ts","../src/autoRefreshTokenCredential.ts","../src/staticTokenCredential.ts","../src/azureCommunicationTokenCredential.ts","../src/credential/cryptoUtils.ts","../src/credential/communicationAccessKeyCredentialPolicy.ts","../src/credential/communicationAuthPolicy.ts","../src/credential/connectionString.ts","../src/credential/clientArguments.ts","../src/identifierModels.ts","../src/identifierModelSerializer.ts"],"sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { AccessToken } from \"@azure/core-auth\";\nimport jwtDecode from \"jwt-decode\";\n\ninterface JwtToken {\n exp: number;\n}\n\nexport const parseToken = (token: string): AccessToken => {\n const { exp } = jwtDecode<JwtToken>(token);\n return {\n token,\n expiresOnTimestamp: exp * 1000,\n };\n};\n","// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { CommunicationGetTokenOptions, TokenCredential } from \"./communicationTokenCredential\";\nimport { AbortSignalLike } from \"@azure/abort-controller\";\nimport { AccessToken } from \"@azure/core-auth\";\nimport { parseToken } from \"./tokenParser\";\n\n/**\n * Options for auto-refreshing a Communication Token credential.\n */\nexport interface CommunicationTokenRefreshOptions {\n /**\n * Callback function that returns a string JWT token acquired from the Communication Identity API.\n * The returned token must be valid (expiration date must be in the future).\n */\n tokenRefresher: (abortSignal?: AbortSignalLike) => Promise<string>;\n\n /**\n * Optional token to initialize.\n */\n token?: string;\n\n /**\n * Indicates whether the token should be proactively renewed prior to expiry or only renew on demand.\n * By default false.\n */\n refreshProactively?: boolean;\n}\n\nconst expiredToken = { token: \"\", expiresOnTimestamp: -10 };\nconst minutesToMs = (minutes: number): number => minutes * 1000 * 60;\nconst defaultExpiringSoonInterval = minutesToMs(10);\nconst defaultRefreshAfterLifetimePercentage = 0.5;\n\nexport class AutoRefreshTokenCredential implements TokenCredential {\n private readonly refresh: (abortSignal?: AbortSignalLike) => Promise<string>;\n private readonly refreshProactively: boolean;\n private readonly expiringSoonIntervalInMs: number = defaultExpiringSoonInterval;\n private readonly refreshAfterLifetimePercentage = defaultRefreshAfterLifetimePercentage;\n\n private currentToken: AccessToken;\n private activeTimeout: ReturnType<typeof setTimeout> | undefined;\n private activeTokenFetching: Promise<string> | null = null;\n private activeTokenUpdating: Promise<void> | null = null;\n private disposed = false;\n\n constructor(refreshArgs: CommunicationTokenRefreshOptions) {\n const { tokenRefresher, token, refreshProactively } = refreshArgs;\n\n this.refresh = tokenRefresher;\n this.currentToken = token ? parseToken(token) : expiredToken;\n this.refreshProactively = refreshProactively ?? false;\n\n if (this.refreshProactively) {\n this.scheduleRefresh();\n }\n }\n\n public async getToken(options?: CommunicationGetTokenOptions): Promise<AccessToken> {\n if (!this.isTokenExpiringSoon(this.currentToken)) {\n return this.currentToken;\n }\n\n if (!this.isTokenValid(this.currentToken)) {\n const updatePromise = this.updateTokenAndReschedule(options?.abortSignal);\n await updatePromise;\n }\n\n return this.currentToken;\n }\n\n public dispose(): void {\n this.disposed = true;\n this.activeTokenFetching = null;\n this.activeTokenUpdating = null;\n this.currentToken = expiredToken;\n if (this.activeTimeout) {\n clearTimeout(this.activeTimeout);\n }\n }\n\n private async updateTokenAndReschedule(abortSignal?: AbortSignalLike): Promise<void> {\n if (this.activeTokenUpdating) {\n return this.activeTokenUpdating;\n }\n this.activeTokenUpdating = this.refreshTokenAndReschedule(abortSignal);\n try {\n await this.activeTokenUpdating;\n } finally {\n this.activeTokenUpdating = null;\n }\n }\n\n private async refreshTokenAndReschedule(abortSignal?: AbortSignalLike): Promise<void> {\n const newToken = await this.refreshToken(abortSignal);\n\n if (!this.isTokenValid(newToken)) {\n throw new Error(\"The token returned from the tokenRefresher is expired.\");\n }\n\n this.currentToken = newToken;\n if (this.refreshProactively) {\n this.scheduleRefresh();\n }\n }\n\n private async refreshToken(abortSignal?: AbortSignalLike): Promise<AccessToken> {\n try {\n if (!this.activeTokenFetching) {\n this.activeTokenFetching = this.refresh(abortSignal);\n }\n return parseToken(await this.activeTokenFetching);\n } finally {\n this.activeTokenFetching = null;\n }\n }\n\n private scheduleRefresh(): void {\n if (this.disposed) {\n return;\n }\n if (this.activeTimeout) {\n clearTimeout(this.activeTimeout);\n }\n const tokenTtlInMs = this.currentToken.expiresOnTimestamp - Date.now();\n let timespanInMs = null;\n\n if (this.isTokenExpiringSoon(this.currentToken)) {\n // Schedule the next refresh for when it reaches a certain percentage of the remaining lifetime.\n timespanInMs = tokenTtlInMs * this.refreshAfterLifetimePercentage;\n } else {\n // Schedule the next refresh for when it gets in to the soon-to-expire window.\n timespanInMs = tokenTtlInMs - this.expiringSoonIntervalInMs;\n }\n\n this.activeTimeout = setTimeout(() => this.updateTokenAndReschedule(), timespanInMs);\n }\n\n private isTokenValid(token: AccessToken): boolean {\n return token && Date.now() < token.expiresOnTimestamp;\n }\n\n private isTokenExpiringSoon(token: AccessToken): boolean {\n return !token || Date.now() >= token.expiresOnTimestamp - this.expiringSoonIntervalInMs;\n }\n}\n","// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { AccessToken } from \"@azure/core-auth\";\nimport { TokenCredential } from \"./communicationTokenCredential\";\n\n/**\n * StaticTokenCredential\n */\nexport class StaticTokenCredential implements TokenCredential {\n constructor(private readonly token: AccessToken) {}\n\n public async getToken(): Promise<AccessToken> {\n return this.token;\n }\n\n public dispose(): void {\n /* intentionally empty */\n }\n}\n","// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport {\n AutoRefreshTokenCredential,\n CommunicationTokenRefreshOptions,\n} from \"./autoRefreshTokenCredential\";\nimport {\n CommunicationGetTokenOptions,\n CommunicationTokenCredential,\n TokenCredential,\n} from \"./communicationTokenCredential\";\nimport { AccessToken } from \"@azure/core-auth\";\nimport { StaticTokenCredential } from \"./staticTokenCredential\";\nimport { parseToken } from \"./tokenParser\";\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","// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { createHash, createHmac } from \"crypto\";\n\nexport const shaHash = async (content: string): Promise<string> =>\n createHash(\"sha256\").update(content).digest(\"base64\");\n\nexport const shaHMAC = async (secret: string, content: string): Promise<string> => {\n const decodedSecret = Buffer.from(secret, \"base64\");\n\n return createHmac(\"sha256\", decodedSecret).update(content).digest(\"base64\");\n};\n","// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport {\n PipelinePolicy,\n PipelineRequest,\n PipelineResponse,\n SendRequest,\n} from \"@azure/core-rest-pipeline\";\nimport { shaHMAC, shaHash } from \"./cryptoUtils\";\nimport { KeyCredential } from \"@azure/core-auth\";\nimport { isNode } from \"@azure/core-util\";\n\n/**\n * CommunicationKeyCredentialPolicy provides a means of signing requests made through\n * the SmsClient.\n */\nconst communicationAccessKeyCredentialPolicy = \"CommunicationAccessKeyCredentialPolicy\";\n\n/**\n * Creates an HTTP pipeline policy to authenticate a request using a `KeyCredential`.\n * @hidden\n *\n * @param credential - The key credential.\n */\nexport function createCommunicationAccessKeyCredentialPolicy(\n credential: KeyCredential\n): PipelinePolicy {\n return {\n name: communicationAccessKeyCredentialPolicy,\n async sendRequest(request: PipelineRequest, next: SendRequest): Promise<PipelineResponse> {\n const verb = request.method.toUpperCase();\n const utcNow = new Date().toUTCString();\n const contentHash = await shaHash(request.body?.toString() || \"\");\n const dateHeader = \"x-ms-date\";\n const signedHeaders = `${dateHeader};host;x-ms-content-sha256`;\n\n const url = new URL(request.url);\n const query = url.searchParams;\n const urlPathAndQuery = query ? `${url.pathname}?${query}` : url.pathname;\n const port = url.port;\n const hostAndPort = port ? `${url.host}:${port}` : url.host;\n\n const stringToSign = `${verb}\\n${urlPathAndQuery}\\n${utcNow};${hostAndPort};${contentHash}`;\n const signature = await shaHMAC(credential.key, stringToSign);\n\n if (isNode) {\n request.headers.set(\"Host\", hostAndPort || \"\");\n }\n\n request.headers.set(dateHeader, utcNow);\n request.headers.set(\"x-ms-content-sha256\", contentHash);\n request.headers.set(\n \"Authorization\",\n `HMAC-SHA256 SignedHeaders=${signedHeaders}&Signature=${signature}`\n );\n return next(request);\n },\n };\n}\n","// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport {\n BearerTokenAuthenticationPolicyOptions,\n PipelinePolicy,\n bearerTokenAuthenticationPolicy,\n} from \"@azure/core-rest-pipeline\";\nimport { KeyCredential, TokenCredential, isTokenCredential } from \"@azure/core-auth\";\nimport { createCommunicationAccessKeyCredentialPolicy } from \"./communicationAccessKeyCredentialPolicy\";\n/**\n * Creates a pipeline policy to authenticate request based\n * on the credential passed in.\n * @hidden\n *\n * @param credential - The KeyCredential or TokenCredential.\n */\nexport function createCommunicationAuthPolicy(\n credential: KeyCredential | TokenCredential\n): PipelinePolicy {\n if (isTokenCredential(credential)) {\n const policyOptions: BearerTokenAuthenticationPolicyOptions = {\n credential: credential,\n scopes: [\"https://communication.azure.com//.default\"],\n };\n return bearerTokenAuthenticationPolicy(policyOptions);\n } else {\n return createCommunicationAccessKeyCredentialPolicy(credential);\n }\n}\n","// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { AzureKeyCredential, KeyCredential } from \"@azure/core-auth\";\n/**\n * Represents different properties of connection string\n * using format \"/endpoint=(.*);accesskey=(.*)\".\n * @hidden\n */\nexport interface EndpointCredential {\n /**\n * The endpoint as string\n */\n endpoint: string;\n /**\n * The access key represented as a KeyCredential object\n */\n credential: KeyCredential;\n}\n\n// TODO: update when connection string format is finalized\nconst CONNECTION_STRING_REGEX = /endpoint=(.*);accesskey=(.*)/i;\n\nconst tryParseConnectionString = (s: string): EndpointCredential | undefined => {\n const match = s.match(CONNECTION_STRING_REGEX);\n if (match?.[1] && match[2]) {\n return { endpoint: match[1], credential: new AzureKeyCredential(match[2]) };\n }\n return undefined;\n};\n/**\n * Returns an EndpointCredential to easily access properties of the connection string.\n * @hidden\n *\n * @param connectionString - The connection string to parse\n * @returns Object to access the endpoint and the credentials\n */\nexport const parseConnectionString = (connectionString: string): EndpointCredential => {\n const parsedConnectionString = tryParseConnectionString(connectionString);\n if (parsedConnectionString) {\n return parsedConnectionString;\n } else {\n throw new Error(`Invalid connection string ${connectionString}`);\n }\n};\n","// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { KeyCredential, TokenCredential, isTokenCredential } from \"@azure/core-auth\";\nimport { parseConnectionString } from \"./connectionString\";\n\nconst isValidEndpoint = (host: string): boolean => {\n const url = new URL(host);\n\n return (\n !!url.protocol?.match(/^http[s]?/) &&\n url.host !== undefined &&\n url.host !== \"\" &&\n (url.pathname === undefined || url.pathname === \"\" || url.pathname === \"/\")\n );\n};\n\nconst assertValidEndpoint = (host: string): void => {\n if (!isValidEndpoint(host)) {\n throw new Error(`Invalid endpoint url ${host}`);\n }\n};\n\n/**\n * Checks whether a value is a KeyCredential.\n *\n * @param credential - The credential being checked.\n */\nexport const isKeyCredential = (credential: unknown): credential is KeyCredential => {\n const castCredential = credential as {\n key: unknown;\n getToken: unknown;\n };\n return (\n castCredential &&\n typeof castCredential.key === \"string\" &&\n castCredential.getToken === undefined\n );\n};\n\n/**\n * The URL and credential from parsing the arguments of a communication client.\n * @hidden\n */\nexport type UrlWithCredential = {\n url: string;\n credential: TokenCredential | KeyCredential;\n};\n\n/**\n * Parses arguments passed to a communication client.\n * @hidden\n */\nexport const parseClientArguments = (\n connectionStringOrUrl: string,\n credentialOrOptions?: unknown\n): UrlWithCredential => {\n if (isKeyCredential(credentialOrOptions) || isTokenCredential(credentialOrOptions)) {\n assertValidEndpoint(connectionStringOrUrl);\n return { url: connectionStringOrUrl, credential: credentialOrOptions };\n } else {\n const { endpoint: host, credential } = parseConnectionString(connectionStringOrUrl);\n assertValidEndpoint(host);\n return { url: host, credential };\n }\n};\n","// 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 | 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 * 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 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 | 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 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 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 \"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\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) return { kind: \"unknown\", id: rawId };\n\n const prefix = `${segments[0]}:${segments[1]}:`;\n const suffix = rawId.substring(prefix.length);\n\n switch (prefix) {\n case \"8:teamsvisitor:\":\n return { kind: \"microsoftTeamsUser\", microsoftTeamsUserId: suffix, isAnonymous: true };\n case \"8:orgid:\":\n return {\n kind: \"microsoftTeamsUser\",\n microsoftTeamsUserId: suffix,\n isAnonymous: false,\n cloud: \"public\",\n };\n case \"8:dod:\":\n return {\n kind: \"microsoftTeamsUser\",\n microsoftTeamsUserId: suffix,\n isAnonymous: false,\n cloud: \"dod\",\n };\n case \"8:gcch:\":\n return {\n kind: \"microsoftTeamsUser\",\n microsoftTeamsUserId: suffix,\n isAnonymous: false,\n cloud: \"gcch\",\n };\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 }\n return { kind: \"unknown\", id: rawId };\n};\n","// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport {\n CommunicationIdentifier,\n CommunicationIdentifierKind,\n getIdentifierKind,\n getIdentifierRawId,\n} from \"./identifierModels\";\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\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 * 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 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.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 \"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 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, phoneNumber } = 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 return {\n kind: \"unknown\",\n id: assertNotNullOrUndefined({ unknown: serializedIdentifier }, \"rawId\"),\n };\n};\n"],"names":["jwtDecode","createHash","createHmac","isNode","isTokenCredential","bearerTokenAuthenticationPolicy","AzureKeyCredential"],"mappings":";;;;;;;;;;;;;;AAAA;AAUO,MAAM,UAAU,GAAG,CAAC,KAAa,KAAiB;IACvD,MAAM,EAAE,GAAG,EAAE,GAAGA,6BAAS,CAAW,KAAK,CAAC,CAAC;IAC3C,OAAO;QACL,KAAK;QACL,kBAAkB,EAAE,GAAG,GAAG,IAAI;KAC/B,CAAC;AACJ,CAAC;;AChBD;AA8BA,MAAM,YAAY,GAAG,EAAE,KAAK,EAAE,EAAE,EAAE,kBAAkB,EAAE,CAAC,EAAE,EAAE,CAAC;AAC5D,MAAM,WAAW,GAAG,CAAC,OAAe,KAAa,OAAO,GAAG,IAAI,GAAG,EAAE,CAAC;AACrE,MAAM,2BAA2B,GAAG,WAAW,CAAC,EAAE,CAAC,CAAC;AACpD,MAAM,qCAAqC,GAAG,GAAG,CAAC;MAErC,0BAA0B,CAAA;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oB,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;AACH,KAAA;IACD,OAAO;AACL,QAAA,IAAI,EAAE,SAAS;QACf,EAAE,EAAE,wBAAwB,CAAC,EAAE,OAAO,EAAE,oBAAoB,EAAE,EAAE,OAAO,CAAC;KACzE,CAAC;AACJ;;;;;;;;;;;;;;;;;;"}
@@ -60,28 +60,42 @@ export const serializeCommunicationIdentifier = (identifier) => {
60
60
  throw new Error(`Can't serialize an identifier with kind ${identifierKind.kind}`);
61
61
  }
62
62
  };
63
+ const getKind = (serializedIdentifier) => {
64
+ if (serializedIdentifier.communicationUser) {
65
+ return "communicationUser";
66
+ }
67
+ if (serializedIdentifier.phoneNumber) {
68
+ return "phoneNumber";
69
+ }
70
+ if (serializedIdentifier.microsoftTeamsUser) {
71
+ return "microsoftTeamsUser";
72
+ }
73
+ return "unknown";
74
+ };
63
75
  /**
64
76
  * @hidden
65
77
  * Translates the serialized format of a communication identifier to CommunicationIdentifier.
66
78
  * @param serializedIdentifier - The SerializedCommunicationIdentifier to be deserialized.
67
79
  */
68
80
  export const deserializeCommunicationIdentifier = (serializedIdentifier) => {
81
+ var _a;
69
82
  assertMaximumOneNestedModel(serializedIdentifier);
70
83
  const { communicationUser, microsoftTeamsUser, phoneNumber } = serializedIdentifier;
71
- if (communicationUser) {
84
+ const kind = (_a = serializedIdentifier.kind) !== null && _a !== void 0 ? _a : getKind(serializedIdentifier);
85
+ if (kind === "communicationUser" && communicationUser) {
72
86
  return {
73
87
  kind: "communicationUser",
74
88
  communicationUserId: assertNotNullOrUndefined({ communicationUser }, "id"),
75
89
  };
76
90
  }
77
- if (phoneNumber) {
91
+ if (kind === "phoneNumber" && phoneNumber) {
78
92
  return {
79
93
  kind: "phoneNumber",
80
94
  phoneNumber: assertNotNullOrUndefined({ phoneNumber }, "value"),
81
95
  rawId: assertNotNullOrUndefined({ phoneNumber: serializedIdentifier }, "rawId"),
82
96
  };
83
97
  }
84
- if (microsoftTeamsUser) {
98
+ if (kind === "microsoftTeamsUser" && microsoftTeamsUser) {
85
99
  return {
86
100
  kind: "microsoftTeamsUser",
87
101
  microsoftTeamsUserId: assertNotNullOrUndefined({ microsoftTeamsUser }, "userId"),
@@ -1 +1 @@
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,oBAAoB,CAAC;AAwE5B,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;QAClB,OAAO,MAAM,CAAC,IAAI,CAAC,CAAC;KACrB;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;QAC9C,iBAAiB,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC;KAC7C;IACD,IAAI,UAAU,CAAC,kBAAkB,KAAK,SAAS,EAAE;QAC/C,iBAAiB,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ed under the MIT license.\n\nimport {\n CommunicationIdentifier,\n CommunicationIdentifierKind,\n getIdentifierKind,\n getIdentifierRawId,\n} from \"./identifierModels\";\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 * 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\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 * 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 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.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 \"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\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, phoneNumber } = serializedIdentifier;\n if (communicationUser) {\n return {\n kind: \"communicationUser\",\n communicationUserId: assertNotNullOrUndefined({ communicationUser }, \"id\"),\n };\n }\n if (phoneNumber) {\n return {\n kind: \"phoneNumber\",\n phoneNumber: assertNotNullOrUndefined({ phoneNumber }, \"value\"),\n rawId: assertNotNullOrUndefined({ phoneNumber: serializedIdentifier }, \"rawId\"),\n };\n }\n if (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 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,oBAAoB,CAAC;AA4E5B,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;QAClB,OAAO,MAAM,CAAC,IAAI,CAAC,CAAC;KACrB;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,C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AAE,WAAW,EAAE,oBAAoB,EAAE,EAAE,OAAO,CAAC;SAChF,CAAC;KACH;IACD,IAAI,IAAI,KAAK,oBAAoB,IAAI,kBAAkB,EAAE;QACvD,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;KACH;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 CommunicationIdentifier,\n CommunicationIdentifierKind,\n getIdentifierKind,\n getIdentifierRawId,\n} from \"./identifierModels\";\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\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 * 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 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.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 \"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 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, phoneNumber } = 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 return {\n kind: \"unknown\",\n id: assertNotNullOrUndefined({ unknown: serializedIdentifier }, \"rawId\"),\n };\n};\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@azure/communication-common",
3
- "version": "2.1.1-alpha.20221020.2",
3
+ "version": "2.2.0",
4
4
  "description": "Common package for Azure Communication services.",
5
5
  "sdk-type": "client",
6
6
  "main": "dist/index.js",
@@ -72,8 +72,8 @@
72
72
  "tslib": "^2.2.0"
73
73
  },
74
74
  "devDependencies": {
75
- "@azure/eslint-plugin-azure-sdk": ">=3.0.0-alpha <3.0.0-alphb",
76
- "@azure/dev-tool": ">=1.0.0-alpha <1.0.0-alphb",
75
+ "@azure/eslint-plugin-azure-sdk": "^3.0.0",
76
+ "@azure/dev-tool": "^1.0.0",
77
77
  "@microsoft/api-extractor": "^7.31.1",
78
78
  "@types/chai-as-promised": "^7.1.0",
79
79
  "@types/chai": "^4.1.6",
@@ -293,6 +293,10 @@ export declare type SerializedCommunicationCloudEnvironment = "public" | "dod" |
293
293
  * 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.
294
294
  */
295
295
  export declare interface SerializedCommunicationIdentifier {
296
+ /**
297
+ * Kind of the identifier, optional.
298
+ */
299
+ kind?: string;
296
300
  /**
297
301
  * Raw Id of the identifier. Optional in requests, required in responses.
298
302
  */