@ampproject/toolbox-runtime-version
Advanced tools
Comparing version 2.0.0-alpha.4 to 2.0.0-alpha.7
@@ -20,6 +20,7 @@ /** | ||
const RUNTIME_METADATA_ENDPOINT = 'https://cdn.ampproject.org/rtv/metadata'; | ||
const AMP_CACHE_HOST = 'https://cdn.ampproject.org'; | ||
const RUNTIME_METADATA_PATH = '/rtv/metadata'; | ||
/** | ||
* Queries https://cdn.ampproject.org/rtv/metadata for the lastest AMP runtime version. Uses a | ||
* Queries https://cdn.ampproject.org/rtv/metadata for the latest AMP runtime version. Uses a | ||
* stale-while-revalidate caching strategy to avoid refreshing the version. | ||
@@ -45,3 +46,3 @@ * | ||
* <ul> | ||
* <li> CURRENT_OPTION: is when you go to https://cdn.ampproject.org/experiments.html and toggle "dev-channel". It's the earliest possible time to get new code.</li> | ||
* <li> CURRENT_OPTIN: is when you go to https://cdn.ampproject.org/experiments.html and toggle "dev-channel". It's the earliest possible time to get new code.</li> | ||
* <li> CURRENT_1%: 1% is the same code as opt-in that we're now comfortable releasing to 1% of the population.</li> | ||
@@ -62,6 +63,18 @@ * <li> CURRENT_CONTROL is the same thing as production, but with a different URL. This is to compare experiments against, since prod's immutable caching would affect metrics.</li> | ||
* @param {bool} options.canary - true if canary should be returned. | ||
* @returns {Promise<Number>} a promise containing the current version | ||
* @param {string} options.ampUrlPrefix - the domain & path to an AMP runtime. | ||
* @returns {Promise<string>} a promise containing the current version. | ||
*/ | ||
async currentVersion(options = {}) { | ||
const response = await this.fetch_(RUNTIME_METADATA_ENDPOINT); | ||
let runtimeMetaUrl = AMP_CACHE_HOST + RUNTIME_METADATA_PATH; | ||
if (options.ampUrlPrefix) { | ||
const customMetaUrl = options.ampUrlPrefix.replace(/\/$/, '') + RUNTIME_METADATA_PATH; | ||
// Check whether ampUrlPrefix is absolute since relative paths are allowed | ||
// by optimizer | ||
if (this.isAbsoluteUrl_(customMetaUrl)) { | ||
runtimeMetaUrl = customMetaUrl; | ||
} else { | ||
log.warn('ampUrlPrefix is not an absolute URL. Falling back to https://cdn.ampproject.org.'); | ||
} | ||
} | ||
const response = await this.fetch_(runtimeMetaUrl); | ||
const data = await response.json(); | ||
@@ -89,4 +102,13 @@ let version; | ||
} | ||
isAbsoluteUrl_(url) { | ||
try { | ||
new URL(url); | ||
return true; | ||
} catch (ex) { } | ||
return false; | ||
} | ||
} | ||
module.exports = RuntimeVersion; |
{ | ||
"name": "@ampproject/toolbox-runtime-version", | ||
"version": "2.0.0-alpha.4", | ||
"version": "2.0.0-alpha.7", | ||
"description": "AMP Runtime versions", | ||
@@ -27,3 +27,3 @@ "main": "index.js", | ||
"homepage": "https://github.com/ampproject/amp-toolbox/tree/master/packages/runtime-version", | ||
"gitHead": "fe0d72e23b0d537c91fa78c465ca1ea99d3487ab" | ||
"gitHead": "2e6b60d382d205f884cd78ce4d41fd702121145d" | ||
} |
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
17920
120