Socket
Socket
Sign inDemoInstall

@azure/communication-common

Package Overview
Dependencies
Maintainers
3
Versions
192
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@azure/communication-common - npm Package Compare versions

Comparing version 1.0.0-alpha.20201218.1 to 1.0.0-alpha.20201223.1

dist-esm/src/autoRefreshTokenCredential.js

16

CHANGELOG.md

@@ -5,3 +5,19 @@ # Release History

### Added
- Added `MicrosoftTeamsUserIdentifier` and `isMicrosoftTeamsUserIdentifier`.
### Breaking Changes
- 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)

@@ -8,0 +24,0 @@

37

dist-esm/src/identifierModels.js
// 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)) {
if (isCommunicationUserIdentifier(identifier)) {
return Object.assign(Object.assign({}, identifier), { kind: "CommunicationUser" });
}
if (isPhoneNumber(identifier)) {
if (isPhoneNumberIdentifier(identifier)) {
return Object.assign(Object.assign({}, identifier), { kind: "PhoneNumber" });
}
if (isCallingApplication(identifier)) {
if (isCallingApplicationIdentifier(identifier)) {
return Object.assign(Object.assign({}, identifier), { kind: "CallingApplication" });
}
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";
//# 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();
}

@@ -325,23 +325,31 @@ throwIfDisposed() {

/**
* 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";

@@ -358,3 +366,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.
*

@@ -364,23 +372,27 @@ * @param identifier The identifier whose kind is to be inferred.

const getIdentifierKind = (identifier) => {
if (isCommunicationUser(identifier)) {
if (isCommunicationUserIdentifier(identifier)) {
return Object.assign(Object.assign({}, identifier), { kind: "CommunicationUser" });
}
if (isPhoneNumber(identifier)) {
if (isPhoneNumberIdentifier(identifier)) {
return Object.assign(Object.assign({}, identifier), { kind: "PhoneNumber" });
}
if (isCallingApplication(identifier)) {
if (isCallingApplicationIdentifier(identifier)) {
return Object.assign(Object.assign({}, identifier), { kind: "CallingApplication" });
}
if (isMicrosoftTeamsUserIdentifier(identifier)) {
return Object.assign(Object.assign({}, identifier), { kind: "MicrosoftTeamsUser" });
}
return Object.assign(Object.assign({}, identifier), { kind: "Unknown" });
};
exports.AzureCommunicationUserCredential = AzureCommunicationUserCredential;
exports.AzureCommunicationTokenCredential = AzureCommunicationTokenCredential;
exports.createCommunicationAccessKeyCredentialPolicy = createCommunicationAccessKeyCredentialPolicy;
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;
//# sourceMappingURL=index.js.map
{
"name": "@azure/communication-common",
"version": "1.0.0-alpha.20201218.1",
"version": "1.0.0-alpha.20201223.1",
"description": "Common package for Azure Communication services.",

@@ -5,0 +5,0 @@ "sdk-type": "client",

@@ -20,9 +20,9 @@ # Azure Communication Common client library for JavaScript

### 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.

@@ -34,3 +34,3 @@ ## Examples

```typescript
const userCredential = new AzureCommunicationUserCredential(
const tokenCredential = new AzureCommunicationTokenCredential(
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjM2MDB9.adM-ddBZZlQ1WlN3pdPBOF5G4Wh9iZpxNP_fSvpF4cWs"

@@ -45,3 +45,3 @@ );

```typescript
const userCredential = new AzureCommunicationUserCredential({
const tokenCredential = new AzureCommunicationTokenCredential({
tokenRefresher: async () => fetchTokenFromMyServerForUser("bob@contoso.com")

@@ -56,3 +56,3 @@ });

```typescript
const userCredential = new AzureCommunicationUserCredential({
const tokenCredential = new AzureCommunicationTokenCredential({
tokenRefresher: async () => fetchTokenFromMyServerForUser("bob@contoso.com"),

@@ -68,6 +68,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"

@@ -74,0 +74,0 @@ });

@@ -7,9 +7,9 @@ import { AbortSignalLike } from '@azure/core-http';

/**
* 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 +19,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 +31,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 +41,3 @@ dispose(): void;

*/
export declare interface CallingApplication {
export declare interface CallingApplicationIdentifier {
/**

@@ -50,5 +50,5 @@ * 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 {
/**

@@ -61,15 +61,15 @@ * The identifier kind.

/**
* 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 {
/**

@@ -81,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.
*/

@@ -88,6 +88,35 @@ 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 {
/**
* 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.

@@ -107,31 +136,21 @@ */

/**
* 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.
*
* @param identifier The identifier whose kind is to be inferred.
*/
export declare const getIdentifierKind: (identifier: Identifier) => IdentifierKind;
export declare const getIdentifierKind: (identifier: CommunicationIdentifier) => CommunicationIdentifierKind;
/**
* Identifies a communication user.
*/
export declare type Identifier = CommunicationUser | PhoneNumber | CallingApplication | UnknownIdentifier;
/**
* The IdentifierKind is a discriminated union that adds a property `kind` to an Identifier.
*/
export declare type IdentifierKind = CommunicationUserKind | PhoneNumberKind | CallingApplicationKind | UnknownIdentifierKind;
/**
* 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;

@@ -146,9 +165,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.

@@ -158,5 +184,29 @@ *

*/
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 {
/**
* 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.
*/
isAnonymous: boolean | undefined;
}
/**
* IdentifierKind for a MicrosoftTeamsUserIdentifier.
*/
export declare interface MicrosoftTeamsUserKind extends MicrosoftTeamsUserIdentifier {
/**
* The identifier kind.
*/
kind: "MicrosoftTeamsUser";
}
/**
* Parses arguments passed to a communication client.

@@ -172,3 +222,3 @@ *

*/
export declare interface PhoneNumber {
export declare interface PhoneNumberIdentifier {
/**

@@ -181,5 +231,5 @@ * 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 {
/**

@@ -192,21 +242,2 @@ * The identifier kind.

/**
* 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;
}
/**
* An unknown identifier that doesn't fit any of the other identifier types.

@@ -213,0 +244,0 @@ */

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc