@azure/communication-common
Advanced tools
Comparing version 1.0.0-beta.3 to 1.0.0-beta.4
# Release History | ||
## 1.0.0-beta.4 (2021-01-25) | ||
### Added | ||
- Added `MicrosoftTeamsUserIdentifier` and `isMicrosoftTeamsUserIdentifier`. | ||
- Added optional `id` property to communication identifiers. | ||
### Breaking Changes | ||
- Changed identifier `kind` property to use lowerCamelCase. | ||
- Renamed `CommunicationUserCredential` to `CommunicationTokenCredential`. | ||
- Renamed `RefreshOptions` to `CommunicationTokenRefreshOptions`. | ||
- Renamed `Identifier` to `CommunicationIdentifier`. | ||
- Renamed `IdentifierKind` to `CommunicationIdentifierKind`. | ||
- Renamed `PhoneNumber` to `PhoneNumberIdentifier`. | ||
- Renamed `isPhoneNumber` to `isPhoneNumberIdentifier`. | ||
- Renamed `CommunicationUser` to `CommunicationUserIdentifier`. | ||
- Renamed `isCommunicationUser` to `isCommunicationUserIdentifier`. | ||
- Renamed `CallingApplication` to `CallingApplicationIdentifier`. | ||
- Renamed `isCallingApplication` to `isCallingApplicationIdentifier`. | ||
## 1.0.0-beta.3 (2020-11-16) | ||
@@ -4,0 +25,0 @@ |
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
import { isTokenCredential } from "@azure/core-auth"; | ||
import { URLBuilder } from "@azure/core-http"; | ||
@@ -33,3 +34,3 @@ import { parseConnectionString } from "./connectionString"; | ||
export const parseClientArguments = (connectionStringOrUrl, credentialOrOptions) => { | ||
if (isKeyCredential(credentialOrOptions)) { | ||
if (isKeyCredential(credentialOrOptions) || isTokenCredential(credentialOrOptions)) { | ||
assertValidEndpoint(connectionStringOrUrl); | ||
@@ -36,0 +37,0 @@ return { url: connectionStringOrUrl, credential: credentialOrOptions }; |
@@ -13,2 +13,8 @@ // Copyright (c) Microsoft Corporation. | ||
}; | ||
/** | ||
* Returns an EndpointCredential to easily access properties of the connection string | ||
* | ||
* @param {string} connectionString The connection string to parse | ||
* @returns {EndpointCredential} Object to access the endpoint and the credenials | ||
*/ | ||
export const parseConnectionString = (connectionString) => { | ||
@@ -15,0 +21,0 @@ const parsedConnectionString = tryParseConnectionString(connectionString); |
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
export * from "./communicationAccessKeyCredentialPolicy"; | ||
export * from "./communicationAuthPolicy"; | ||
export * from "./clientArguments"; | ||
export * from "./connectionString"; | ||
//# sourceMappingURL=index.js.map |
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
/** | ||
* Tests an Identifier to determine whether it implements CommunicationUser. | ||
* Tests an Identifier to determine whether it implements CommunicationUserIdentifier. | ||
* | ||
* @param identifier The assumed CommunicationUser to be tested. | ||
* @param identifier The assumed CommunicationUserIdentifier to be tested. | ||
*/ | ||
export const isCommunicationUser = (identifier) => { | ||
export const isCommunicationUserIdentifier = (identifier) => { | ||
return typeof identifier.communicationUserId === "string"; | ||
}; | ||
/** | ||
* Tests an Identifier to determine whether it implements PhoneNumber. | ||
* Tests an Identifier to determine whether it implements PhoneNumberIdentifier. | ||
* | ||
* @param identifier The assumed PhoneNumber to be tested. | ||
* @param identifier The assumed PhoneNumberIdentifier to be tested. | ||
*/ | ||
export const isPhoneNumber = (identifier) => { | ||
export const isPhoneNumberIdentifier = (identifier) => { | ||
return typeof identifier.phoneNumber === "string"; | ||
}; | ||
/** | ||
* Tests an Identifier to determine whether it implements CallingApplication. | ||
* Tests an Identifier to determine whether it implements MicrosoftTeamsUserIdentifier. | ||
* | ||
* @param identifier The assumed CallingApplication to be tested. | ||
* @param identifier The assumed available to be tested. | ||
*/ | ||
export const isCallingApplication = (identifier) => { | ||
export const isMicrosoftTeamsUserIdentifier = (identifier) => { | ||
return typeof identifier.microsoftTeamsUserId === "string"; | ||
}; | ||
/** | ||
* Tests an Identifier to determine whether it implements MicrosoftTeamsUserIdentifier. | ||
* | ||
* @param identifier The assumed CallingApplicationIdentifier to be tested. | ||
*/ | ||
export const isCallingApplicationIdentifier = (identifier) => { | ||
return typeof identifier.callingApplicationId === "string"; | ||
@@ -36,3 +44,3 @@ }; | ||
/** | ||
* Returns the IdentifierKind for a given Identifier. Returns undefined if the kind couldn't be inferred. | ||
* Returns the CommunicationIdentifierKind for a given CommunicationIdentifier. Returns undefined if the kind couldn't be inferred. | ||
* | ||
@@ -42,13 +50,16 @@ * @param identifier The identifier whose kind is to be inferred. | ||
export const getIdentifierKind = (identifier) => { | ||
if (isCommunicationUser(identifier)) { | ||
return Object.assign(Object.assign({}, identifier), { kind: "CommunicationUser" }); | ||
if (isCommunicationUserIdentifier(identifier)) { | ||
return Object.assign(Object.assign({}, identifier), { kind: "communicationUser" }); | ||
} | ||
if (isPhoneNumber(identifier)) { | ||
return Object.assign(Object.assign({}, identifier), { kind: "PhoneNumber" }); | ||
if (isPhoneNumberIdentifier(identifier)) { | ||
return Object.assign(Object.assign({}, identifier), { kind: "phoneNumber" }); | ||
} | ||
if (isCallingApplication(identifier)) { | ||
return Object.assign(Object.assign({}, identifier), { kind: "CallingApplication" }); | ||
if (isCallingApplicationIdentifier(identifier)) { | ||
return Object.assign(Object.assign({}, identifier), { kind: "callingApplication" }); | ||
} | ||
return Object.assign(Object.assign({}, identifier), { kind: "Unknown" }); | ||
if (isMicrosoftTeamsUserIdentifier(identifier)) { | ||
return Object.assign(Object.assign({}, identifier), { kind: "microsoftTeamsUser" }); | ||
} | ||
return Object.assign(Object.assign({}, identifier), { kind: "unknown" }); | ||
}; | ||
//# sourceMappingURL=identifierModels.js.map |
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
export { AzureCommunicationUserCredential } from "./communicationUserCredential"; | ||
export { AzureCommunicationTokenCredential } from "./communicationTokenCredential"; | ||
export * from "./credential"; | ||
export * from "./identifierModels"; | ||
export * from "./identifierModelSerializer"; | ||
//# sourceMappingURL=index.js.map |
@@ -44,3 +44,3 @@ 'use strict'; | ||
const defaultRefreshingInterval = minutesToMs(10); | ||
class AutoRefreshUserCredential { | ||
class AutoRefreshTokenCredential { | ||
constructor(refreshArgs) { | ||
@@ -51,5 +51,5 @@ this.refreshingIntervalInMs = defaultRefreshingInterval; | ||
this.disposed = false; | ||
const { tokenRefresher, initialToken, refreshProactively } = refreshArgs; | ||
const { tokenRefresher, token, refreshProactively } = refreshArgs; | ||
this.refresh = tokenRefresher; | ||
this.currentToken = initialToken ? parseToken(initialToken) : expiredToken; | ||
this.currentToken = token ? parseToken(token) : expiredToken; | ||
this.refreshProactively = refreshProactively !== null && refreshProactively !== void 0 ? refreshProactively : false; | ||
@@ -137,12 +137,12 @@ if (this.refreshProactively) { | ||
/** | ||
* The CommunicationUserCredential implementation with support for proactive token refresh. | ||
* The CommunicationTokenCredential implementation with support for proactive token refresh. | ||
*/ | ||
class AzureCommunicationUserCredential { | ||
class AzureCommunicationTokenCredential { | ||
constructor(tokenOrRefreshOptions) { | ||
this.disposed = false; | ||
if (typeof tokenOrRefreshOptions === "string") { | ||
this.userCredential = new StaticTokenCredential(parseToken(tokenOrRefreshOptions)); | ||
this.tokenCredential = new StaticTokenCredential(parseToken(tokenOrRefreshOptions)); | ||
} | ||
else { | ||
this.userCredential = new AutoRefreshUserCredential(tokenOrRefreshOptions); | ||
this.tokenCredential = new AutoRefreshTokenCredential(tokenOrRefreshOptions); | ||
} | ||
@@ -157,3 +157,3 @@ } | ||
this.throwIfDisposed(); | ||
const token = yield this.userCredential.getToken(abortSignal); | ||
const token = yield this.tokenCredential.getToken(abortSignal); | ||
this.throwIfDisposed(); | ||
@@ -164,7 +164,7 @@ return token; | ||
/** | ||
* Disposes the CommunicationUserCredential and cancels any internal auto-refresh operation. | ||
* Disposes the CommunicationTokenCredential and cancels any internal auto-refresh operation. | ||
*/ | ||
dispose() { | ||
this.disposed = true; | ||
this.userCredential.dispose(); | ||
this.tokenCredential.dispose(); | ||
} | ||
@@ -262,2 +262,17 @@ throwIfDisposed() { | ||
/** | ||
* Creates a pipeline policy to authenticate request based | ||
* on the credential passed in | ||
* | ||
* @param {KeyCredential | TokenCredential} credential The key credential | ||
*/ | ||
const createCommunicationAuthPolicy = (credential) => { | ||
if (coreAuth.isTokenCredential(credential)) { | ||
return coreHttp.bearerTokenAuthenticationPolicy(credential, "https://communication.azure.com//.default"); | ||
} | ||
else { | ||
return createCommunicationAccessKeyCredentialPolicy(credential); | ||
} | ||
}; | ||
// Copyright (c) Microsoft Corporation. | ||
@@ -273,2 +288,8 @@ // TODO: update when connection string format is finalized | ||
}; | ||
/** | ||
* Returns an EndpointCredential to easily access properties of the connection string | ||
* | ||
* @param {string} connectionString The connection string to parse | ||
* @returns {EndpointCredential} Object to access the endpoint and the credenials | ||
*/ | ||
const parseConnectionString = (connectionString) => { | ||
@@ -313,3 +334,3 @@ const parsedConnectionString = tryParseConnectionString(connectionString); | ||
const parseClientArguments = (connectionStringOrUrl, credentialOrOptions) => { | ||
if (isKeyCredential(credentialOrOptions)) { | ||
if (isKeyCredential(credentialOrOptions) || coreAuth.isTokenCredential(credentialOrOptions)) { | ||
assertValidEndpoint(connectionStringOrUrl); | ||
@@ -328,23 +349,31 @@ return { url: connectionStringOrUrl, credential: credentialOrOptions }; | ||
/** | ||
* Tests an Identifier to determine whether it implements CommunicationUser. | ||
* Tests an Identifier to determine whether it implements CommunicationUserIdentifier. | ||
* | ||
* @param identifier The assumed CommunicationUser to be tested. | ||
* @param identifier The assumed CommunicationUserIdentifier to be tested. | ||
*/ | ||
const isCommunicationUser = (identifier) => { | ||
const isCommunicationUserIdentifier = (identifier) => { | ||
return typeof identifier.communicationUserId === "string"; | ||
}; | ||
/** | ||
* Tests an Identifier to determine whether it implements PhoneNumber. | ||
* Tests an Identifier to determine whether it implements PhoneNumberIdentifier. | ||
* | ||
* @param identifier The assumed PhoneNumber to be tested. | ||
* @param identifier The assumed PhoneNumberIdentifier to be tested. | ||
*/ | ||
const isPhoneNumber = (identifier) => { | ||
const isPhoneNumberIdentifier = (identifier) => { | ||
return typeof identifier.phoneNumber === "string"; | ||
}; | ||
/** | ||
* Tests an Identifier to determine whether it implements CallingApplication. | ||
* Tests an Identifier to determine whether it implements MicrosoftTeamsUserIdentifier. | ||
* | ||
* @param identifier The assumed CallingApplication to be tested. | ||
* @param identifier The assumed available to be tested. | ||
*/ | ||
const isCallingApplication = (identifier) => { | ||
const isMicrosoftTeamsUserIdentifier = (identifier) => { | ||
return typeof identifier.microsoftTeamsUserId === "string"; | ||
}; | ||
/** | ||
* Tests an Identifier to determine whether it implements MicrosoftTeamsUserIdentifier. | ||
* | ||
* @param identifier The assumed CallingApplicationIdentifier to be tested. | ||
*/ | ||
const isCallingApplicationIdentifier = (identifier) => { | ||
return typeof identifier.callingApplicationId === "string"; | ||
@@ -361,3 +390,3 @@ }; | ||
/** | ||
* Returns the IdentifierKind for a given Identifier. Returns undefined if the kind couldn't be inferred. | ||
* Returns the CommunicationIdentifierKind for a given CommunicationIdentifier. Returns undefined if the kind couldn't be inferred. | ||
* | ||
@@ -367,23 +396,109 @@ * @param identifier The identifier whose kind is to be inferred. | ||
const getIdentifierKind = (identifier) => { | ||
if (isCommunicationUser(identifier)) { | ||
return Object.assign(Object.assign({}, identifier), { kind: "CommunicationUser" }); | ||
if (isCommunicationUserIdentifier(identifier)) { | ||
return Object.assign(Object.assign({}, identifier), { kind: "communicationUser" }); | ||
} | ||
if (isPhoneNumber(identifier)) { | ||
return Object.assign(Object.assign({}, identifier), { kind: "PhoneNumber" }); | ||
if (isPhoneNumberIdentifier(identifier)) { | ||
return Object.assign(Object.assign({}, identifier), { kind: "phoneNumber" }); | ||
} | ||
if (isCallingApplication(identifier)) { | ||
return Object.assign(Object.assign({}, identifier), { kind: "CallingApplication" }); | ||
if (isCallingApplicationIdentifier(identifier)) { | ||
return Object.assign(Object.assign({}, identifier), { kind: "callingApplication" }); | ||
} | ||
return Object.assign(Object.assign({}, identifier), { kind: "Unknown" }); | ||
if (isMicrosoftTeamsUserIdentifier(identifier)) { | ||
return Object.assign(Object.assign({}, identifier), { kind: "microsoftTeamsUser" }); | ||
} | ||
return Object.assign(Object.assign({}, identifier), { kind: "unknown" }); | ||
}; | ||
exports.AzureCommunicationUserCredential = AzureCommunicationUserCredential; | ||
// Copyright (c) Microsoft Corporation. | ||
const addIdIfExisting = (identifier, id) => { | ||
return id === undefined ? identifier : Object.assign(Object.assign({}, identifier), { id }); | ||
}; | ||
/** | ||
* @internal | ||
* Translates a CommunicationIdentifier to its serialized format for sending a request. | ||
* @param identifier The CommunicationIdentifier to be serialized. | ||
*/ | ||
const _serializeCommunicationIdentifier = (identifier) => { | ||
var _a, _b; | ||
const identifierKind = getIdentifierKind(identifier); | ||
switch (identifierKind.kind) { | ||
case "communicationUser": | ||
return { kind: "communicationUser", id: identifierKind.communicationUserId }; | ||
case "callingApplication": | ||
return { kind: "callingApplication", id: identifierKind.callingApplicationId }; | ||
case "phoneNumber": | ||
return addIdIfExisting({ kind: "phoneNumber", phoneNumber: identifierKind.phoneNumber }, identifierKind.id); | ||
case "microsoftTeamsUser": | ||
return addIdIfExisting({ | ||
kind: "microsoftTeamsUser", | ||
microsoftTeamsUserId: identifierKind.microsoftTeamsUserId, | ||
isAnonymous: (_a = identifierKind.isAnonymous) !== null && _a !== void 0 ? _a : false, | ||
cloud: (_b = identifierKind.cloud) !== null && _b !== void 0 ? _b : "public" | ||
}, identifierKind.id); | ||
case "unknown": | ||
return { kind: "unknown", id: identifierKind.id }; | ||
default: | ||
throw new Error(`Can't serialize an identifier with kind ${identifierKind.kind}`); | ||
} | ||
}; | ||
/** | ||
* @internal | ||
* Translates the serialized format of a communication identifier to CommunicationIdentifier. | ||
* @param serializedIdentifier The SerializedCommunicationIdentifier to be deserialized. | ||
*/ | ||
const _deserializeCommunicationIdentifier = (serializedIdentifier) => { | ||
switch (serializedIdentifier.kind) { | ||
case "communicationUser": | ||
return { | ||
kind: "communicationUser", | ||
communicationUserId: assertNotNullOrUndefined(serializedIdentifier, "id"), | ||
id: assertNotNullOrUndefined(serializedIdentifier, "id") | ||
}; | ||
case "callingApplication": | ||
return { | ||
kind: "callingApplication", | ||
callingApplicationId: assertNotNullOrUndefined(serializedIdentifier, "id"), | ||
id: assertNotNullOrUndefined(serializedIdentifier, "id") | ||
}; | ||
case "phoneNumber": | ||
return { | ||
kind: "phoneNumber", | ||
phoneNumber: assertNotNullOrUndefined(serializedIdentifier, "phoneNumber"), | ||
id: assertNotNullOrUndefined(serializedIdentifier, "id") | ||
}; | ||
case "microsoftTeamsUser": | ||
return { | ||
kind: "microsoftTeamsUser", | ||
microsoftTeamsUserId: assertNotNullOrUndefined(serializedIdentifier, "microsoftTeamsUserId"), | ||
isAnonymous: assertNotNullOrUndefined(serializedIdentifier, "isAnonymous"), | ||
cloud: assertNotNullOrUndefined(serializedIdentifier, "cloud"), | ||
id: assertNotNullOrUndefined(serializedIdentifier, "id") | ||
}; | ||
case "unknown": | ||
return { kind: "unknown", id: assertNotNullOrUndefined(serializedIdentifier, "id") }; | ||
default: | ||
return { kind: "unknown", id: assertNotNullOrUndefined(serializedIdentifier, "id") }; | ||
} | ||
}; | ||
const assertNotNullOrUndefined = (obj, prop) => { | ||
if (prop in obj) { | ||
return obj[prop]; | ||
} | ||
throw new Error(`Property ${prop} is required for identifier of kind ${obj.kind}.`); | ||
}; | ||
exports.AzureCommunicationTokenCredential = AzureCommunicationTokenCredential; | ||
exports._deserializeCommunicationIdentifier = _deserializeCommunicationIdentifier; | ||
exports._serializeCommunicationIdentifier = _serializeCommunicationIdentifier; | ||
exports.createCommunicationAccessKeyCredentialPolicy = createCommunicationAccessKeyCredentialPolicy; | ||
exports.createCommunicationAuthPolicy = createCommunicationAuthPolicy; | ||
exports.getIdentifierKind = getIdentifierKind; | ||
exports.isCallingApplication = isCallingApplication; | ||
exports.isCommunicationUser = isCommunicationUser; | ||
exports.isCallingApplicationIdentifier = isCallingApplicationIdentifier; | ||
exports.isCommunicationUserIdentifier = isCommunicationUserIdentifier; | ||
exports.isKeyCredential = isKeyCredential; | ||
exports.isPhoneNumber = isPhoneNumber; | ||
exports.isMicrosoftTeamsUserIdentifier = isMicrosoftTeamsUserIdentifier; | ||
exports.isPhoneNumberIdentifier = isPhoneNumberIdentifier; | ||
exports.isUnknownIdentifier = isUnknownIdentifier; | ||
exports.parseClientArguments = parseClientArguments; | ||
exports.parseConnectionString = parseConnectionString; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@azure/communication-common", | ||
"version": "1.0.0-beta.3", | ||
"version": "1.0.0-beta.4", | ||
"description": "Common package for Azure Communication services.", | ||
@@ -16,3 +16,3 @@ "sdk-type": "client", | ||
"build:node": "tsc -p . && cross-env ONLY_NODE=true rollup -c 2>&1", | ||
"build:samples": "cd samples && tsc -p .", | ||
"build:samples": "echo Skipped.", | ||
"build:test": "tsc -p . && rollup -c rollup.test.config.js 2>&1", | ||
@@ -37,3 +37,4 @@ "build": "tsc -p . && rollup -c 2>&1 && api-extractor run --local", | ||
"unit-test:node": "mocha --reporter ../../../common/tools/mocha-multi-reporter.js dist-test/index.node.js", | ||
"unit-test": "npm run unit-test:node && npm run unit-test:browser" | ||
"unit-test": "npm run unit-test:node && npm run unit-test:browser", | ||
"docs": "typedoc --excludePrivate --excludeNotExported --excludeExternals --stripInternal --mode file --out ./dist/docs ./src" | ||
}, | ||
@@ -93,3 +94,3 @@ "files": [ | ||
"cross-env": "^7.0.2", | ||
"eslint": "^6.1.0", | ||
"eslint": "^7.15.0", | ||
"inherits": "^2.0.3", | ||
@@ -105,3 +106,3 @@ "karma-chrome-launcher": "^3.0.0", | ||
"karma-mocha": "^2.0.1", | ||
"karma-remap-istanbul": "^0.6.0", | ||
"karma-sourcemap-loader": "^0.3.8", | ||
"karma": "^5.1.0", | ||
@@ -118,5 +119,6 @@ "mocha-junit-reporter": "^1.18.0", | ||
"sinon": "^9.0.2", | ||
"typescript": "~3.9.3", | ||
"util": "^0.12.1" | ||
"typescript": "4.1.2", | ||
"util": "^0.12.1", | ||
"typedoc": "0.15.2" | ||
} | ||
} |
@@ -10,3 +10,3 @@ # Azure Communication Common client library for JavaScript | ||
- An [Azure subscription][azure_sub]. | ||
- An existing Communication Services resource. If you need to create the resource, you can use the [Azure Portal][azure_portal] or [Azure CLI][azure_cli]. | ||
- 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]. | ||
@@ -21,9 +21,9 @@ ### Installing | ||
### CommunicationUserCredential and AzureCommunicationUserCredential | ||
### CommunicationTokenCredential and AzureCommunicationTokenCredential | ||
A `CommunicationUserCredential` authenticates a user with Communication Services, such as Chat or Calling. It optionally provides an auto-refresh mechanism to ensure a continuously stable authentication state during communications. | ||
A `CommunicationTokenCredential` authenticates a user with Communication Services, such as Chat or Calling. It optionally provides an auto-refresh mechanism to ensure a continuously stable authentication state during communications. | ||
It is up to you the developer to first create valid user tokens with the Azure Communication Administration library. Then you use these tokens to create a `AzureCommunicationUserCredential`. | ||
It is up to you the developer to first create valid user tokens with the Azure Communication Administration library. Then you use these tokens to create a `AzureCommunicationTokenCredential`. | ||
`CommunicationUserCredential` is only the interface, please always use the `AzureCommunicationUserCredential` constructor to create a credential and take advantage of the built-in refresh logic. | ||
`CommunicationTokenCredential` is only the interface, please always use the `AzureCommunicationTokenCredential` constructor to create a credential and take advantage of the built-in refresh logic. | ||
@@ -35,3 +35,3 @@ ## Examples | ||
```typescript | ||
const userCredential = new AzureCommunicationUserCredential( | ||
const tokenCredential = new AzureCommunicationTokenCredential( | ||
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjM2MDB9.adM-ddBZZlQ1WlN3pdPBOF5G4Wh9iZpxNP_fSvpF4cWs" | ||
@@ -46,3 +46,3 @@ ); | ||
```typescript | ||
const userCredential = new AzureCommunicationUserCredential({ | ||
const tokenCredential = new AzureCommunicationTokenCredential({ | ||
tokenRefresher: async () => fetchTokenFromMyServerForUser("bob@contoso.com") | ||
@@ -57,3 +57,3 @@ }); | ||
```typescript | ||
const userCredential = new AzureCommunicationUserCredential({ | ||
const tokenCredential = new AzureCommunicationTokenCredential({ | ||
tokenRefresher: async () => fetchTokenFromMyServerForUser("bob@contoso.com"), | ||
@@ -69,6 +69,6 @@ refreshProactively: true | ||
```typescript | ||
const userCredential = new AzureCommunicationUserCredential({ | ||
const tokenCredential = new AzureCommunicationTokenCredential({ | ||
tokenRefresher: async () => fetchTokenFromMyServerForUser("bob@contoso.com"), | ||
refreshProactively: true, | ||
initialToken: | ||
token: | ||
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjM2MDB9.adM-ddBZZlQ1WlN3pdPBOF5G4Wh9iZpxNP_fSvpF4cWs" | ||
@@ -95,3 +95,4 @@ }); | ||
[azure_portal]: https://portal.azure.com | ||
[azure_powershell]: https://docs.microsoft.com/powershell/module/az.communication/new-azcommunicationservice | ||
![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-js%2Fsdk%2Fcommunication%2Fcommunication-sms%2FREADME.png) |
@@ -5,11 +5,12 @@ import { AbortSignalLike } from '@azure/core-http'; | ||
import { RequestPolicyFactory } from '@azure/core-http'; | ||
import { TokenCredential } from '@azure/core-auth'; | ||
/** | ||
* The CommunicationUserCredential implementation with support for proactive token refresh. | ||
* The CommunicationTokenCredential implementation with support for proactive token refresh. | ||
*/ | ||
export declare class AzureCommunicationUserCredential implements CommunicationUserCredential { | ||
private readonly userCredential; | ||
export declare class AzureCommunicationTokenCredential implements CommunicationTokenCredential { | ||
private readonly tokenCredential; | ||
private disposed; | ||
/** | ||
* Creates an instance of CommunicationUserCredential with a static token and no proactive refreshing. | ||
* Creates an instance of CommunicationTokenCredential with a static token and no proactive refreshing. | ||
* @param token A user access token issued by Communication Services. | ||
@@ -19,7 +20,7 @@ */ | ||
/** | ||
* Creates an instance of CommunicationUserCredential with a lambda to get a token and options | ||
* Creates an instance of CommunicationTokenCredential with a lambda to get a token and options | ||
* to configure proactive refreshing. | ||
* @param refreshOptions Options to configure refresh and opt-in to proactive refreshing. | ||
*/ | ||
constructor(refreshOptions: RefreshOptions); | ||
constructor(refreshOptions: CommunicationTokenRefreshOptions); | ||
/** | ||
@@ -31,3 +32,3 @@ * Gets an `AccessToken` for the user. Throws if already disposed. | ||
/** | ||
* Disposes the CommunicationUserCredential and cancels any internal auto-refresh operation. | ||
* Disposes the CommunicationTokenCredential and cancels any internal auto-refresh operation. | ||
*/ | ||
@@ -41,3 +42,3 @@ dispose(): void; | ||
*/ | ||
export declare interface CallingApplication { | ||
export declare interface CallingApplicationIdentifier extends WithOptionalFullId { | ||
/** | ||
@@ -50,25 +51,25 @@ * Id of the CallingApplication. | ||
/** | ||
* IdentifierKind for a CallingApplication identifier. | ||
* IdentifierKind for a CallingApplicationIdentifier. | ||
*/ | ||
export declare interface CallingApplicationKind extends CallingApplication { | ||
export declare interface CallingApplicationKind extends CallingApplicationIdentifier { | ||
/** | ||
* The identifier kind. | ||
*/ | ||
kind: "CallingApplication"; | ||
kind: "callingApplication"; | ||
} | ||
/** | ||
* An Azure Communication user. | ||
* Identifies a communication participant. | ||
*/ | ||
export declare interface CommunicationUser { | ||
/** | ||
* Id of the CommunicationUser as returned from the Communication Service. | ||
*/ | ||
communicationUserId: string; | ||
} | ||
export declare type CommunicationIdentifier = CommunicationUserIdentifier | PhoneNumberIdentifier | CallingApplicationIdentifier | MicrosoftTeamsUserIdentifier | UnknownIdentifier; | ||
/** | ||
* The Azure Communication Services User token credential. | ||
* The CommunicationIdentifierKind is a discriminated union that adds a property `kind` to an Identifier. | ||
*/ | ||
export declare interface CommunicationUserCredential { | ||
export declare type CommunicationIdentifierKind = CommunicationUserKind | PhoneNumberKind | CallingApplicationKind | MicrosoftTeamsUserKind | UnknownIdentifierKind; | ||
/** | ||
* The Azure Communication Services token credential. | ||
*/ | ||
export declare interface CommunicationTokenCredential { | ||
/** | ||
@@ -80,3 +81,3 @@ * Gets an `AccessToken` for the user. Throws if already disposed. | ||
/** | ||
* Disposes the CommunicationUserCredential and cancels any internal auto-refresh operation. | ||
* Disposes the CommunicationTokenCredential and cancels any internal auto-refresh operation. | ||
*/ | ||
@@ -87,9 +88,38 @@ dispose(): void; | ||
/** | ||
* IdentifierKind for a CommunicationUser identifier. | ||
* Options for auto-refreshing a Communication Token credential. | ||
*/ | ||
export declare interface CommunicationUserKind extends CommunicationUser { | ||
export declare interface CommunicationTokenRefreshOptions { | ||
/** | ||
* Function that returns a token acquired from the Communication configuration SDK. | ||
*/ | ||
tokenRefresher: (abortSignal?: AbortSignalLike) => Promise<string>; | ||
/** | ||
* Optional token to initialize. | ||
*/ | ||
token?: string; | ||
/** | ||
* Indicates whether the token should be proactively renewed prior to expiry or only renew on demand. | ||
* By default false. | ||
*/ | ||
refreshProactively?: boolean; | ||
} | ||
/** | ||
* An Azure Communication user. | ||
*/ | ||
export declare interface CommunicationUserIdentifier extends WithOptionalFullId { | ||
/** | ||
* Id of the CommunicationUser as returned from the Communication Service. | ||
*/ | ||
communicationUserId: string; | ||
} | ||
/** | ||
* IdentifierKind for a CommunicationUserIdentifier. | ||
*/ | ||
export declare interface CommunicationUserKind extends CommunicationUserIdentifier { | ||
/** | ||
* The identifier kind. | ||
*/ | ||
kind: "CommunicationUser"; | ||
kind: "communicationUser"; | ||
} | ||
@@ -106,31 +136,46 @@ | ||
/** | ||
* Returns the IdentifierKind for a given Identifier. Returns undefined if the kind couldn't be inferred. | ||
* Creates a pipeline policy to authenticate request based | ||
* on the credential passed in | ||
* | ||
* @param identifier The identifier whose kind is to be inferred. | ||
* @param {KeyCredential | TokenCredential} credential The key credential | ||
*/ | ||
export declare const getIdentifierKind: (identifier: Identifier) => IdentifierKind; | ||
export declare const createCommunicationAuthPolicy: (credential: KeyCredential | TokenCredential) => RequestPolicyFactory; | ||
/* Excluded from this release type: _deserializeCommunicationIdentifier */ | ||
/** | ||
* Identifies a communication user. | ||
* Represents different properties of connection string | ||
* using format "/endpoint=(.*);accesskey=(.*)" | ||
*/ | ||
export declare type Identifier = CommunicationUser | PhoneNumber | CallingApplication | UnknownIdentifier; | ||
export declare interface EndpointCredential { | ||
/** | ||
* The endpoint as string | ||
*/ | ||
endpoint: string; | ||
/** | ||
* The access key represented as a KeyCredential object | ||
*/ | ||
credential: KeyCredential; | ||
} | ||
/** | ||
* The IdentifierKind is a discriminated union that adds a property `kind` to an Identifier. | ||
* Returns the CommunicationIdentifierKind for a given CommunicationIdentifier. Returns undefined if the kind couldn't be inferred. | ||
* | ||
* @param identifier The identifier whose kind is to be inferred. | ||
*/ | ||
export declare type IdentifierKind = CommunicationUserKind | PhoneNumberKind | CallingApplicationKind | UnknownIdentifierKind; | ||
export declare const getIdentifierKind: (identifier: CommunicationIdentifier) => CommunicationIdentifierKind; | ||
/** | ||
* Tests an Identifier to determine whether it implements CallingApplication. | ||
* Tests an Identifier to determine whether it implements MicrosoftTeamsUserIdentifier. | ||
* | ||
* @param identifier The assumed CallingApplication to be tested. | ||
* @param identifier The assumed CallingApplicationIdentifier to be tested. | ||
*/ | ||
export declare const isCallingApplication: (identifier: Identifier) => identifier is CallingApplication; | ||
export declare const isCallingApplicationIdentifier: (identifier: CommunicationIdentifier) => identifier is CallingApplicationIdentifier; | ||
/** | ||
* Tests an Identifier to determine whether it implements CommunicationUser. | ||
* Tests an Identifier to determine whether it implements CommunicationUserIdentifier. | ||
* | ||
* @param identifier The assumed CommunicationUser to be tested. | ||
* @param identifier The assumed CommunicationUserIdentifier to be tested. | ||
*/ | ||
export declare const isCommunicationUser: (identifier: Identifier) => identifier is CommunicationUser; | ||
export declare const isCommunicationUserIdentifier: (identifier: CommunicationIdentifier) => identifier is CommunicationUserIdentifier; | ||
@@ -145,9 +190,16 @@ /** | ||
/** | ||
* Tests an Identifier to determine whether it implements PhoneNumber. | ||
* Tests an Identifier to determine whether it implements MicrosoftTeamsUserIdentifier. | ||
* | ||
* @param identifier The assumed PhoneNumber to be tested. | ||
* @param identifier The assumed available to be tested. | ||
*/ | ||
export declare const isPhoneNumber: (identifier: Identifier) => identifier is PhoneNumber; | ||
export declare const isMicrosoftTeamsUserIdentifier: (identifier: CommunicationIdentifier) => identifier is MicrosoftTeamsUserIdentifier; | ||
/** | ||
* Tests an Identifier to determine whether it implements PhoneNumberIdentifier. | ||
* | ||
* @param identifier The assumed PhoneNumberIdentifier to be tested. | ||
*/ | ||
export declare const isPhoneNumberIdentifier: (identifier: CommunicationIdentifier) => identifier is PhoneNumberIdentifier; | ||
/** | ||
* Tests an Identifier to determine whether it implements UnknownIdentifier. | ||
@@ -157,5 +209,33 @@ * | ||
*/ | ||
export declare const isUnknownIdentifier: (identifier: Identifier) => identifier is UnknownIdentifier; | ||
export declare const isUnknownIdentifier: (identifier: CommunicationIdentifier) => identifier is UnknownIdentifier; | ||
/** | ||
* A Microsoft Teams user. | ||
*/ | ||
export declare interface MicrosoftTeamsUserIdentifier extends WithOptionalFullId { | ||
/** | ||
* Id of the Microsoft Teams user. If the user isn't anonymous, the id is the AAD object id of the user. | ||
*/ | ||
microsoftTeamsUserId: string; | ||
/** | ||
* True if the user is anonymous, for example when joining a meeting with a share link. If missing, the user is not anonymous. | ||
*/ | ||
isAnonymous?: boolean; | ||
/** | ||
* The cloud that the Microsoft Teams user belongs to. If missing, the cloud is "public". | ||
*/ | ||
cloud?: "public" | "dod" | "gcch"; | ||
} | ||
/** | ||
* IdentifierKind for a MicrosoftTeamsUserIdentifier. | ||
*/ | ||
export declare interface MicrosoftTeamsUserKind extends MicrosoftTeamsUserIdentifier { | ||
/** | ||
* The identifier kind. | ||
*/ | ||
kind: "microsoftTeamsUser"; | ||
} | ||
/** | ||
* Parses arguments passed to a communication client. | ||
@@ -169,5 +249,13 @@ * | ||
/** | ||
* Returns an EndpointCredential to easily access properties of the connection string | ||
* | ||
* @param {string} connectionString The connection string to parse | ||
* @returns {EndpointCredential} Object to access the endpoint and the credenials | ||
*/ | ||
export declare const parseConnectionString: (connectionString: string) => EndpointCredential; | ||
/** | ||
* A phone number. | ||
*/ | ||
export declare interface PhoneNumber { | ||
export declare interface PhoneNumberIdentifier extends WithOptionalFullId { | ||
/** | ||
@@ -180,30 +268,19 @@ * The phone number in E.164 format. | ||
/** | ||
* IdentifierKind for a PhoneNumber identifier. | ||
* IdentifierKind for a PhoneNumberIdentifier. | ||
*/ | ||
export declare interface PhoneNumberKind extends PhoneNumber { | ||
export declare interface PhoneNumberKind extends PhoneNumberIdentifier { | ||
/** | ||
* The identifier kind. | ||
*/ | ||
kind: "PhoneNumber"; | ||
kind: "phoneNumber"; | ||
} | ||
/** | ||
* Options for auto-refreshing a Communication user credential. | ||
*/ | ||
export declare interface RefreshOptions { | ||
/** | ||
* Function that returns a user token acquired from the Communication configuration SDK. | ||
*/ | ||
tokenRefresher: (abortSignal?: AbortSignalLike) => Promise<string>; | ||
/** | ||
* Optional user token to initialize. | ||
*/ | ||
initialToken?: string; | ||
/** | ||
* Indicates whether the user token should be proactively renewed prior to expiry or only renew on demand. | ||
* By default false. | ||
*/ | ||
refreshProactively?: boolean; | ||
} | ||
/* Excluded from this release type: _serializeCommunicationIdentifier */ | ||
/* Excluded from this release type: _SerializedCommunicationCloudEnvironment */ | ||
/* Excluded from this release type: _SerializedCommunicationIdentifier */ | ||
/* Excluded from this release type: _SerializedCommunicationIdentifierKind */ | ||
/** | ||
@@ -226,3 +303,3 @@ * An unknown identifier that doesn't fit any of the other identifier types. | ||
*/ | ||
kind: "Unknown"; | ||
kind: "unknown"; | ||
} | ||
@@ -235,5 +312,12 @@ | ||
url: string; | ||
credential: KeyCredential; | ||
credential: TokenCredential | KeyCredential; | ||
}; | ||
export declare interface WithOptionalFullId { | ||
/** | ||
* Optional full id of the identifier. | ||
*/ | ||
id?: string; | ||
} | ||
export { } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
148666
37
1302
92
43
15
1