{"version":3,"file":"AuthorityMetadataEntity.js","sources":["../../../src/cache/entities/AuthorityMetadataEntity.ts"],"sourcesContent":["/*\n * Copyright (c) Microsoft Corporation. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { CloudDiscoveryMetadata } from \"../../authority/CloudDiscoveryMetadata\";\nimport { OpenIdConfigResponse } from \"../../authority/OpenIdConfigResponse\";\nimport { AUTHORITY_METADATA_CONSTANTS } from \"../../utils/Constants\";\nimport { TimeUtils } from \"../../utils/TimeUtils\";\n\nexport class AuthorityMetadataEntity {\n aliases: Array;\n preferred_cache: string;\n preferred_network: string;\n canonical_authority: string;\n authorization_endpoint: string;\n token_endpoint: string;\n end_session_endpoint?: string;\n issuer: string;\n aliasesFromNetwork: boolean;\n endpointsFromNetwork: boolean;\n expiresAt: number;\n jwks_uri: string;\n\n constructor() {\n this.expiresAt = TimeUtils.nowSeconds() + AUTHORITY_METADATA_CONSTANTS.REFRESH_TIME_SECONDS;\n }\n\n /**\n * Update the entity with new aliases, preferred_cache and preferred_network values\n * @param metadata \n * @param fromNetwork \n */\n updateCloudDiscoveryMetadata(metadata: CloudDiscoveryMetadata, fromNetwork: boolean): void {\n this.aliases = metadata.aliases;\n this.preferred_cache = metadata.preferred_cache;\n this.preferred_network = metadata.preferred_network;\n this.aliasesFromNetwork = fromNetwork;\n }\n\n /**\n * Update the entity with new endpoints\n * @param metadata \n * @param fromNetwork \n */\n updateEndpointMetadata(metadata: OpenIdConfigResponse, fromNetwork: boolean): void {\n this.authorization_endpoint = metadata.authorization_endpoint;\n this.token_endpoint = metadata.token_endpoint;\n this.end_session_endpoint = metadata.end_session_endpoint;\n this.issuer = metadata.issuer;\n this.endpointsFromNetwork = fromNetwork;\n this.jwks_uri = metadata.jwks_uri;\n }\n\n /**\n * Save the authority that was used to create this cache entry\n * @param authority \n */\n updateCanonicalAuthority(authority: string): void {\n this.canonical_authority = authority;\n }\n\n /**\n * Reset the exiresAt value\n */\n resetExpiresAt(): void {\n this.expiresAt = TimeUtils.nowSeconds() + AUTHORITY_METADATA_CONSTANTS.REFRESH_TIME_SECONDS;\n }\n\n /**\n * Returns whether or not the data needs to be refreshed\n */\n isExpired(): boolean {\n return this.expiresAt <= TimeUtils.nowSeconds();\n }\n\n /**\n * Validates an entity: checks for all expected params\n * @param entity\n */\n static isAuthorityMetadataEntity(key: string, entity: object): boolean {\n\n if (!entity) {\n return false;\n }\n\n return (\n key.indexOf(AUTHORITY_METADATA_CONSTANTS.CACHE_KEY) === 0 &&\n entity.hasOwnProperty(\"aliases\") &&\n entity.hasOwnProperty(\"preferred_cache\") &&\n entity.hasOwnProperty(\"preferred_network\") &&\n entity.hasOwnProperty(\"canonical_authority\") &&\n entity.hasOwnProperty(\"authorization_endpoint\") &&\n entity.hasOwnProperty(\"token_endpoint\") &&\n entity.hasOwnProperty(\"issuer\") &&\n entity.hasOwnProperty(\"aliasesFromNetwork\") &&\n entity.hasOwnProperty(\"endpointsFromNetwork\") &&\n entity.hasOwnProperty(\"expiresAt\") &&\n entity.hasOwnProperty(\"jwks_uri\")\n );\n }\n}\n"],"names":[],"mappings":";;;;;AAAA;;;AAGG;AAOH,IAAA,uBAAA,kBAAA,YAAA;AAcI,IAAA,SAAA,uBAAA,GAAA;QACI,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC,UAAU,EAAE,GAAG,4BAA4B,CAAC,oBAAoB,CAAC;KAC/F;AAED;;;;AAIG;AACH,IAAA,uBAAA,CAAA,SAAA,CAAA,4BAA4B,GAA5B,UAA6B,QAAgC,EAAE,WAAoB,EAAA;AAC/E,QAAA,IAAI,CAAC,OAAO,GAAG,QAAQ,CAAC,OAAO,CAAC;AAChC,QAAA,IAAI,CAAC,eAAe,GAAG,QAAQ,CAAC,eAAe,CAAC;AAChD,QAAA,IAAI,CAAC,iBAAiB,GAAG,QAAQ,CAAC,iBAAiB,CAAC;AACpD,QAAA,IAAI,CAAC,kBAAkB,GAAG,WAAW,CAAC;KACzC,CAAA;AAED;;;;AAIG;AACH,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