@microsoft/mgt-element
Advanced tools
Comparing version 3.1.3-next.enable-tree-shaking.d405e0b to 3.1.3-next.mgt-chat.4702515
@@ -55,3 +55,3 @@ /** | ||
*/ | ||
forComponent(component: Element | string): Graph; | ||
forComponent(component: Element | string, version?: string): Graph; | ||
/** | ||
@@ -89,3 +89,3 @@ * Returns a new graph request for a specific component | ||
*/ | ||
export declare const createFromProvider: (provider: IProvider, version?: string, component?: Element) => Graph; | ||
export declare const createFromProvider: (provider: IProvider, version?: string, component?: Element | string) => Graph; | ||
//# sourceMappingURL=Graph.d.ts.map |
@@ -69,4 +69,4 @@ /** | ||
*/ | ||
forComponent(component) { | ||
const graph = new Graph(this._client, this._version); | ||
forComponent(component, version) { | ||
const graph = new Graph(this._client, version || this._version); | ||
graph.setComponent(component); | ||
@@ -73,0 +73,0 @@ return graph; |
@@ -45,3 +45,3 @@ /** | ||
*/ | ||
forComponent(component: Element): IGraph; | ||
forComponent(component: Element | string, version?: string): IGraph; | ||
/** | ||
@@ -48,0 +48,0 @@ * use this method to make calls directly to the Graph. |
@@ -18,7 +18,4 @@ /** | ||
export * from './providers/SimpleProvider'; | ||
export * from './utils/CacheItem'; | ||
export * from './utils/CacheSchema'; | ||
export * from './utils/CacheService'; | ||
export * from './utils/CacheStore'; | ||
export * from './utils/dbListKey'; | ||
export * from './utils/EventDispatcher'; | ||
@@ -36,2 +33,4 @@ export * from './utils/equals'; | ||
export * from './utils/CustomElement'; | ||
export * from './utils/Logging'; | ||
export * from './utils/registerComponent'; | ||
export { PACKAGE_VERSION } from './utils/version'; | ||
@@ -38,0 +37,0 @@ export * from './CollectionResponse'; |
@@ -18,7 +18,4 @@ /** | ||
export * from './providers/SimpleProvider'; | ||
export * from './utils/CacheItem'; | ||
export * from './utils/CacheSchema'; | ||
export * from './utils/CacheService'; | ||
export * from './utils/CacheStore'; | ||
export * from './utils/dbListKey'; | ||
export * from './utils/EventDispatcher'; | ||
@@ -36,2 +33,4 @@ export * from './utils/equals'; | ||
export * from './utils/CustomElement'; | ||
export * from './utils/Logging'; | ||
export * from './utils/registerComponent'; | ||
export { PACKAGE_VERSION } from './utils/version'; | ||
@@ -38,0 +37,0 @@ export * from './CollectionResponse'; |
@@ -34,4 +34,4 @@ /** | ||
*/ | ||
forComponent(component: MgtBaseComponent): MockGraph; | ||
forComponent(component: MgtBaseComponent | string): MockGraph; | ||
} | ||
//# sourceMappingURL=MockGraph.d.ts.map |
@@ -11,3 +11,3 @@ /** | ||
/** | ||
* Provider Type to be extended for implmenting new providers | ||
* Provider Type to be extended for implementing new providers | ||
* | ||
@@ -212,2 +212,3 @@ * @export | ||
export interface ActiveAccountChanged { | ||
detail: IProviderAccount; | ||
} | ||
@@ -221,2 +222,3 @@ /** | ||
export interface LoginChangedEvent { | ||
detail: ProviderState; | ||
} | ||
@@ -223,0 +225,0 @@ /** |
@@ -11,3 +11,3 @@ /** | ||
/** | ||
* Provider Type to be extended for implmenting new providers | ||
* Provider Type to be extended for implementing new providers | ||
* | ||
@@ -140,3 +140,3 @@ * @export | ||
this._state = state; | ||
this._loginChangedDispatcher.fire({}); | ||
this._loginChangedDispatcher.fire({ detail: this._state }); | ||
} | ||
@@ -170,3 +170,3 @@ } | ||
setActiveAccount(user) { | ||
this.fireActiveAccountChanged(); | ||
this.fireActiveAccountChanged({ detail: user }); | ||
} | ||
@@ -196,4 +196,4 @@ /** | ||
*/ | ||
fireActiveAccountChanged() { | ||
this._activeAccountChangedDispatcher.fire({}); | ||
fireActiveAccountChanged(account) { | ||
this._activeAccountChangedDispatcher.fire(account); | ||
} | ||
@@ -200,0 +200,0 @@ /** |
@@ -18,3 +18,3 @@ /** | ||
import { BatchRequestContent } from '@microsoft/microsoft-graph-client'; | ||
import { delay } from '../utils'; | ||
import { delay } from './delay'; | ||
import { prepScopes } from './prepScopes'; | ||
@@ -21,0 +21,0 @@ import { BatchRequest } from './BatchRequest'; |
@@ -8,5 +8,10 @@ /** | ||
import { CacheStore } from './CacheStore'; | ||
import { CacheSchema } from './CacheSchema'; | ||
import { CacheItem } from './CacheItem'; | ||
/** | ||
* Localstorage key for storing names of cache databases | ||
* | ||
* @type {string} | ||
* | ||
*/ | ||
export declare const dbListKey = "mgt-db-list"; | ||
/** | ||
* Holds the cache options for cache store | ||
@@ -88,2 +93,9 @@ * | ||
fileLists: CacheOptions; | ||
/** | ||
* Cache options for conversation store | ||
* | ||
* @type {CacheOptions} | ||
* @memberof CacheConfig | ||
*/ | ||
conversation: CacheOptions; | ||
} | ||
@@ -160,2 +172,56 @@ /** | ||
} | ||
export interface Index { | ||
name: string; | ||
field: string; | ||
} | ||
/** | ||
* Represents organization for a cache | ||
* | ||
* @export | ||
* @interface CacheSchema | ||
*/ | ||
export interface CacheSchema { | ||
/** | ||
* version number of cache, useful for upgrading | ||
* | ||
* @type {number} | ||
* @memberof CacheSchema | ||
*/ | ||
version: number; | ||
/** | ||
* name of the cache | ||
* | ||
* @type {string} | ||
* @memberof CacheSchema | ||
*/ | ||
name: string; | ||
/** | ||
* list of stores in the cache | ||
* | ||
* @type {{ [name: string]: CacheSchemaStore }} | ||
* @memberof CacheSchema | ||
*/ | ||
stores: Record<string, string>; | ||
/** | ||
* Optional field to define indexed fields on a per store basis | ||
* K is the name of the store for which the indexes should be applied | ||
* T is the names of the fields on the stored data to be indexed | ||
*/ | ||
indexes?: Record<string, Index[]>; | ||
} | ||
/** | ||
* item that is stored in cache | ||
* | ||
* @export | ||
* @interface CacheItem | ||
*/ | ||
export interface CacheItem { | ||
/** | ||
* date and time that item was retrieved from api/stored in cache | ||
* | ||
* @type {number} | ||
* @memberof CacheItem | ||
*/ | ||
timeCached?: number; | ||
} | ||
//# sourceMappingURL=CacheService.d.ts.map |
@@ -19,4 +19,11 @@ /** | ||
import { CacheStore } from './CacheStore'; | ||
import { dbListKey } from './dbListKey'; | ||
import { error } from './Logging'; | ||
/** | ||
* Localstorage key for storing names of cache databases | ||
* | ||
* @type {string} | ||
* | ||
*/ | ||
export const dbListKey = 'mgt-db-list'; | ||
/** | ||
* class in charge of managing all the caches and their stores | ||
@@ -66,3 +73,3 @@ * | ||
delReq.onerror = () => { | ||
console.error(`🦒: ${delReq.error.name} occurred deleting cache: ${x}`, delReq.error.message); | ||
error(`${delReq.error.name} occurred deleting cache: ${x}`, delReq.error.message); | ||
reject(); | ||
@@ -158,4 +165,8 @@ }; | ||
isEnabled: true | ||
}, | ||
conversation: { | ||
invalidationPeriod: 5 * 24 * 60 * 60 * 1000, | ||
isEnabled: true | ||
} | ||
}; | ||
//# sourceMappingURL=CacheService.js.map |
@@ -7,4 +7,3 @@ /** | ||
*/ | ||
import { CacheItem } from './CacheItem'; | ||
import { CacheSchema } from './CacheSchema'; | ||
import { CacheItem, CacheSchema } from './CacheService'; | ||
/** | ||
@@ -27,4 +26,12 @@ * Represents a store in the cache | ||
*/ | ||
getValue(key: string): Promise<T>; | ||
getValue(key: string): Promise<T | null>; | ||
/** | ||
* removes a value from the cache for the given key | ||
* | ||
* @param {string} key | ||
* @returns {Promise<void>} | ||
* @memberof Cache | ||
*/ | ||
delete(key: string): Promise<void>; | ||
/** | ||
* inserts value into cache for the given key | ||
@@ -50,3 +57,4 @@ * | ||
private getDb; | ||
queryDb(indexName: string, query: IDBKeyRange | IDBValidKey): Promise<T[]>; | ||
} | ||
//# sourceMappingURL=CacheStore.d.ts.map |
@@ -18,3 +18,3 @@ /** | ||
import { Providers } from '../providers/Providers'; | ||
import { dbListKey } from './dbListKey'; | ||
import { dbListKey } from './CacheService'; | ||
/** | ||
@@ -56,2 +56,23 @@ * Represents a store in the cache | ||
/** | ||
* removes a value from the cache for the given key | ||
* | ||
* @param {string} key | ||
* @returns {Promise<void>} | ||
* @memberof Cache | ||
*/ | ||
delete(key) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (!window.indexedDB) { | ||
return; | ||
} | ||
try { | ||
const db = yield this.getDb(); | ||
return db.delete(this.store, key); | ||
} | ||
catch (e) { | ||
return; | ||
} | ||
}); | ||
} | ||
/** | ||
* inserts value into cache for the given key | ||
@@ -113,3 +134,4 @@ * | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
upgrade: (db, _oldVersion, _newVersion, _transaction) => { | ||
upgrade: (db, _oldVersion, _newVersion, transaction) => { | ||
var _a, _b; | ||
const dbArray = JSON.parse(localStorage.getItem(dbListKey)) || []; | ||
@@ -121,5 +143,18 @@ if (!dbArray.includes(dbName)) { | ||
for (const storeName in this.schema.stores) { | ||
if (Object.prototype.hasOwnProperty.call(this.schema.stores, storeName) && | ||
!db.objectStoreNames.contains(storeName)) { | ||
db.createObjectStore(storeName); | ||
if (Object.prototype.hasOwnProperty.call(this.schema.stores, storeName)) { | ||
const indexes = (_b = (_a = this.schema.indexes) === null || _a === void 0 ? void 0 : _a[storeName]) !== null && _b !== void 0 ? _b : []; | ||
if (!db.objectStoreNames.contains(storeName)) { | ||
const objectStore = db.createObjectStore(storeName); | ||
indexes.forEach(i => { | ||
objectStore.createIndex(i.name, i.field); | ||
}); | ||
} | ||
else { | ||
const store = transaction.objectStore(storeName); | ||
indexes.forEach(i => { | ||
if (store && !store.indexNames.contains(i.name)) { | ||
store.createIndex(i.name, i.field); | ||
} | ||
}); | ||
} | ||
} | ||
@@ -132,3 +167,9 @@ } | ||
} | ||
queryDb(indexName, query) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const db = yield this.getDb(); | ||
return (yield db.getAllFromIndex(this.store, indexName, query)); | ||
}); | ||
} | ||
} | ||
//# sourceMappingURL=CacheStore.js.map |
@@ -9,2 +9,3 @@ /** | ||
import { customElementHelper } from '../components/customElementHelper'; | ||
import { error } from './Logging'; | ||
/** | ||
@@ -28,3 +29,3 @@ * This is a wrapper decorator for `customElement` from `lit` | ||
// eslint-disable-next-line no-console | ||
console.error(`🦒: Tag name ${mgtTagName} is already defined using class ${mgtElement.name} version ${version(mgtElement)}\n`, `Currently registering class ${classOrDescriptor.name} with version ${version(classOrDescriptor)}\n`, 'Please use the disambiguation feature to define a unique tag name for this component see: https://github.com/microsoftgraph/microsoft-graph-toolkit/tree/main/packages/mgt-components#disambiguation'); | ||
error(`Tag name ${mgtTagName} is already defined using class ${mgtElement.name} version ${version(mgtElement)}\n`, `Currently registering class ${classOrDescriptor.name} with version ${version(classOrDescriptor)}\n`, 'Please use the disambiguation feature to define a unique tag name for this component see: https://github.com/microsoftgraph/microsoft-graph-toolkit/tree/main/packages/mgt-components#disambiguation'); | ||
return classOrDescriptor; | ||
@@ -31,0 +32,0 @@ }; |
@@ -1,8 +0,2 @@ | ||
/** | ||
* ------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. | ||
* See License in the project root for license information. | ||
* ------------------------------------------------------------------------------------------- | ||
*/ | ||
export {}; | ||
//# sourceMappingURL=equals.tests.d.ts.map |
@@ -0,1 +1,2 @@ | ||
/* eslint-disable @typescript-eslint/no-unused-expressions */ | ||
/** | ||
@@ -7,3 +8,3 @@ * ------------------------------------------------------------------------------------------- | ||
*/ | ||
import { it } from '@jest/globals'; | ||
import { expect } from '@open-wc/testing'; | ||
import { equals } from './equals'; | ||
@@ -17,34 +18,40 @@ describe('objectEquals', () => { | ||
const simpleDate = new Date(0); | ||
it.each([ | ||
[{}, {}], | ||
[ | ||
{ a: 1, b: true, c: 'foo' }, | ||
{ c: 'foo', b: true, a: 1 } | ||
], | ||
[{ a: [1, 2, 3] }, { a: [1, 2, 3] }], | ||
[{ a: { b: { c: 1 } } }, { a: { b: { c: 1 } } }], | ||
[{ a: [1, [2, [3]]] }, { a: [1, [2, [3]]] }], | ||
[circularObject, circularObject], | ||
[circularObject, { a: circularObject }], | ||
[circularArray, circularArray], | ||
[ | ||
{ a: circularObject, b: circularArray }, | ||
{ a: circularObject, b: circularArray } | ||
], | ||
[{ a: simpleDate }, { a: simpleDate }] | ||
])('should return true between %p and %p', (o1, o2) => { | ||
expect(equals(o1, o2)).toBe(true); | ||
it('should return true', () => { | ||
const testValues = [ | ||
[{}, {}], | ||
[ | ||
{ a: 1, b: true, c: 'foo' }, | ||
{ c: 'foo', b: true, a: 1 } | ||
], | ||
[{ a: [1, 2, 3] }, { a: [1, 2, 3] }], | ||
[{ a: { b: { c: 1 } } }, { a: { b: { c: 1 } } }], | ||
[{ a: [1, [2, [3]]] }, { a: [1, [2, [3]]] }], | ||
[circularObject, circularObject], | ||
[circularObject, { a: circularObject }], | ||
[circularArray, circularArray], | ||
[ | ||
{ a: circularObject, b: circularArray }, | ||
{ a: circularObject, b: circularArray } | ||
], | ||
[{ a: simpleDate }, { a: simpleDate }] | ||
]; | ||
for (const [o1, o2] of testValues) { | ||
expect(equals(o1, o2)).to.be.true; | ||
} | ||
}); | ||
it.each([ | ||
[{ a: {} }, { a: [] }], | ||
[{ a: [1, 2, 3] }, { a: [3, 2, 1] }], | ||
[{ a: [1, [2, [3]]] }, { a: [1, [2, [4]]] }], | ||
[{ a: { b: [{ c: 1 }, { d: [2, 3] }] } }, { a: { b: [{ c: 1 }, { d: [3, 2] }] } }], | ||
[{ a: new Date() }, { a: new Date() }], | ||
[circularObject, circularArray], | ||
[circularObject, { b: circularObject }] | ||
])('should return false between %p and %p', (o1, o2) => { | ||
expect(equals(o1, o2)).toBe(false); | ||
it('should return false ', () => { | ||
const testValues = [ | ||
[{ a: {} }, { a: [] }], | ||
[{ a: [1, 2, 3] }, { a: [3, 2, 1] }], | ||
[{ a: [1, [2, [3]]] }, { a: [1, [2, [4]]] }], | ||
[{ a: { b: [{ c: 1 }, { d: [2, 3] }] } }, { a: { b: [{ c: 1 }, { d: [3, 2] }] } }], | ||
[{ a: new Date() }, { a: new Date() }], | ||
[circularObject, circularArray], | ||
[circularObject, { b: circularObject }] | ||
]; | ||
for (const [o1, o2] of testValues) { | ||
expect(equals(o1, o2)).to.be.false; | ||
} | ||
}); | ||
}); | ||
//# sourceMappingURL=equals.tests.js.map |
@@ -7,19 +7,22 @@ /** | ||
*/ | ||
import { it } from '@jest/globals'; | ||
import { assert } from 'console'; | ||
import { EventDispatcher } from './EventDispatcher'; | ||
import { assert, restore, fake } from 'sinon'; | ||
describe('EventDispatcher tests', () => { | ||
afterEach(() => { | ||
// Restore the default sandbox here | ||
restore(); | ||
}); | ||
it('should add and remove event handlers', () => { | ||
const dispatcher = new EventDispatcher(); | ||
const handler1 = jest.fn(); | ||
const handler2 = jest.fn(); | ||
const handler1 = fake(); | ||
const handler2 = fake(); | ||
dispatcher.add(handler1); | ||
dispatcher.add(handler2); | ||
dispatcher.fire('event'); | ||
expect(handler1).toHaveBeenCalledTimes(1); | ||
expect(handler2).toHaveBeenCalledTimes(1); | ||
assert.calledOnce(handler1); | ||
assert.calledOnce(handler2); | ||
dispatcher.remove(handler1); | ||
dispatcher.fire('event'); | ||
expect(handler1).toHaveBeenCalledTimes(1); | ||
expect(handler2).toHaveBeenCalledTimes(2); | ||
assert.calledOnce(handler1); | ||
assert.callCount(handler2, 2); | ||
}); | ||
@@ -29,11 +32,11 @@ it('should not throw when remove is called with an unregistered handler', () => { | ||
const dispatcher = new EventDispatcher(); | ||
const handler1 = jest.fn(); | ||
const handler1 = fake(); | ||
dispatcher.remove(handler1); | ||
} | ||
catch (e) { | ||
assert(false, 'should not throw'); | ||
assert.fail('should not throw'); | ||
} | ||
assert(true, 'did not throw'); | ||
assert.pass('did not throw'); | ||
}); | ||
}); | ||
//# sourceMappingURL=EventDispatcher.tests.js.map |
@@ -0,1 +1,2 @@ | ||
/* eslint-disable @typescript-eslint/no-unused-expressions */ | ||
/** | ||
@@ -7,3 +8,13 @@ * ------------------------------------------------------------------------------------------- | ||
*/ | ||
import { it } from '@jest/globals'; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
import { expect } from '@open-wc/testing'; | ||
import { fake } from 'sinon'; | ||
import { AuthenticationHandlerOptions } from '@microsoft/microsoft-graph-client'; | ||
@@ -16,25 +27,26 @@ import { MockProvider } from '../mock/MockProvider'; | ||
describe('GraphHelpers - prepScopes', () => { | ||
it('should return an empty array when incremental consent is disabled', () => { | ||
it('should return an empty array when incremental consent is disabled', () => __awaiter(void 0, void 0, void 0, function* () { | ||
const scopes = ['scope1', 'scope2']; | ||
Providers.globalProvider = new MockProvider(true); | ||
Providers.globalProvider.isIncrementalConsentDisabled = true; | ||
expect(prepScopes(...scopes)).toEqual([]); | ||
}); | ||
it('should return an array of AuthenticationHandlerOptions when incremental consent is enabled', () => { | ||
// eql for loose equality | ||
yield expect(prepScopes(...scopes)).to.eql([]); | ||
})); | ||
it('should return an array of AuthenticationHandlerOptions when incremental consent is enabled', () => __awaiter(void 0, void 0, void 0, function* () { | ||
const scopes = ['scope1', 'scope2']; | ||
Providers.globalProvider = new MockProvider(true); | ||
Providers.globalProvider.isIncrementalConsentDisabled = false; | ||
expect(prepScopes(...scopes)).toEqual([new AuthenticationHandlerOptions(undefined, { scopes })]); | ||
}); | ||
yield expect(prepScopes(...scopes)).to.eql([new AuthenticationHandlerOptions(undefined, { scopes })]); | ||
})); | ||
}); | ||
describe('GraphHelpers - chainMiddleware', () => { | ||
it('should return the first middleware when only one is passed', () => { | ||
const middleware = [{ execute: jest.fn(), setNext: jest.fn() }]; | ||
it('should return the first middleware when only one is passed', () => __awaiter(void 0, void 0, void 0, function* () { | ||
const middleware = [{ execute: fake(), setNext: fake() }]; | ||
const result = chainMiddleware(...middleware); | ||
expect(result).toEqual(middleware[0]); | ||
}); | ||
yield expect(result).to.equal(middleware[0]); | ||
})); | ||
it('should return undefined when the middleware array is empty', () => { | ||
const middleware = []; | ||
const result = chainMiddleware(...middleware); | ||
expect(result).toBeUndefined(); | ||
expect(result).to.be.undefined; | ||
}); | ||
@@ -45,3 +57,3 @@ it('should now throw when the middleware array is undefined', () => { | ||
const result = chainMiddleware(undefined); | ||
expect(result).toBeUndefined(); | ||
expect(result).to.be.undefined; | ||
} | ||
@@ -51,22 +63,31 @@ catch (e) { | ||
} | ||
expect(error).toBeUndefined(); | ||
expect(error).to.be.undefined; | ||
}); | ||
}); | ||
describe('GraphHelpers - validateBaseUrl', () => { | ||
it.each([ | ||
'https://graph.microsoft.com', | ||
'https://graph.microsoft.us', | ||
'https://dod-graph.microsoft.us', | ||
'https://graph.microsoft.de', | ||
'https://microsoftgraph.chinacloudapi.cn' | ||
])('should return %p as a valid base url', (graphUrl) => { | ||
expect(validateBaseURL(graphUrl)).toBe(graphUrl); | ||
it('should return as a valid Url', () => __awaiter(void 0, void 0, void 0, function* () { | ||
const validUrls = [ | ||
'https://graph.microsoft.com', | ||
'https://graph.microsoft.us', | ||
'https://dod-graph.microsoft.us', | ||
'https://graph.microsoft.de', | ||
'https://microsoftgraph.chinacloudapi.cn' | ||
]; | ||
for (const url of validUrls) { | ||
yield expect(validateBaseURL(url)).to.equal(url); | ||
} | ||
})); | ||
it('should return undefeined for invalid Url', () => { | ||
const validUrls = ['https://graph.microsoft.net', 'https://random.us', 'https://nope.cn']; | ||
for (const url of validUrls) { | ||
expect(validateBaseURL(url)).to.be.undefined; | ||
} | ||
}); | ||
it.each(['https://graph.microsoft.net', 'https://random.us', 'https://nope.cn'])('should return undefined for %p as an invalid base url', (graphUrl) => { | ||
expect(validateBaseURL(graphUrl)).toBeUndefined(); | ||
it('should return undefined for when supplied a %p which is not a well formed url', () => { | ||
const testValues = ['not a url', 'graph.microsoft.com']; | ||
for (const test of testValues) { | ||
expect(validateBaseURL(test)).to.be.undefined; | ||
} | ||
}); | ||
it.each(['not a url', 'graph.microsoft.com'])('should return undefined for when supplied a %p which is not a well formed url', (input) => { | ||
expect(validateBaseURL(input)).toBeUndefined(); | ||
}); | ||
}); | ||
//# sourceMappingURL=GraphHelpers.tests.js.map |
@@ -7,3 +7,3 @@ /** | ||
*/ | ||
export declare const PACKAGE_VERSION = "3.1.3-next.enable-tree-shaking.d405e0b"; | ||
export declare const PACKAGE_VERSION = "3.1.3-next.mgt-chat.4702515"; | ||
//# sourceMappingURL=version.d.ts.map |
@@ -9,3 +9,3 @@ /** | ||
// ANY CHANGES WILL BE LOST DURING BUILD | ||
export const PACKAGE_VERSION = '3.1.3-next.enable-tree-shaking.d405e0b'; | ||
export const PACKAGE_VERSION = '3.1.3-next.mgt-chat.4702515'; | ||
//# sourceMappingURL=version.js.map |
{ | ||
"name": "@microsoft/mgt-element", | ||
"version": "3.1.3-next.enable-tree-shaking.d405e0b", | ||
"version": "3.1.3-next.mgt-chat.4702515", | ||
"description": "Microsoft Graph Toolkit base classes", | ||
@@ -5,0 +5,0 @@ "homepage": "https://github.com/microsoftgraph/microsoft-graph-toolkit", |
@@ -27,3 +27,4 @@ # Microsoft Graph Toolkit Base package | ||
import {Providers} from '@microsoft/mgt-element'; | ||
import {Msal2Provider} from '@microsoft/mgt-msal2-provider'; | ||
// importing via the export path will exclude the custom element for <mgt-msal2-proivder> from the final bundle | ||
import {Msal2Provider} from '@microsoft/mgt-msal2-provider/dist/es6/exports'; | ||
@@ -30,0 +31,0 @@ // initialize the auth provider globally |
@@ -92,4 +92,4 @@ /** | ||
*/ | ||
public forComponent(component: Element | string): Graph { | ||
const graph = new Graph(this._client, this._version); | ||
public forComponent(component: Element | string, version?: string): Graph { | ||
const graph = new Graph(this._client, version || this._version); | ||
graph.setComponent(component); | ||
@@ -151,3 +151,3 @@ return graph; | ||
*/ | ||
export const createFromProvider = (provider: IProvider, version?: string, component?: Element): Graph => { | ||
export const createFromProvider = (provider: IProvider, version?: string, component?: Element | string): Graph => { | ||
const middleware: Middleware[] = [ | ||
@@ -154,0 +154,0 @@ new AuthenticationHandler(provider), |
@@ -50,3 +50,3 @@ /** | ||
*/ | ||
forComponent(component: Element): IGraph; | ||
forComponent(component: Element | string, version?: string): IGraph; | ||
@@ -53,0 +53,0 @@ /** |
@@ -22,7 +22,4 @@ /** | ||
export * from './utils/CacheItem'; | ||
export * from './utils/CacheSchema'; | ||
export * from './utils/CacheService'; | ||
export * from './utils/CacheStore'; | ||
export * from './utils/dbListKey'; | ||
export * from './utils/EventDispatcher'; | ||
@@ -40,2 +37,5 @@ export * from './utils/equals'; | ||
export * from './utils/CustomElement'; | ||
export * from './utils/Logging'; | ||
export * from './utils/registerComponent'; | ||
export { PACKAGE_VERSION } from './utils/version'; | ||
@@ -42,0 +42,0 @@ |
@@ -65,3 +65,3 @@ /** | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
public forComponent(component: MgtBaseComponent): MockGraph { | ||
public forComponent(component: MgtBaseComponent | string): MockGraph { | ||
// The purpose of the forComponent pattern is to update the headers of any outgoing Graph requests. | ||
@@ -68,0 +68,0 @@ // The MockGraph isn't making real Graph requests, so we can simply no-op and return the same instance. |
@@ -14,3 +14,3 @@ /** | ||
/** | ||
* Provider Type to be extended for implmenting new providers | ||
* Provider Type to be extended for implementing new providers | ||
* | ||
@@ -165,3 +165,3 @@ * @export | ||
this._state = state; | ||
this._loginChangedDispatcher.fire({}); | ||
this._loginChangedDispatcher.fire({ detail: this._state }); | ||
} | ||
@@ -229,3 +229,3 @@ } | ||
public setActiveAccount?(user: IProviderAccount) { | ||
this.fireActiveAccountChanged(); | ||
this.fireActiveAccountChanged({ detail: user }); | ||
} | ||
@@ -258,4 +258,4 @@ | ||
*/ | ||
private fireActiveAccountChanged() { | ||
this._activeAccountChangedDispatcher.fire({}); | ||
private fireActiveAccountChanged(account: { detail: IProviderAccount }) { | ||
this._activeAccountChangedDispatcher.fire(account); | ||
} | ||
@@ -292,3 +292,5 @@ | ||
// eslint-disable-next-line @typescript-eslint/no-empty-interface | ||
export interface ActiveAccountChanged {} | ||
export interface ActiveAccountChanged { | ||
detail: IProviderAccount; | ||
} | ||
/** | ||
@@ -301,3 +303,5 @@ * loginChangedEvent | ||
// eslint-disable-next-line @typescript-eslint/no-empty-interface | ||
export interface LoginChangedEvent {} | ||
export interface LoginChangedEvent { | ||
detail: ProviderState; | ||
} | ||
@@ -304,0 +308,0 @@ /** |
@@ -10,3 +10,3 @@ /** | ||
import { BatchRequestContent, MiddlewareOptions } from '@microsoft/microsoft-graph-client'; | ||
import { delay } from '../utils'; | ||
import { delay } from './delay'; | ||
import { prepScopes } from './prepScopes'; | ||
@@ -13,0 +13,0 @@ import { IGraph } from '../IGraph'; |
@@ -11,7 +11,14 @@ /** | ||
import { CacheStore } from './CacheStore'; | ||
import { CacheSchema } from './CacheSchema'; | ||
import { CacheItem } from './CacheItem'; | ||
import { dbListKey } from './dbListKey'; | ||
import { error } from './Logging'; | ||
/** | ||
* Localstorage key for storing names of cache databases | ||
* | ||
* @type {string} | ||
* | ||
*/ | ||
export const dbListKey = 'mgt-db-list'; | ||
/** | ||
* Holds the cache options for cache store | ||
@@ -96,2 +103,9 @@ * | ||
fileLists: CacheOptions; | ||
/** | ||
* Cache options for conversation store | ||
* | ||
* @type {CacheOptions} | ||
* @memberof CacheConfig | ||
*/ | ||
conversation: CacheOptions; | ||
} | ||
@@ -171,3 +185,3 @@ | ||
delReq.onerror = () => { | ||
console.error(`🦒: ${delReq.error.name} occurred deleting cache: ${x}`, delReq.error.message); | ||
error(`${delReq.error.name} occurred deleting cache: ${x}`, delReq.error.message); | ||
reject(); | ||
@@ -227,2 +241,6 @@ }; | ||
isEnabled: true | ||
}, | ||
conversation: { | ||
invalidationPeriod: 5 * 24 * 60 * 60 * 1000, | ||
isEnabled: true | ||
} | ||
@@ -270,1 +288,58 @@ }; | ||
} | ||
export interface Index { | ||
name: string; | ||
field: string; | ||
} | ||
/** | ||
* Represents organization for a cache | ||
* | ||
* @export | ||
* @interface CacheSchema | ||
*/ | ||
export interface CacheSchema { | ||
/** | ||
* version number of cache, useful for upgrading | ||
* | ||
* @type {number} | ||
* @memberof CacheSchema | ||
*/ | ||
version: number; | ||
/** | ||
* name of the cache | ||
* | ||
* @type {string} | ||
* @memberof CacheSchema | ||
*/ | ||
name: string; | ||
/** | ||
* list of stores in the cache | ||
* | ||
* @type {{ [name: string]: CacheSchemaStore }} | ||
* @memberof CacheSchema | ||
*/ | ||
stores: Record<string, string>; | ||
/** | ||
* Optional field to define indexed fields on a per store basis | ||
* K is the name of the store for which the indexes should be applied | ||
* T is the names of the fields on the stored data to be indexed | ||
*/ | ||
indexes?: Record<string, Index[]>; | ||
} | ||
/** | ||
* item that is stored in cache | ||
* | ||
* @export | ||
* @interface CacheItem | ||
*/ | ||
export interface CacheItem { | ||
/** | ||
* date and time that item was retrieved from api/stored in cache | ||
* | ||
* @type {number} | ||
* @memberof CacheItem | ||
*/ | ||
timeCached?: number; | ||
} |
@@ -10,5 +10,3 @@ /** | ||
import { Providers } from '../providers/Providers'; | ||
import { dbListKey } from './dbListKey'; | ||
import { CacheItem } from './CacheItem'; | ||
import { CacheSchema } from './CacheSchema'; | ||
import { CacheItem, CacheSchema, Index, dbListKey } from './CacheService'; | ||
@@ -42,3 +40,3 @@ /** | ||
*/ | ||
public async getValue(key: string): Promise<T> { | ||
public async getValue(key: string): Promise<T | null> { | ||
if (!window.indexedDB) { | ||
@@ -56,2 +54,21 @@ return null; | ||
/** | ||
* removes a value from the cache for the given key | ||
* | ||
* @param {string} key | ||
* @returns {Promise<void>} | ||
* @memberof Cache | ||
*/ | ||
public async delete(key: string): Promise<void> { | ||
if (!window.indexedDB) { | ||
return; | ||
} | ||
try { | ||
const db = await this.getDb(); | ||
return db.delete(this.store, key); | ||
} catch (e) { | ||
return; | ||
} | ||
} | ||
/** | ||
* inserts value into cache for the given key | ||
@@ -107,3 +124,3 @@ * | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
upgrade: (db, _oldVersion, _newVersion, _transaction) => { | ||
upgrade: (db, _oldVersion, _newVersion, transaction) => { | ||
const dbArray: string[] = (JSON.parse(localStorage.getItem(dbListKey)) as string[]) || []; | ||
@@ -115,7 +132,17 @@ if (!dbArray.includes(dbName)) { | ||
for (const storeName in this.schema.stores) { | ||
if ( | ||
Object.prototype.hasOwnProperty.call(this.schema.stores, storeName) && | ||
!db.objectStoreNames.contains(storeName) | ||
) { | ||
db.createObjectStore(storeName); | ||
if (Object.prototype.hasOwnProperty.call(this.schema.stores, storeName)) { | ||
const indexes: Index[] = this.schema.indexes?.[storeName] ?? []; | ||
if (!db.objectStoreNames.contains(storeName)) { | ||
const objectStore = db.createObjectStore(storeName); | ||
indexes.forEach(i => { | ||
objectStore.createIndex(i.name, i.field); | ||
}); | ||
} else { | ||
const store = transaction.objectStore(storeName); | ||
indexes.forEach(i => { | ||
if (store && !store.indexNames.contains(i.name)) { | ||
store.createIndex(i.name, i.field); | ||
} | ||
}); | ||
} | ||
} | ||
@@ -127,2 +154,7 @@ } | ||
} | ||
public async queryDb(indexName: string, query: IDBKeyRange | IDBValidKey): Promise<T[]> { | ||
const db = await this.getDb(); | ||
return (await db.getAllFromIndex(this.store, indexName, query)) as T[]; | ||
} | ||
} |
@@ -10,2 +10,3 @@ /** | ||
import { customElementHelper } from '../components/customElementHelper'; | ||
import { error } from './Logging'; | ||
@@ -30,4 +31,4 @@ /** | ||
// eslint-disable-next-line no-console | ||
console.error( | ||
`🦒: Tag name ${mgtTagName} is already defined using class ${mgtElement.name} version ${version(mgtElement)}\n`, | ||
error( | ||
`Tag name ${mgtTagName} is already defined using class ${mgtElement.name} version ${version(mgtElement)}\n`, | ||
`Currently registering class ${classOrDescriptor.name} with version ${version(classOrDescriptor)}\n`, | ||
@@ -34,0 +35,0 @@ 'Please use the disambiguation feature to define a unique tag name for this component see: https://github.com/microsoftgraph/microsoft-graph-toolkit/tree/main/packages/mgt-components#disambiguation' |
@@ -0,1 +1,2 @@ | ||
/* eslint-disable @typescript-eslint/no-unused-expressions */ | ||
/** | ||
@@ -7,4 +8,3 @@ * ------------------------------------------------------------------------------------------- | ||
*/ | ||
import { it } from '@jest/globals'; | ||
import { expect } from '@open-wc/testing'; | ||
import { equals } from './equals'; | ||
@@ -22,34 +22,40 @@ | ||
it.each([ | ||
[{}, {}], | ||
[ | ||
{ a: 1, b: true, c: 'foo' }, | ||
{ c: 'foo', b: true, a: 1 } | ||
], | ||
[{ a: [1, 2, 3] }, { a: [1, 2, 3] }], | ||
[{ a: { b: { c: 1 } } }, { a: { b: { c: 1 } } }], | ||
[{ a: [1, [2, [3]]] }, { a: [1, [2, [3]]] }], | ||
[circularObject, circularObject], | ||
[circularObject, { a: circularObject }], | ||
[circularArray, circularArray], | ||
[ | ||
{ a: circularObject, b: circularArray }, | ||
{ a: circularObject, b: circularArray } | ||
], | ||
[{ a: simpleDate }, { a: simpleDate }] | ||
])('should return true between %p and %p', (o1: unknown, o2: unknown) => { | ||
expect(equals(o1, o2)).toBe(true); | ||
it('should return true', () => { | ||
const testValues = [ | ||
[{}, {}], | ||
[ | ||
{ a: 1, b: true, c: 'foo' }, | ||
{ c: 'foo', b: true, a: 1 } | ||
], | ||
[{ a: [1, 2, 3] }, { a: [1, 2, 3] }], | ||
[{ a: { b: { c: 1 } } }, { a: { b: { c: 1 } } }], | ||
[{ a: [1, [2, [3]]] }, { a: [1, [2, [3]]] }], | ||
[circularObject, circularObject], | ||
[circularObject, { a: circularObject }], | ||
[circularArray, circularArray], | ||
[ | ||
{ a: circularObject, b: circularArray }, | ||
{ a: circularObject, b: circularArray } | ||
], | ||
[{ a: simpleDate }, { a: simpleDate }] | ||
]; | ||
for (const [o1, o2] of testValues) { | ||
expect(equals(o1, o2)).to.be.true; | ||
} | ||
}); | ||
it.each([ | ||
[{ a: {} }, { a: [] }], | ||
[{ a: [1, 2, 3] }, { a: [3, 2, 1] }], | ||
[{ a: [1, [2, [3]]] }, { a: [1, [2, [4]]] }], | ||
[{ a: { b: [{ c: 1 }, { d: [2, 3] }] } }, { a: { b: [{ c: 1 }, { d: [3, 2] }] } }], | ||
[{ a: new Date() }, { a: new Date() }], | ||
[circularObject, circularArray], | ||
[circularObject, { b: circularObject }] | ||
])('should return false between %p and %p', (o1: unknown, o2: unknown) => { | ||
expect(equals(o1, o2)).toBe(false); | ||
it('should return false ', () => { | ||
const testValues = [ | ||
[{ a: {} }, { a: [] }], | ||
[{ a: [1, 2, 3] }, { a: [3, 2, 1] }], | ||
[{ a: [1, [2, [3]]] }, { a: [1, [2, [4]]] }], | ||
[{ a: { b: [{ c: 1 }, { d: [2, 3] }] } }, { a: { b: [{ c: 1 }, { d: [3, 2] }] } }], | ||
[{ a: new Date() }, { a: new Date() }], | ||
[circularObject, circularArray], | ||
[circularObject, { b: circularObject }] | ||
]; | ||
for (const [o1, o2] of testValues) { | ||
expect(equals(o1, o2)).to.be.false; | ||
} | ||
}); | ||
}); |
@@ -8,31 +8,36 @@ /** | ||
import { it } from '@jest/globals'; | ||
import { assert } from 'console'; | ||
import { EventDispatcher } from './EventDispatcher'; | ||
import { assert, restore, fake } from 'sinon'; | ||
describe('EventDispatcher tests', () => { | ||
afterEach(() => { | ||
// Restore the default sandbox here | ||
restore(); | ||
}); | ||
it('should add and remove event handlers', () => { | ||
const dispatcher = new EventDispatcher(); | ||
const handler1 = jest.fn(); | ||
const handler2 = jest.fn(); | ||
const handler1 = fake(); | ||
const handler2 = fake(); | ||
dispatcher.add(handler1); | ||
dispatcher.add(handler2); | ||
dispatcher.fire('event'); | ||
expect(handler1).toHaveBeenCalledTimes(1); | ||
expect(handler2).toHaveBeenCalledTimes(1); | ||
assert.calledOnce(handler1); | ||
assert.calledOnce(handler2); | ||
dispatcher.remove(handler1); | ||
dispatcher.fire('event'); | ||
expect(handler1).toHaveBeenCalledTimes(1); | ||
expect(handler2).toHaveBeenCalledTimes(2); | ||
assert.calledOnce(handler1); | ||
assert.callCount(handler2, 2); | ||
}); | ||
it('should not throw when remove is called with an unregistered handler', () => { | ||
try { | ||
const dispatcher = new EventDispatcher(); | ||
const handler1 = jest.fn(); | ||
const handler1 = fake(); | ||
dispatcher.remove(handler1); | ||
} catch (e) { | ||
assert(false, 'should not throw'); | ||
assert.fail('should not throw'); | ||
} | ||
assert(true, 'did not throw'); | ||
assert.pass('did not throw'); | ||
}); | ||
}); |
@@ -0,1 +1,2 @@ | ||
/* eslint-disable @typescript-eslint/no-unused-expressions */ | ||
/** | ||
@@ -8,3 +9,4 @@ * ------------------------------------------------------------------------------------------- | ||
import { it } from '@jest/globals'; | ||
import { expect } from '@open-wc/testing'; | ||
import { fake } from 'sinon'; | ||
import { AuthenticationHandlerOptions, Middleware } from '@microsoft/microsoft-graph-client'; | ||
@@ -18,13 +20,14 @@ import { MockProvider } from '../mock/MockProvider'; | ||
describe('GraphHelpers - prepScopes', () => { | ||
it('should return an empty array when incremental consent is disabled', () => { | ||
it('should return an empty array when incremental consent is disabled', async () => { | ||
const scopes = ['scope1', 'scope2']; | ||
Providers.globalProvider = new MockProvider(true); | ||
Providers.globalProvider.isIncrementalConsentDisabled = true; | ||
expect(prepScopes(...scopes)).toEqual([]); | ||
// eql for loose equality | ||
await expect(prepScopes(...scopes)).to.eql([]); | ||
}); | ||
it('should return an array of AuthenticationHandlerOptions when incremental consent is enabled', () => { | ||
it('should return an array of AuthenticationHandlerOptions when incremental consent is enabled', async () => { | ||
const scopes = ['scope1', 'scope2']; | ||
Providers.globalProvider = new MockProvider(true); | ||
Providers.globalProvider.isIncrementalConsentDisabled = false; | ||
expect(prepScopes(...scopes)).toEqual([new AuthenticationHandlerOptions(undefined, { scopes })]); | ||
await expect(prepScopes(...scopes)).to.eql([new AuthenticationHandlerOptions(undefined, { scopes })]); | ||
}); | ||
@@ -34,6 +37,6 @@ }); | ||
describe('GraphHelpers - chainMiddleware', () => { | ||
it('should return the first middleware when only one is passed', () => { | ||
const middleware: Middleware[] = [{ execute: jest.fn(), setNext: jest.fn() }]; | ||
it('should return the first middleware when only one is passed', async () => { | ||
const middleware: Middleware[] = [{ execute: fake(), setNext: fake() }]; | ||
const result = chainMiddleware(...middleware); | ||
expect(result).toEqual(middleware[0]); | ||
await expect(result).to.equal(middleware[0]); | ||
}); | ||
@@ -44,3 +47,3 @@ | ||
const result = chainMiddleware(...middleware); | ||
expect(result).toBeUndefined(); | ||
expect(result).to.be.undefined; | ||
}); | ||
@@ -51,7 +54,7 @@ it('should now throw when the middleware array is undefined', () => { | ||
const result = chainMiddleware(undefined); | ||
expect(result).toBeUndefined(); | ||
expect(result).to.be.undefined; | ||
} catch (e) { | ||
error = 'thrown and caught'; | ||
} | ||
expect(error).toBeUndefined(); | ||
expect(error).to.be.undefined; | ||
}); | ||
@@ -61,23 +64,27 @@ }); | ||
describe('GraphHelpers - validateBaseUrl', () => { | ||
it.each([ | ||
'https://graph.microsoft.com', | ||
'https://graph.microsoft.us', | ||
'https://dod-graph.microsoft.us', | ||
'https://graph.microsoft.de', | ||
'https://microsoftgraph.chinacloudapi.cn' | ||
])('should return %p as a valid base url', (graphUrl: string) => { | ||
expect(validateBaseURL(graphUrl)).toBe(graphUrl); | ||
it('should return as a valid Url', async () => { | ||
const validUrls = [ | ||
'https://graph.microsoft.com', | ||
'https://graph.microsoft.us', | ||
'https://dod-graph.microsoft.us', | ||
'https://graph.microsoft.de', | ||
'https://microsoftgraph.chinacloudapi.cn' | ||
]; | ||
for (const url of validUrls) { | ||
await expect(validateBaseURL(url)).to.equal(url); | ||
} | ||
}); | ||
it.each(['https://graph.microsoft.net', 'https://random.us', 'https://nope.cn'])( | ||
'should return undefined for %p as an invalid base url', | ||
(graphUrl: string) => { | ||
expect(validateBaseURL(graphUrl)).toBeUndefined(); | ||
it('should return undefeined for invalid Url', () => { | ||
const validUrls = ['https://graph.microsoft.net', 'https://random.us', 'https://nope.cn']; | ||
for (const url of validUrls) { | ||
expect(validateBaseURL(url)).to.be.undefined; | ||
} | ||
); | ||
it.each(['not a url', 'graph.microsoft.com'])( | ||
'should return undefined for when supplied a %p which is not a well formed url', | ||
(input: string) => { | ||
expect(validateBaseURL(input)).toBeUndefined(); | ||
}); | ||
it('should return undefined for when supplied a %p which is not a well formed url', () => { | ||
const testValues = ['not a url', 'graph.microsoft.com']; | ||
for (const test of testValues) { | ||
expect(validateBaseURL(test)).to.be.undefined; | ||
} | ||
); | ||
}); | ||
}); |
@@ -11,2 +11,2 @@ /** | ||
export const PACKAGE_VERSION = '3.1.3-next.enable-tree-shaking.d405e0b'; | ||
export const PACKAGE_VERSION = '3.1.3-next.mgt-chat.4702515'; |
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
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
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
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
662094
228
10214
95