@microsoft/mgt-element
Advanced tools
Comparing version 3.1.3-next.mgt-chat.f278f22 to 3.1.3-next.mgt-without-loader.701821d
@@ -8,2 +8,3 @@ /** | ||
import { LitElement, PropertyValueMap, PropertyValues } from 'lit'; | ||
import { ProviderState } from '../providers/IProvider'; | ||
/** | ||
@@ -36,4 +37,6 @@ * Defines media query based on component width | ||
* @extends {LitElement} | ||
* @deprecated Use MgtBaseTaskComponent instead | ||
*/ | ||
export declare abstract class MgtBaseComponent extends LitElement { | ||
protected providerState: ProviderState; | ||
/** | ||
@@ -40,0 +43,0 @@ * Exposes the semver of the library the component is part of |
@@ -59,2 +59,3 @@ /** | ||
* @extends {LitElement} | ||
* @deprecated Use MgtBaseTaskComponent instead | ||
*/ | ||
@@ -122,2 +123,3 @@ export class MgtBaseComponent extends LitElement { | ||
super(); | ||
this.providerState = ProviderState.Loading; | ||
/** | ||
@@ -145,2 +147,4 @@ * Gets or sets the direction of the component | ||
this.handleProviderUpdates = () => { | ||
var _a, _b; | ||
this.providerState = (_b = (_a = Providers.globalProvider) === null || _a === void 0 ? void 0 : _a.state) !== null && _b !== void 0 ? _b : ProviderState.Loading; | ||
void this.requestStateUpdate(); | ||
@@ -318,4 +322,8 @@ }; | ||
state(), | ||
__metadata("design:type", Number) | ||
], MgtBaseComponent.prototype, "providerState", void 0); | ||
__decorate([ | ||
state(), | ||
__metadata("design:type", String) | ||
], MgtBaseComponent.prototype, "direction", void 0); | ||
//# sourceMappingURL=baseComponent.js.map |
@@ -13,3 +13,3 @@ /** | ||
* | ||
* @param {string} disambiguation | ||
* @param {string} disambiguation the disambiguation value to be used, should be lowercase | ||
* @return {CustomElementHelper} the current object | ||
@@ -16,0 +16,0 @@ * @memberof CustomElementHelper |
@@ -17,3 +17,3 @@ /** | ||
* | ||
* @param {string} disambiguation | ||
* @param {string} disambiguation the disambiguation value to be used, should be lowercase | ||
* @return {CustomElementHelper} the current object | ||
@@ -23,4 +23,7 @@ * @memberof CustomElementHelper | ||
withDisambiguation(disambiguation) { | ||
if (disambiguation && !this._disambiguation) | ||
this._disambiguation = disambiguation; | ||
if (disambiguation && !this._disambiguation) { | ||
this._disambiguation = disambiguation.toLowerCase(); | ||
if (disambiguation !== this._disambiguation) | ||
console.warn(`🦒: Disambiguation value, ${disambiguation}, should be lowercase. Value has been converted to lowercase, ${this._disambiguation}.`); | ||
} | ||
return this; | ||
@@ -27,0 +30,0 @@ } |
@@ -10,2 +10,15 @@ /** | ||
import { TemplateContext } from '../utils/TemplateContext'; | ||
/** | ||
* Lookup for rendered component templates and contexts by slot name. | ||
*/ | ||
export type RenderedTemplates = Record<string, { | ||
/** | ||
* Reference to the data context used to render the slot. | ||
*/ | ||
context: Record<string, unknown>; | ||
/** | ||
* Reference to the rendered DOM element corresponding to the slot. | ||
*/ | ||
slot: HTMLElement; | ||
}>; | ||
export interface TemplateRenderedData { | ||
@@ -16,3 +29,3 @@ templateType: string; | ||
} | ||
type OrderedHtmlTemplate = HTMLTemplateElement & { | ||
export type OrderedHtmlTemplate = HTMLTemplateElement & { | ||
templateOrder: number; | ||
@@ -27,2 +40,3 @@ }; | ||
* @extends {MgtBaseComponent} | ||
* @deprecated Use MgtTemplatedTaskComponent instead | ||
* | ||
@@ -104,3 +118,2 @@ * @fires {CustomEvent<MgtElement.TemplateRenderedData>} templateRendered - fires when a template is rendered | ||
} | ||
export {}; | ||
//# sourceMappingURL=templatedComponent.d.ts.map |
@@ -28,2 +28,3 @@ /** | ||
* @extends {MgtBaseComponent} | ||
* @deprecated Use MgtTemplatedTaskComponent instead | ||
* | ||
@@ -30,0 +31,0 @@ * @fires {CustomEvent<MgtElement.TemplateRenderedData>} templateRendered - fires when a template is rendered |
@@ -55,3 +55,3 @@ /** | ||
*/ | ||
forComponent(component: Element | string, version?: string): Graph; | ||
forComponent(component: Element | 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 | string) => Graph; | ||
export declare const createFromProvider: (provider: IProvider, version?: string, component?: Element) => Graph; | ||
//# sourceMappingURL=Graph.d.ts.map |
@@ -69,4 +69,4 @@ /** | ||
*/ | ||
forComponent(component, version) { | ||
const graph = new Graph(this._client, version || this._version); | ||
forComponent(component) { | ||
const graph = new Graph(this._client, this._version); | ||
graph.setComponent(component); | ||
@@ -86,3 +86,3 @@ return graph; | ||
request.middlewareOptions = (options) => { | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call, @typescript-eslint/dot-notation | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/dot-notation | ||
request['_middlewareOptions'] = request['_middlewareOptions'].concat(options); | ||
@@ -89,0 +89,0 @@ return request; |
@@ -45,3 +45,3 @@ /** | ||
*/ | ||
forComponent(component: Element | string, version?: string): IGraph; | ||
forComponent(component: Element): IGraph; | ||
/** | ||
@@ -48,0 +48,0 @@ * use this method to make calls directly to the Graph. |
@@ -13,3 +13,5 @@ /** | ||
export * from './components/baseProvider'; | ||
export * from './components/baseTaskComponent'; | ||
export * from './components/templatedComponent'; | ||
export * from './components/templatedTaskComponent'; | ||
export * from './components/customElementHelper'; | ||
@@ -19,4 +21,7 @@ export * from './providers/IProvider'; | ||
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'; | ||
@@ -34,3 +39,2 @@ export * from './utils/equals'; | ||
export * from './utils/CustomElement'; | ||
export * from './utils/Logging'; | ||
export * from './utils/registerComponent'; | ||
@@ -37,0 +41,0 @@ export { PACKAGE_VERSION } from './utils/version'; |
@@ -13,3 +13,5 @@ /** | ||
export * from './components/baseProvider'; | ||
export * from './components/baseTaskComponent'; | ||
export * from './components/templatedComponent'; | ||
export * from './components/templatedTaskComponent'; | ||
export * from './components/customElementHelper'; | ||
@@ -19,4 +21,7 @@ export * from './providers/IProvider'; | ||
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'; | ||
@@ -34,3 +39,2 @@ export * from './utils/equals'; | ||
export * from './utils/CustomElement'; | ||
export * from './utils/Logging'; | ||
export * from './utils/registerComponent'; | ||
@@ -37,0 +41,0 @@ export { PACKAGE_VERSION } from './utils/version'; |
@@ -34,4 +34,4 @@ /** | ||
*/ | ||
forComponent(component: MgtBaseComponent | string): MockGraph; | ||
forComponent(component: MgtBaseComponent): MockGraph; | ||
} | ||
//# sourceMappingURL=MockGraph.d.ts.map |
@@ -90,5 +90,5 @@ /** | ||
static setBaseFallbackUrl() { | ||
this._baseUrl = 'https://proxy.apisandbox.msdn.microsoft.com/svc?url='; | ||
this._baseUrl = 'https://graph.office.net/en-us/graph/api/proxy?url='; | ||
} | ||
} | ||
//# sourceMappingURL=MockMiddleware.js.map |
@@ -46,3 +46,15 @@ /** | ||
private _baseURL; | ||
private _approvedScopes; | ||
get approvedScopes(): string[]; | ||
set approvedScopes(value: string[]); | ||
hasAtLeastOneApprovedScope(requiredScopeSet: string[]): boolean; | ||
hasAllOneApprovedScope(requiredScopeSet: string[]): boolean; | ||
/** | ||
* Examines the currently consented scopes for any match in the requiredScopeSet to determine what, if any, scopes need to be consented to | ||
* | ||
* @param {string[]} requiredScopeSet an array of scopes to be checked | ||
* @returns {string[]} if any matches in requiredScopeSet exist then an empty array is returns, otherwise an array containing the first element in the requiredScopeSet is returned | ||
*/ | ||
needsAdditionalScopes(requiredScopeSet: string[]): string[]; | ||
/** | ||
* The base URL to be used in the graph client config. | ||
@@ -212,3 +224,2 @@ */ | ||
export interface ActiveAccountChanged { | ||
detail: IProviderAccount; | ||
} | ||
@@ -222,3 +233,2 @@ /** | ||
export interface LoginChangedEvent { | ||
detail: ProviderState; | ||
} | ||
@@ -225,0 +235,0 @@ /** |
@@ -29,3 +29,28 @@ /** | ||
} | ||
get approvedScopes() { | ||
return this._approvedScopes; | ||
} | ||
set approvedScopes(value) { | ||
this._approvedScopes = value.map(v => v.toLowerCase()); | ||
} | ||
hasAtLeastOneApprovedScope(requiredScopeSet) { | ||
return requiredScopeSet.some(s => this.approvedScopes.includes(s.toLowerCase().trim())); | ||
} | ||
hasAllOneApprovedScope(requiredScopeSet) { | ||
return requiredScopeSet.some(s => !this.approvedScopes.includes(s.toLowerCase().trim())); | ||
} | ||
/** | ||
* Examines the currently consented scopes for any match in the requiredScopeSet to determine what, if any, scopes need to be consented to | ||
* | ||
* @param {string[]} requiredScopeSet an array of scopes to be checked | ||
* @returns {string[]} if any matches in requiredScopeSet exist then an empty array is returns, otherwise an array containing the first element in the requiredScopeSet is returned | ||
*/ | ||
needsAdditionalScopes(requiredScopeSet) { | ||
const reqScopes = []; | ||
if (requiredScopeSet.length && !this.hasAtLeastOneApprovedScope(requiredScopeSet)) { | ||
reqScopes.push(requiredScopeSet[0].trim()); | ||
} | ||
return reqScopes; | ||
} | ||
/** | ||
* The base URL to be used in the graph client config. | ||
@@ -113,2 +138,3 @@ */ | ||
this._baseURL = MICROSOFT_GRAPH_DEFAULT_ENDPOINT; | ||
this._approvedScopes = []; | ||
this._customHosts = undefined; | ||
@@ -141,3 +167,3 @@ /** | ||
this._state = state; | ||
this._loginChangedDispatcher.fire({ detail: this._state }); | ||
this._loginChangedDispatcher.fire({}); | ||
} | ||
@@ -171,3 +197,3 @@ } | ||
setActiveAccount(user) { | ||
this.fireActiveAccountChanged({ detail: user }); | ||
this.fireActiveAccountChanged(); | ||
} | ||
@@ -197,4 +223,4 @@ /** | ||
*/ | ||
fireActiveAccountChanged(account) { | ||
this._activeAccountChangedDispatcher.fire(account); | ||
fireActiveAccountChanged() { | ||
this._activeAccountChangedDispatcher.fire({}); | ||
} | ||
@@ -201,0 +227,0 @@ /** |
@@ -36,3 +36,5 @@ /** | ||
* @param {string} resource | ||
* @param {string[]} [scopes] | ||
* @param {string[]} [scopes] any additional scopes that should be requested | ||
* Note: use `IProvider.needsAdditionalScopes(scopes)` to calculate which | ||
* scopes, if any, need to be requested before calling `Batch.get()` | ||
* @memberof Batch | ||
@@ -39,0 +41,0 @@ */ |
@@ -55,3 +55,5 @@ /** | ||
* @param {string} resource | ||
* @param {string[]} [scopes] | ||
* @param {string[]} [scopes] any additional scopes that should be requested | ||
* Note: use `IProvider.needsAdditionalScopes(scopes)` to calculate which | ||
* scopes, if any, need to be requested before calling `Batch.get()` | ||
* @memberof Batch | ||
@@ -98,3 +100,3 @@ */ | ||
} | ||
const middlewareOptions = this.scopes.length ? prepScopes(...this.scopes) : []; | ||
const middlewareOptions = this.scopes.length ? prepScopes(this.scopes) : []; | ||
const batchRequest = this.graph.api('$batch').middlewareOptions(middlewareOptions); | ||
@@ -101,0 +103,0 @@ const batchRequestBody = yield batchRequestContent.getContent(); |
@@ -8,10 +8,5 @@ /** | ||
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 | ||
@@ -93,9 +88,2 @@ * | ||
fileLists: CacheOptions; | ||
/** | ||
* Cache options for conversation store | ||
* | ||
* @type {CacheOptions} | ||
* @memberof CacheConfig | ||
*/ | ||
conversation: CacheOptions; | ||
} | ||
@@ -172,56 +160,2 @@ /** | ||
} | ||
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,11 +19,4 @@ /** | ||
import { CacheStore } from './CacheStore'; | ||
import { error } from './Logging'; | ||
import { dbListKey } from './dbListKey'; | ||
/** | ||
* 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 | ||
@@ -73,3 +66,3 @@ * | ||
delReq.onerror = () => { | ||
error(`${delReq.error.name} occurred deleting cache: ${x}`, delReq.error.message); | ||
console.error(`🦒: ${delReq.error.name} occurred deleting cache: ${x}`, delReq.error.message); | ||
reject(); | ||
@@ -165,8 +158,4 @@ }; | ||
isEnabled: true | ||
}, | ||
conversation: { | ||
invalidationPeriod: 5 * 24 * 60 * 60 * 1000, | ||
isEnabled: true | ||
} | ||
}; | ||
//# sourceMappingURL=CacheService.js.map |
@@ -7,3 +7,4 @@ /** | ||
*/ | ||
import { CacheItem, CacheSchema } from './CacheService'; | ||
import { CacheItem } from './CacheItem'; | ||
import { CacheSchema } from './CacheSchema'; | ||
/** | ||
@@ -26,12 +27,4 @@ * Represents a store in the cache | ||
*/ | ||
getValue(key: string): Promise<T | null>; | ||
getValue(key: string): Promise<T>; | ||
/** | ||
* 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 | ||
@@ -57,4 +50,3 @@ * | ||
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 './CacheService'; | ||
import { dbListKey } from './dbListKey'; | ||
/** | ||
@@ -56,23 +56,2 @@ * 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 | ||
@@ -134,4 +113,3 @@ * | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
upgrade: (db, _oldVersion, _newVersion, transaction) => { | ||
var _a, _b; | ||
upgrade: (db, _oldVersion, _newVersion, _transaction) => { | ||
const dbArray = JSON.parse(localStorage.getItem(dbListKey)) || []; | ||
@@ -143,18 +121,5 @@ if (!dbArray.includes(dbName)) { | ||
for (const storeName in this.schema.stores) { | ||
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); | ||
} | ||
}); | ||
} | ||
if (Object.prototype.hasOwnProperty.call(this.schema.stores, storeName) && | ||
!db.objectStoreNames.contains(storeName)) { | ||
db.createObjectStore(storeName); | ||
} | ||
@@ -167,9 +132,3 @@ } | ||
} | ||
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,3 +9,2 @@ /** | ||
import { customElementHelper } from '../components/customElementHelper'; | ||
import { error } from './Logging'; | ||
/** | ||
@@ -29,3 +28,3 @@ * This is a wrapper decorator for `customElement` from `lit` | ||
// eslint-disable-next-line no-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'); | ||
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'); | ||
return classOrDescriptor; | ||
@@ -32,0 +31,0 @@ }; |
@@ -31,9 +31,9 @@ /* eslint-disable @typescript-eslint/no-unused-expressions */ | ||
// eql for loose equality | ||
yield expect(prepScopes(...scopes)).to.eql([]); | ||
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* () { | ||
it('should return an array of AuthenticationHandlerOptions when incremental consent is enabled with only the first scope in the list', () => __awaiter(void 0, void 0, void 0, function* () { | ||
const scopes = ['scope1', 'scope2']; | ||
Providers.globalProvider = new MockProvider(true); | ||
Providers.globalProvider.isIncrementalConsentDisabled = false; | ||
yield expect(prepScopes(...scopes)).to.eql([new AuthenticationHandlerOptions(undefined, { scopes })]); | ||
yield expect(prepScopes(scopes)).to.eql([new AuthenticationHandlerOptions(undefined, { scopes: ['scope1'] })]); | ||
})); | ||
@@ -40,0 +40,0 @@ }); |
@@ -16,3 +16,3 @@ /** | ||
*/ | ||
export declare const prepScopes: (...scopes: string[]) => AuthenticationHandlerOptions[]; | ||
export declare const prepScopes: (scopes: string[], provider?: import("..").IProvider) => AuthenticationHandlerOptions[]; | ||
//# sourceMappingURL=prepScopes.d.ts.map |
@@ -17,7 +17,8 @@ /** | ||
*/ | ||
export const prepScopes = (...scopes) => { | ||
export const prepScopes = (scopes, provider = Providers.globalProvider) => { | ||
const additionalScopes = provider.needsAdditionalScopes(scopes); | ||
const authProviderOptions = { | ||
scopes | ||
scopes: additionalScopes | ||
}; | ||
if (!Providers.globalProvider.isIncrementalConsentDisabled) { | ||
if (!provider.isIncrementalConsentDisabled) { | ||
return [new AuthenticationHandlerOptions(undefined, authProviderOptions)]; | ||
@@ -24,0 +25,0 @@ } |
@@ -7,3 +7,3 @@ /** | ||
*/ | ||
export declare const PACKAGE_VERSION = "3.1.3-next.mgt-chat.f278f22"; | ||
export declare const PACKAGE_VERSION = "3.1.3-next.mgt-without-loader.701821d"; | ||
//# sourceMappingURL=version.d.ts.map |
@@ -9,3 +9,3 @@ /** | ||
// ANY CHANGES WILL BE LOST DURING BUILD | ||
export const PACKAGE_VERSION = '3.1.3-next.mgt-chat.f278f22'; | ||
export const PACKAGE_VERSION = '3.1.3-next.mgt-without-loader.701821d'; | ||
//# sourceMappingURL=version.js.map |
{ | ||
"name": "@microsoft/mgt-element", | ||
"version": "3.1.3-next.mgt-chat.f278f22", | ||
"version": "3.1.3-next.mgt-without-loader.701821d", | ||
"description": "Microsoft Graph Toolkit base classes", | ||
@@ -35,2 +35,3 @@ "homepage": "https://github.com/microsoftgraph/microsoft-graph-toolkit", | ||
"dependencies": { | ||
"@lit/task": "^1.0.0", | ||
"@microsoft/microsoft-graph-client": "3.0.2", | ||
@@ -37,0 +38,0 @@ "idb": "6.0.0", |
@@ -45,4 +45,7 @@ /** | ||
* @extends {LitElement} | ||
* @deprecated Use MgtBaseTaskComponent instead | ||
*/ | ||
export abstract class MgtBaseComponent extends LitElement { | ||
@state() | ||
protected providerState: ProviderState = ProviderState.Loading; | ||
/** | ||
@@ -313,2 +316,3 @@ * Exposes the semver of the library the component is part of | ||
private readonly handleProviderUpdates = () => { | ||
this.providerState = Providers.globalProvider?.state ?? ProviderState.Loading; | ||
void this.requestStateUpdate(); | ||
@@ -315,0 +319,0 @@ }; |
@@ -17,3 +17,3 @@ /** | ||
* | ||
* @param {string} disambiguation | ||
* @param {string} disambiguation the disambiguation value to be used, should be lowercase | ||
* @return {CustomElementHelper} the current object | ||
@@ -23,3 +23,9 @@ * @memberof CustomElementHelper | ||
public withDisambiguation(disambiguation: string) { | ||
if (disambiguation && !this._disambiguation) this._disambiguation = disambiguation; | ||
if (disambiguation && !this._disambiguation) { | ||
this._disambiguation = disambiguation.toLowerCase(); | ||
if (disambiguation !== this._disambiguation) | ||
console.warn( | ||
`🦒: Disambiguation value, ${disambiguation}, should be lowercase. Value has been converted to lowercase, ${this._disambiguation}.` | ||
); | ||
} | ||
return this; | ||
@@ -26,0 +32,0 @@ } |
@@ -19,3 +19,3 @@ /** | ||
*/ | ||
type RenderedTemplates = Record< | ||
export type RenderedTemplates = Record< | ||
string, | ||
@@ -40,3 +40,3 @@ { | ||
type OrderedHtmlTemplate = HTMLTemplateElement & { templateOrder: number }; | ||
export type OrderedHtmlTemplate = HTMLTemplateElement & { templateOrder: number }; | ||
@@ -50,2 +50,3 @@ /** | ||
* @extends {MgtBaseComponent} | ||
* @deprecated Use MgtTemplatedTaskComponent instead | ||
* | ||
@@ -52,0 +53,0 @@ * @fires {CustomEvent<MgtElement.TemplateRenderedData>} templateRendered - fires when a template is rendered |
@@ -92,4 +92,4 @@ /** | ||
*/ | ||
public forComponent(component: Element | string, version?: string): Graph { | ||
const graph = new Graph(this._client, version || this._version); | ||
public forComponent(component: Element | string): Graph { | ||
const graph = new Graph(this._client, this._version); | ||
graph.setComponent(component); | ||
@@ -111,4 +111,4 @@ return graph; | ||
request.middlewareOptions = (options: MiddlewareOptions[]): GraphRequest => { | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call, @typescript-eslint/dot-notation | ||
request['_middlewareOptions'] = request['_middlewareOptions'].concat(options); | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/dot-notation | ||
request['_middlewareOptions'] = (request['_middlewareOptions'] as MiddlewareOptions[]).concat(options); | ||
return request; | ||
@@ -152,3 +152,3 @@ }; | ||
*/ | ||
export const createFromProvider = (provider: IProvider, version?: string, component?: Element | string): Graph => { | ||
export const createFromProvider = (provider: IProvider, version?: string, component?: Element): Graph => { | ||
const middleware: Middleware[] = [ | ||
@@ -155,0 +155,0 @@ new AuthenticationHandler(provider), |
@@ -50,3 +50,3 @@ /** | ||
*/ | ||
forComponent(component: Element | string, version?: string): IGraph; | ||
forComponent(component: Element): IGraph; | ||
@@ -53,0 +53,0 @@ /** |
@@ -15,3 +15,5 @@ /** | ||
export * from './components/baseProvider'; | ||
export * from './components/baseTaskComponent'; | ||
export * from './components/templatedComponent'; | ||
export * from './components/templatedTaskComponent'; | ||
export * from './components/customElementHelper'; | ||
@@ -23,4 +25,7 @@ | ||
export * from './utils/CacheItem'; | ||
export * from './utils/CacheSchema'; | ||
export * from './utils/CacheService'; | ||
export * from './utils/CacheStore'; | ||
export * from './utils/dbListKey'; | ||
export * from './utils/EventDispatcher'; | ||
@@ -38,3 +43,2 @@ export * from './utils/equals'; | ||
export * from './utils/CustomElement'; | ||
export * from './utils/Logging'; | ||
export * from './utils/registerComponent'; | ||
@@ -41,0 +45,0 @@ |
@@ -65,3 +65,3 @@ /** | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
public forComponent(component: MgtBaseComponent | string): MockGraph { | ||
public forComponent(component: MgtBaseComponent): 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. |
@@ -88,4 +88,4 @@ /** | ||
private static setBaseFallbackUrl() { | ||
this._baseUrl = 'https://proxy.apisandbox.msdn.microsoft.com/svc?url='; | ||
this._baseUrl = 'https://graph.office.net/en-us/graph/api/proxy?url='; | ||
} | ||
} |
@@ -49,2 +49,3 @@ /** | ||
} | ||
private _state: ProviderState; | ||
@@ -55,3 +56,34 @@ private readonly _loginChangedDispatcher = new EventDispatcher<LoginChangedEvent>(); | ||
private _approvedScopes: string[] = []; | ||
public get approvedScopes(): string[] { | ||
return this._approvedScopes; | ||
} | ||
public set approvedScopes(value: string[]) { | ||
this._approvedScopes = value.map(v => v.toLowerCase()); | ||
} | ||
public hasAtLeastOneApprovedScope(requiredScopeSet: string[]): boolean { | ||
return requiredScopeSet.some(s => this.approvedScopes.includes(s.toLowerCase().trim())); | ||
} | ||
public hasAllOneApprovedScope(requiredScopeSet: string[]): boolean { | ||
return requiredScopeSet.some(s => !this.approvedScopes.includes(s.toLowerCase().trim())); | ||
} | ||
/** | ||
* Examines the currently consented scopes for any match in the requiredScopeSet to determine what, if any, scopes need to be consented to | ||
* | ||
* @param {string[]} requiredScopeSet an array of scopes to be checked | ||
* @returns {string[]} if any matches in requiredScopeSet exist then an empty array is returns, otherwise an array containing the first element in the requiredScopeSet is returned | ||
*/ | ||
public needsAdditionalScopes(requiredScopeSet: string[]): string[] { | ||
const reqScopes: string[] = []; | ||
if (requiredScopeSet.length && !this.hasAtLeastOneApprovedScope(requiredScopeSet)) { | ||
reqScopes.push(requiredScopeSet[0].trim()); | ||
} | ||
return reqScopes; | ||
} | ||
/** | ||
* The base URL to be used in the graph client config. | ||
@@ -166,3 +198,3 @@ */ | ||
this._state = state; | ||
this._loginChangedDispatcher.fire({ detail: this._state }); | ||
this._loginChangedDispatcher.fire({}); | ||
} | ||
@@ -230,3 +262,3 @@ } | ||
public setActiveAccount?(user: IProviderAccount) { | ||
this.fireActiveAccountChanged({ detail: user }); | ||
this.fireActiveAccountChanged(); | ||
} | ||
@@ -259,4 +291,4 @@ | ||
*/ | ||
private fireActiveAccountChanged(account: { detail: IProviderAccount }) { | ||
this._activeAccountChangedDispatcher.fire(account); | ||
private fireActiveAccountChanged() { | ||
this._activeAccountChangedDispatcher.fire({}); | ||
} | ||
@@ -293,5 +325,3 @@ | ||
// eslint-disable-next-line @typescript-eslint/no-empty-interface | ||
export interface ActiveAccountChanged { | ||
detail: IProviderAccount; | ||
} | ||
export interface ActiveAccountChanged {} | ||
/** | ||
@@ -304,5 +334,3 @@ * loginChangedEvent | ||
// eslint-disable-next-line @typescript-eslint/no-empty-interface | ||
export interface LoginChangedEvent { | ||
detail: ProviderState; | ||
} | ||
export interface LoginChangedEvent {} | ||
@@ -309,0 +337,0 @@ /** |
@@ -61,3 +61,5 @@ /** | ||
* @param {string} resource | ||
* @param {string[]} [scopes] | ||
* @param {string[]} [scopes] any additional scopes that should be requested | ||
* Note: use `IProvider.needsAdditionalScopes(scopes)` to calculate which | ||
* scopes, if any, need to be requested before calling `Batch.get()` | ||
* @memberof Batch | ||
@@ -110,3 +112,3 @@ */ | ||
const middlewareOptions: MiddlewareOptions[] = this.scopes.length ? prepScopes(...this.scopes) : []; | ||
const middlewareOptions: MiddlewareOptions[] = this.scopes.length ? prepScopes(this.scopes) : []; | ||
const batchRequest = this.graph.api('$batch').middlewareOptions(middlewareOptions); | ||
@@ -113,0 +115,0 @@ |
@@ -11,14 +11,7 @@ /** | ||
import { CacheStore } from './CacheStore'; | ||
import { error } from './Logging'; | ||
import { CacheSchema } from './CacheSchema'; | ||
import { CacheItem } from './CacheItem'; | ||
import { dbListKey } from './dbListKey'; | ||
/** | ||
* Localstorage key for storing names of cache databases | ||
* | ||
* @type {string} | ||
* | ||
*/ | ||
export const dbListKey = 'mgt-db-list'; | ||
/** | ||
* Holds the cache options for cache store | ||
@@ -103,9 +96,2 @@ * | ||
fileLists: CacheOptions; | ||
/** | ||
* Cache options for conversation store | ||
* | ||
* @type {CacheOptions} | ||
* @memberof CacheConfig | ||
*/ | ||
conversation: CacheOptions; | ||
} | ||
@@ -185,3 +171,3 @@ | ||
delReq.onerror = () => { | ||
error(`${delReq.error.name} occurred deleting cache: ${x}`, delReq.error.message); | ||
console.error(`🦒: ${delReq.error.name} occurred deleting cache: ${x}`, delReq.error.message); | ||
reject(); | ||
@@ -241,6 +227,2 @@ }; | ||
isEnabled: true | ||
}, | ||
conversation: { | ||
invalidationPeriod: 5 * 24 * 60 * 60 * 1000, | ||
isEnabled: true | ||
} | ||
@@ -288,58 +270,1 @@ }; | ||
} | ||
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,3 +10,5 @@ /** | ||
import { Providers } from '../providers/Providers'; | ||
import { CacheItem, CacheSchema, Index, dbListKey } from './CacheService'; | ||
import { dbListKey } from './dbListKey'; | ||
import { CacheItem } from './CacheItem'; | ||
import { CacheSchema } from './CacheSchema'; | ||
@@ -40,3 +42,3 @@ /** | ||
*/ | ||
public async getValue(key: string): Promise<T | null> { | ||
public async getValue(key: string): Promise<T> { | ||
if (!window.indexedDB) { | ||
@@ -54,21 +56,2 @@ 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 | ||
@@ -124,3 +107,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[]) || []; | ||
@@ -132,17 +115,7 @@ if (!dbArray.includes(dbName)) { | ||
for (const storeName in this.schema.stores) { | ||
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); | ||
} | ||
}); | ||
} | ||
if ( | ||
Object.prototype.hasOwnProperty.call(this.schema.stores, storeName) && | ||
!db.objectStoreNames.contains(storeName) | ||
) { | ||
db.createObjectStore(storeName); | ||
} | ||
@@ -154,7 +127,2 @@ } | ||
} | ||
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,3 +10,2 @@ /** | ||
import { customElementHelper } from '../components/customElementHelper'; | ||
import { error } from './Logging'; | ||
@@ -31,4 +30,4 @@ /** | ||
// eslint-disable-next-line no-console | ||
error( | ||
`Tag name ${mgtTagName} is already defined using class ${mgtElement.name} version ${version(mgtElement)}\n`, | ||
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`, | ||
@@ -35,0 +34,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' |
@@ -24,9 +24,9 @@ /* eslint-disable @typescript-eslint/no-unused-expressions */ | ||
// eql for loose equality | ||
await expect(prepScopes(...scopes)).to.eql([]); | ||
await expect(prepScopes(scopes)).to.eql([]); | ||
}); | ||
it('should return an array of AuthenticationHandlerOptions when incremental consent is enabled', async () => { | ||
it('should return an array of AuthenticationHandlerOptions when incremental consent is enabled with only the first scope in the list', async () => { | ||
const scopes = ['scope1', 'scope2']; | ||
Providers.globalProvider = new MockProvider(true); | ||
Providers.globalProvider.isIncrementalConsentDisabled = false; | ||
await expect(prepScopes(...scopes)).to.eql([new AuthenticationHandlerOptions(undefined, { scopes })]); | ||
await expect(prepScopes(scopes)).to.eql([new AuthenticationHandlerOptions(undefined, { scopes: ['scope1'] })]); | ||
}); | ||
@@ -33,0 +33,0 @@ }); |
@@ -20,8 +20,9 @@ /** | ||
export const prepScopes = (...scopes: string[]) => { | ||
export const prepScopes = (scopes: string[], provider = Providers.globalProvider) => { | ||
const additionalScopes = provider.needsAdditionalScopes(scopes); | ||
const authProviderOptions = { | ||
scopes | ||
scopes: additionalScopes | ||
}; | ||
if (!Providers.globalProvider.isIncrementalConsentDisabled) { | ||
if (!provider.isIncrementalConsentDisabled) { | ||
return [new AuthenticationHandlerOptions(undefined, authProviderOptions)]; | ||
@@ -28,0 +29,0 @@ } else { |
@@ -11,2 +11,2 @@ /** | ||
export const PACKAGE_VERSION = '3.1.3-next.mgt-chat.f278f22'; | ||
export const PACKAGE_VERSION = '3.1.3-next.mgt-without-loader.701821d'; |
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
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
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
736021
243
11266
4
7933
+ Added@lit/task@^1.0.0
+ Added@lit/task@1.0.1(transitive)