From 29e4548bd3a8ef5de0366d49565adcdaeb03987d Mon Sep 17 00:00:00 2001 From: Justin Ridgewell Date: Mon, 12 Aug 2019 18:56:26 -0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=80=20Add=20jsonConfiguration=20transf?= =?UTF-8?q?orm=20(#23745)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Add jsonConfiguration transform The `jsonConfiguration` transform is a static helper that takes large configuration objects and converts them to a JSON string representation at build time. This improves load time and memory of the config object. We keep the configuration as a JS Object in the source code to make development easier. We can add comments as necessary (not possible in JSON), can use traililng comments, get nice syntax highlighting, etc. Only true JSON configurations can be represented this way. Any dynamic behavior inside the configuration is forbidden. The actual `jsonConfiguration` funciton will never be included in the builds, it's purpose is to signal to the babel transform. It exists only in development and tests. ```js // Input const config = jsonConfiguration({foo: 'bar'}); // Output const config = JSON.parse('{"foo": "bar"}'); ``` * Fix types * Add failure cases * Convert ads config * Add innerJsonConfiguration * Rename and cleanup * Use null fake vendor * Fix import paths * Fix property keys * Use escaped uniq value * Cleanup lint rule * Use cooked and raw template values * Fix lint check * lint * Revert _fake_ * what the hell is going on with this test * Use JsonObject as return type * Add comment * Add comments * Fix [].join case * Add additional checking around includeJsonLiteral --- .eslintrc | 1 + ads/_config.js | 10 +- build-system/amp.extern.js | 9 + .../index.js | 217 +++++++++++++++++ .../test/fixtures/transform/escapes/input.js | 27 +++ .../fixtures/transform/escapes/options.json | 3 + .../test/fixtures/transform/escapes/output.js | 17 ++ .../fixtures/transform/json-literal/input.js | 23 ++ .../transform/json-literal/options.json | 3 + .../fixtures/transform/json-literal/output.js | 17 ++ .../fixtures/transform/transform/input.js | 38 +++ .../fixtures/transform/transform/options.json | 3 + .../fixtures/transform/transform/output.js | 21 ++ .../test/index.js | 19 ++ build-system/build.conf.js | 12 +- build-system/compile/compile.js | 8 +- .../eslint-rules/json-configuration.js | 145 ++++++++++++ build-system/tasks/helpers.js | 8 +- build-system/tasks/karma.conf.js | 7 +- extensions/amp-a4a/0.1/callout-vendors.js | 7 +- extensions/amp-ad/0.1/amp-ad.js | 2 +- extensions/amp-analytics/0.1/vendors.js | 219 +++++++++-------- .../amp-analytics/0.1/vendors/acquialift.js | 6 +- .../0.1/vendors/adobeanalytics.js | 6 +- .../vendors/adobeanalytics_nativeConfig.js | 6 +- .../amp-analytics/0.1/vendors/afsanalytics.js | 6 +- .../amp-analytics/0.1/vendors/alexametrics.js | 6 +- .../amp-analytics/0.1/vendors/amplitude.js | 6 +- .../amp-analytics/0.1/vendors/atinternet.js | 6 +- .../0.1/vendors/baiduanalytics.js | 6 +- extensions/amp-analytics/0.1/vendors/bg.js | 6 +- extensions/amp-analytics/0.1/vendors/burt.js | 6 +- .../amp-analytics/0.1/vendors/byside.js | 6 +- .../amp-analytics/0.1/vendors/chartbeat.js | 6 +- .../amp-analytics/0.1/vendors/clicky.js | 6 +- .../amp-analytics/0.1/vendors/colanalytics.js | 6 +- .../amp-analytics/0.1/vendors/comscore.js | 6 +- .../amp-analytics/0.1/vendors/cxense.js | 6 +- .../amp-analytics/0.1/vendors/dynatrace.js | 6 +- extensions/amp-analytics/0.1/vendors/epica.js | 6 +- .../0.1/vendors/euleriananalytics.js | 6 +- .../0.1/vendors/facebookpixel.js | 6 +- .../amp-analytics/0.1/vendors/gemius.js | 6 +- .../0.1/vendors/googleadwords.js | 6 +- .../0.1/vendors/googleanalytics.js | 6 +- extensions/amp-analytics/0.1/vendors/gtag.js | 6 +- .../0.1/vendors/ibeatanalytics.js | 6 +- .../amp-analytics/0.1/vendors/infonline.js | 6 +- .../amp-analytics/0.1/vendors/iplabel.js | 6 +- extensions/amp-analytics/0.1/vendors/keen.js | 6 +- .../amp-analytics/0.1/vendors/kenshoo.js | 6 +- extensions/amp-analytics/0.1/vendors/krux.js | 6 +- .../amp-analytics/0.1/vendors/linkpulse.js | 6 +- .../amp-analytics/0.1/vendors/lotame.js | 6 +- .../0.1/vendors/marinsoftware.js | 6 +- .../amp-analytics/0.1/vendors/mediametrie.js | 6 +- .../0.1/vendors/mediarithmics.js | 6 +- .../amp-analytics/0.1/vendors/mediator.js | 6 +- .../amp-analytics/0.1/vendors/metrika.js | 6 +- extensions/amp-analytics/0.1/vendors/moat.js | 224 ++++++++++-------- .../amp-analytics/0.1/vendors/mobify.js | 6 +- .../amp-analytics/0.1/vendors/mparticle.js | 6 +- .../amp-analytics/0.1/vendors/mpulse.js | 6 +- .../amp-analytics/0.1/vendors/navegg.js | 6 +- .../amp-analytics/0.1/vendors/newrelic.js | 6 +- .../0.1/vendors/nielsen-marketing-cloud.js | 6 +- .../amp-analytics/0.1/vendors/nielsen.js | 6 +- extensions/amp-analytics/0.1/vendors/oewa.js | 6 +- .../amp-analytics/0.1/vendors/oewadirect.js | 6 +- .../0.1/vendors/oracleInfinityAnalytics.js | 6 +- .../amp-analytics/0.1/vendors/parsely.js | 6 +- .../amp-analytics/0.1/vendors/permutive.js | 6 +- .../amp-analytics/0.1/vendors/piStats.js | 6 +- extensions/amp-analytics/0.1/vendors/piano.js | 6 +- .../amp-analytics/0.1/vendors/pinpoll.js | 6 +- .../amp-analytics/0.1/vendors/pressboard.js | 6 +- .../amp-analytics/0.1/vendors/quantcast.js | 6 +- extensions/amp-analytics/0.1/vendors/rakam.js | 6 +- .../amp-analytics/0.1/vendors/reppublika.js | 6 +- .../amp-analytics/0.1/vendors/retargetly.js | 6 +- .../amp-analytics/0.1/vendors/segment.js | 6 +- .../amp-analytics/0.1/vendors/shinystat.js | 6 +- .../amp-analytics/0.1/vendors/simplereach.js | 6 +- .../amp-analytics/0.1/vendors/snowplow.js | 6 +- .../amp-analytics/0.1/vendors/teaanalytics.js | 6 +- .../0.1/vendors/tealiumcollect.js | 6 +- .../amp-analytics/0.1/vendors/top100.js | 6 +- .../amp-analytics/0.1/vendors/topmailru.js | 6 +- .../amp-analytics/0.1/vendors/treasuredata.js | 6 +- .../0.1/vendors/umenganalytics.js | 6 +- .../amp-analytics/0.1/vendors/upscore.js | 6 +- .../0.1/vendors/vponanalytics.js | 6 +- .../amp-analytics/0.1/vendors/webengage.js | 6 +- .../amp-analytics/0.1/vendors/webtrekk.js | 6 +- .../amp-analytics/0.1/vendors/webtrekk_v2.js | 6 +- src/ad-cid.js | 6 +- src/json.js | 39 ++- 97 files changed, 1214 insertions(+), 303 deletions(-) create mode 100644 build-system/babel-plugins/babel-plugin-transform-json-configuration/index.js create mode 100644 build-system/babel-plugins/babel-plugin-transform-json-configuration/test/fixtures/transform/escapes/input.js create mode 100644 build-system/babel-plugins/babel-plugin-transform-json-configuration/test/fixtures/transform/escapes/options.json create mode 100644 build-system/babel-plugins/babel-plugin-transform-json-configuration/test/fixtures/transform/escapes/output.js create mode 100644 build-system/babel-plugins/babel-plugin-transform-json-configuration/test/fixtures/transform/json-literal/input.js create mode 100644 build-system/babel-plugins/babel-plugin-transform-json-configuration/test/fixtures/transform/json-literal/options.json create mode 100644 build-system/babel-plugins/babel-plugin-transform-json-configuration/test/fixtures/transform/json-literal/output.js create mode 100644 build-system/babel-plugins/babel-plugin-transform-json-configuration/test/fixtures/transform/transform/input.js create mode 100644 build-system/babel-plugins/babel-plugin-transform-json-configuration/test/fixtures/transform/transform/options.json create mode 100644 build-system/babel-plugins/babel-plugin-transform-json-configuration/test/fixtures/transform/transform/output.js create mode 100644 build-system/babel-plugins/babel-plugin-transform-json-configuration/test/index.js create mode 100644 build-system/eslint-rules/json-configuration.js diff --git a/.eslintrc b/.eslintrc index 11a75f4f23d2..bc91e82a3df4 100644 --- a/.eslintrc +++ b/.eslintrc @@ -72,6 +72,7 @@ "local/dict-string-keys": 2, "local/html-template": 2, "local/is-experiment-on": 2, + "local/json-configuration": 2, "local/no-array-destructuring": 2, "local/no-deep-destructuring": 2, "local/no-duplicate-import": 2, diff --git a/ads/_config.js b/ads/_config.js index 1840324d9e50..53a4e00ca210 100755 --- a/ads/_config.js +++ b/ads/_config.js @@ -14,6 +14,8 @@ * limitations under the License. */ +import {jsonConfiguration} from '../src/json'; + /** * @typedef {{ * prefetch: (string|undefined), @@ -61,9 +63,9 @@ let AdNetworkConfigDef; * fullWidthHeightRatio: number * } * - * @const {!Object}} + * @const {!Object} */ -export const adConfig = { +const adConfig = jsonConfiguration({ '_ping_': { renderStartImplemented: true, clientIdScope: '_PING_', @@ -1137,4 +1139,6 @@ export const adConfig = { prefetch: 'https://dup.baidustatic.com/js/dm.js', renderStartImplemented: true, }, -}; +}); + +export {adConfig}; diff --git a/build-system/amp.extern.js b/build-system/amp.extern.js index c81e89379bd9..1699f732f4cb 100644 --- a/build-system/amp.extern.js +++ b/build-system/amp.extern.js @@ -68,6 +68,15 @@ FormData.prototype.entries = function () {}; */ function JsonObject() {} +/** + * @typedef {{ + * YOU_MUST_USE: string, + * jsonLiteral: function(), + * TO_MAKE_THIS_TYPE: string, + * }} + */ +var InternalJsonLiteralTypeDef; + /** * Force the dataset property to be handled as a JsonObject. * @type {!JsonObject} diff --git a/build-system/babel-plugins/babel-plugin-transform-json-configuration/index.js b/build-system/babel-plugins/babel-plugin-transform-json-configuration/index.js new file mode 100644 index 000000000000..273e2568ef36 --- /dev/null +++ b/build-system/babel-plugins/babel-plugin-transform-json-configuration/index.js @@ -0,0 +1,217 @@ +/** + * Copyright 2019 The AMP HTML Authors. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS-IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +module.exports = function({template, types: t}) { + /** + * Produces a random number that is guaranteed not to be present in str. + * @param {string} str + * @return {number} + */ + function uniqInString(str) { + while (true) { + const uniq = Math.floor(Math.random() * 2 ** 31); + if (!str.includes(uniq)) { + return uniq; + } + } + } + + /** + * Transforms a statically computable sourcetext path (aka an AST node) into + * a JSON stringified value. + * + * Special "includes" may be used join multiple nested sections + * into a single JSONified string. + * + * @param {!NodePath} path + * @return {string} + */ + function stringifyValue(path) { + const arg = path.get('arguments.0'); + + // sourceText now contains the actual source code written in the file. Eg, + // `{foo: bar}` in the file is now `"{foo: bar}"`. + const sourceText = arg.toString(); + + // We use a unique number to represent inclusions of nested sections. We'll + // be able to search the output JSON string for this exact number, and know + // that we have an inclusion at that location. + const uniq = uniqInString(sourceText); + + // We're going to build up a template string to replace the object literal + // in source text. Eg, ({foo: 'bar'}) will turn into (`{"foo": "bar"}`). + // Each inclusion will generate an expression (the included variable's + // identifier) and a new quasi (the string part of a template string). + const quasis = []; + const expressions = []; + + try { + // We're using a `with (proxy)` to evaluate the object's source code into + // this JS environment. The with-proxy is necessary to allow inclusions + // of nested sections into this section. + // With statements allow you to inject a dynamic lexical scope into code. + // Eg, `with (obj) { a = 1 }` will try to lookup/set the `obj.a` + // property, if `obj` has an `a` property. + // Proxies behave like meta-objects, allowing you to control get/set/has + // operations on the object. Eg, `p.foo` looks up the `"foo"` property + // from `p`. + // So, using a with-proxy allows us to capture and control the lexical + // scope of the evaluating code! + const proxy = new Proxy( + {}, + { + has(target, prop) { + // Anything not on the global is assumed to be an inclusion. This + // includes the `includeJsonLiteral` function call and the + // identifier it is passed as an argument. + return !(prop in global); + }, + get(target, prop) { + // With statements first attempt to look up the + // `Symbol.unscopables` from object. We're explicitly allowing any + // references, so return nothing. + if (prop === Symbol.unscopables) { + return; + } + + // The only other lookups are inclusions of the form + // `includeJsonLiteral(foo)`. Both `includeJsonLiteral` and `foo` + // will be trapped by the with-proxy, allowing us to control the + // values they represent. For `includeJsonLiteral`, the prop + // `"includeJsonLiteral"` will be looked up, and `foo` will lookup + // `"foo"`. + + // `includeJsonLiteral` is being used as a function call, so we + // must return a function. We want to propagate its argument, so + // we return that in the function. + if (prop === 'includeJsonLiteral') { + return s => s; + } + + // The argument to `includeJsonLiteral`. We'll create a new + // identifier reference to it for our template literal expression. + expressions.push(t.identifier(prop)); + + // Finally, we can't actually return the reference's real value + // (because it may be runtime dynamic, or in another file, etc). + // But we must return something that is representable in our + // evaluated object, and that value must be JSON stringable. Our + // unique number is both, and we can search the JSON string for the + // unique number later on to figure out where the inclusion was + // meant to be placed. + return uniq; + }, + } + ); + + // To explain the rest, imagine the following: + // ```js + // const obj = jsonConfiguration({ foo: 'foo', bar: includeJsonLiteral(bar) }); + // ``` + // + // We're going to evaluate the source text + // ```js + // {foo: 'foo', bar: includeJsonLiteral(bar) } + // ``` + const evaluate = new Function( + 'proxy', + `with (proxy) return ${sourceText}` + ); + + // After evaluation, object will be (with 12345 being our unique number): + // ```js + // { foo: 'foo', bar: 12345 } + // ``` + const obj = evaluate(proxy); + + // When we JSON stringify obj, we'll get the string + // ```js + // '{ "foo": "foo", "bar": 12345 }' + // ``` + const json = JSON.stringify(obj); + + // Now, we can search for our unqiue number to find all our inclusions! + const regex = new RegExp(`((?:(?!${uniq})[^])*)(${uniq}|$)`, 'g'); + let match; + while ((match = regex.exec(json))) { + const cooked = match[1]; + // If match[2] is not the unique number, it's the end of string. + const endOfString = match[2] === ''; + + // The first execution, cooked will be '{ "foo": "foo", "bar": ', and + // endOfString will be false. + // The second execution, cooked will be ' }', and endOfString will be + // true. + + // We must escape any escape sequences (and any special template + // interpolation strings) to generate the raw value (this is an AST + // requirement). + if (cooked || !endOfString) { + const raw = cooked.replace(/\${|\\/g, '\\$&'); + quasis.push(t.templateElement({cooked, raw})); + } + + // Our regex can execute forever (it's happy with empty matches). So, + // explicitly check for the end of the string to break. + if (endOfString) { + break; + } + } + + // At this point, quasis will be all of our cooked strings, and + // expressions will be all our our included sections. As source code, it' + // looks like: + // ```js + // `{ "foo": "foo", "bar": ${bar} }` + // ``` + return t.templateLiteral(quasis, expressions); + } catch (e) { + const ref = arg || path; + throw ref.buildCodeFrameError( + 'failed to parse JSON value. Is this a statically computable value?' + ); + } + } + + const handlers = Object.assign(Object.create(null), { + jsonConfiguration(path) { + path.replaceWith(template.expression.ast` + JSON.parse(${stringifyValue(path)}) + `); + }, + + includeJsonLiteral(path) { + path.replaceWith(path.node.arguments[0]); + }, + + jsonLiteral(path) { + path.replaceWith(stringifyValue(path)); + }, + }); + + return { + name: 'transform-json-configuration', + + visitor: { + CallExpression(path) { + const handler = handlers[path.node.callee.name]; + if (handler) { + handler(path); + } + }, + }, + }; +}; diff --git a/build-system/babel-plugins/babel-plugin-transform-json-configuration/test/fixtures/transform/escapes/input.js b/build-system/babel-plugins/babel-plugin-transform-json-configuration/test/fixtures/transform/escapes/input.js new file mode 100644 index 000000000000..b865477ec4cc --- /dev/null +++ b/build-system/babel-plugins/babel-plugin-transform-json-configuration/test/fixtures/transform/escapes/input.js @@ -0,0 +1,27 @@ +/** + * Copyright 2019 The AMP HTML Authors. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS-IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +jsonLiteral({ + 'dblquote': 'a[href$=".pdf"]', + 'interpolate': '${foo}', + 'escape': '\\u00f8C', +}); + +jsonConfiguration({ + 'dblquote': 'a[href$=".pdf"]', + 'interpolate': '${foo}', + 'escape': '\\u00f8C', +}); diff --git a/build-system/babel-plugins/babel-plugin-transform-json-configuration/test/fixtures/transform/escapes/options.json b/build-system/babel-plugins/babel-plugin-transform-json-configuration/test/fixtures/transform/escapes/options.json new file mode 100644 index 000000000000..2077a9fbfcac --- /dev/null +++ b/build-system/babel-plugins/babel-plugin-transform-json-configuration/test/fixtures/transform/escapes/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["../../../../../babel-plugin-transform-json-configuration"] +} diff --git a/build-system/babel-plugins/babel-plugin-transform-json-configuration/test/fixtures/transform/escapes/output.js b/build-system/babel-plugins/babel-plugin-transform-json-configuration/test/fixtures/transform/escapes/output.js new file mode 100644 index 000000000000..78caee1abcf2 --- /dev/null +++ b/build-system/babel-plugins/babel-plugin-transform-json-configuration/test/fixtures/transform/escapes/output.js @@ -0,0 +1,17 @@ +/** + * Copyright 2019 The AMP HTML Authors. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS-IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +`{"dblquote":"a[href$=\\".pdf\\"]","interpolate":"\${foo}","escape":"\\\\u00f8C"}`; +JSON.parse(`{"dblquote":"a[href$=\\".pdf\\"]","interpolate":"\${foo}","escape":"\\\\u00f8C"}`); diff --git a/build-system/babel-plugins/babel-plugin-transform-json-configuration/test/fixtures/transform/json-literal/input.js b/build-system/babel-plugins/babel-plugin-transform-json-configuration/test/fixtures/transform/json-literal/input.js new file mode 100644 index 000000000000..e0b1afc3adea --- /dev/null +++ b/build-system/babel-plugins/babel-plugin-transform-json-configuration/test/fixtures/transform/json-literal/input.js @@ -0,0 +1,23 @@ +/** + * Copyright 2019 The AMP HTML Authors. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS-IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +const inner = jsonLiteral({ + inner: true, +}); + +jsonConfiguration({ + config: includeJsonLiteral(inner), +}); diff --git a/build-system/babel-plugins/babel-plugin-transform-json-configuration/test/fixtures/transform/json-literal/options.json b/build-system/babel-plugins/babel-plugin-transform-json-configuration/test/fixtures/transform/json-literal/options.json new file mode 100644 index 000000000000..2077a9fbfcac --- /dev/null +++ b/build-system/babel-plugins/babel-plugin-transform-json-configuration/test/fixtures/transform/json-literal/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["../../../../../babel-plugin-transform-json-configuration"] +} diff --git a/build-system/babel-plugins/babel-plugin-transform-json-configuration/test/fixtures/transform/json-literal/output.js b/build-system/babel-plugins/babel-plugin-transform-json-configuration/test/fixtures/transform/json-literal/output.js new file mode 100644 index 000000000000..7f1d28fb636c --- /dev/null +++ b/build-system/babel-plugins/babel-plugin-transform-json-configuration/test/fixtures/transform/json-literal/output.js @@ -0,0 +1,17 @@ +/** + * Copyright 2019 The AMP HTML Authors. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS-IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +const inner = `{"inner":true}`; +JSON.parse(`{"config":${inner}}`); diff --git a/build-system/babel-plugins/babel-plugin-transform-json-configuration/test/fixtures/transform/transform/input.js b/build-system/babel-plugins/babel-plugin-transform-json-configuration/test/fixtures/transform/transform/input.js new file mode 100644 index 000000000000..4e4c173210dc --- /dev/null +++ b/build-system/babel-plugins/babel-plugin-transform-json-configuration/test/fixtures/transform/transform/input.js @@ -0,0 +1,38 @@ +/** + * Copyright 2019 The AMP HTML Authors. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS-IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +jsonConfiguration({}); + +jsonConfiguration({a: 1}); + +jsonConfiguration({'b': ['test']}); + +jsonConfiguration({ + // comment + c: true, + d: { + e: false, + } +}); + +jsonConfiguration({ + f: null, + g: undefined, +}); + +jsonConfiguration({ + h: `test`, +}); diff --git a/build-system/babel-plugins/babel-plugin-transform-json-configuration/test/fixtures/transform/transform/options.json b/build-system/babel-plugins/babel-plugin-transform-json-configuration/test/fixtures/transform/transform/options.json new file mode 100644 index 000000000000..2077a9fbfcac --- /dev/null +++ b/build-system/babel-plugins/babel-plugin-transform-json-configuration/test/fixtures/transform/transform/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["../../../../../babel-plugin-transform-json-configuration"] +} diff --git a/build-system/babel-plugins/babel-plugin-transform-json-configuration/test/fixtures/transform/transform/output.js b/build-system/babel-plugins/babel-plugin-transform-json-configuration/test/fixtures/transform/transform/output.js new file mode 100644 index 000000000000..acf68036b6ae --- /dev/null +++ b/build-system/babel-plugins/babel-plugin-transform-json-configuration/test/fixtures/transform/transform/output.js @@ -0,0 +1,21 @@ +/** + * Copyright 2019 The AMP HTML Authors. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS-IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +JSON.parse(`{}`); +JSON.parse(`{"a":1}`); +JSON.parse(`{"b":["test"]}`); +JSON.parse(`{"c":true,"d":{"e":false}}`); +JSON.parse(`{"f":null}`); +JSON.parse(`{"h":"test"}`); diff --git a/build-system/babel-plugins/babel-plugin-transform-json-configuration/test/index.js b/build-system/babel-plugins/babel-plugin-transform-json-configuration/test/index.js new file mode 100644 index 000000000000..44564fa07fec --- /dev/null +++ b/build-system/babel-plugins/babel-plugin-transform-json-configuration/test/index.js @@ -0,0 +1,19 @@ +/** + * Copyright 2019 The AMP HTML Authors. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS-IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +const runner = require('@babel/helper-plugin-test-runner').default; + +runner(__dirname); diff --git a/build-system/build.conf.js b/build-system/build.conf.js index fbbc9b31c0fe..4e8bc279cdd6 100644 --- a/build-system/build.conf.js +++ b/build-system/build.conf.js @@ -27,6 +27,7 @@ const defaultPlugins = [ localPlugin('transform-amp-extension-call'), localPlugin('transform-html-template'), localPlugin('transform-version-call'), + getJsonConfigurationPlugin(), getReplacePlugin(), ]; @@ -116,6 +117,10 @@ const eliminateIntermediateBundles = () => [ localPlugin('transform-prune-namespace'), ]; +function getJsonConfigurationPlugin() { + return localPlugin('transform-json-configuration'); +} + /** * Resolves babel plugin set to apply before compiling on singlepass. * @param {!Object} buildFlags @@ -145,4 +150,9 @@ function plugins({isEsmBuild, isForTesting, isSinglePass}) { return applied; } -module.exports = {plugins, eliminateIntermediateBundles, getReplacePlugin}; +module.exports = { + plugins, + eliminateIntermediateBundles, + getReplacePlugin, + getJsonConfigurationPlugin, +}; diff --git a/build-system/compile/compile.js b/build-system/compile/compile.js index ab9cf93b5b58..bbbe80fc8d22 100644 --- a/build-system/compile/compile.js +++ b/build-system/compile/compile.js @@ -159,12 +159,8 @@ function compile(entryModuleFilenames, outputDir, outputFilename, options) { } return new Promise(function(resolve, reject) { - let entryModuleFilename; - if (entryModuleFilenames instanceof Array) { - entryModuleFilename = entryModuleFilenames[0]; - } else { - entryModuleFilename = entryModuleFilenames; - entryModuleFilenames = [entryModuleFilename]; + if (!(entryModuleFilenames instanceof Array)) { + entryModuleFilenames = [entryModuleFilenames]; } const unneededFiles = [ 'build/fake-module/third_party/babel/custom-babel-helpers.js', diff --git a/build-system/eslint-rules/json-configuration.js b/build-system/eslint-rules/json-configuration.js new file mode 100644 index 000000000000..46147e949a0e --- /dev/null +++ b/build-system/eslint-rules/json-configuration.js @@ -0,0 +1,145 @@ +/** + * Copyright 2019 The AMP HTML Authors. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS-IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +'use strict'; + +/** + * Finds the jsonConfiguration helper function from src/json.js, and performs + * validation on its input. + */ + +module.exports = function(context) { + const configurationCalls = ['jsonConfiguration', 'jsonLiteral'].map( + name => `CallExpression[callee.name=${name}]` + ); + + function verifyPath(node) { + for (let n = node; n; n = n.parent) { + const {parent} = n; + const {type} = parent; + + if (type === 'ArrayExpression' || type === 'ObjectExpression') { + continue; + } + + if (type === 'Property' && parent.value === n) { + continue; + } + + if (type === 'CallExpression') { + const {name} = parent.callee; + if (name === 'jsonConfiguration' || name === 'jsonLiteral') { + break; + } + } + + return context.report({ + node, + message: 'Value must descend from object/array literals only.', + }); + } + } + + return { + 'CallExpression[callee.name=jsonConfiguration]': function(node) { + const args = node.arguments; + + if ( + args.length === 1 && + (args[0].type === 'ObjectExpression' || + args[0].type === 'ArrayExpression') + ) { + return; + } + + return context.report({ + node: args[0] || node, + message: + 'Expected json configuration to pass in object or array literal', + }); + }, + + [`:matches(${configurationCalls}) * Identifier`]: function(node) { + const {name, parent} = node; + if (name === 'undefined') { + return; + } + + if (name === 'includeJsonLiteral') { + return; + } + + if (name in global) { + return; + } + + if ( + parent.type === 'CallExpression' && + parent.callee.name === 'includeJsonLiteral' + ) { + return; + } + + if ( + parent.type === 'Property' && + parent.key === node && + !parent.computed + ) { + return; + } + + if ( + parent.type === 'MemberExpression' && + parent.property === node && + !parent.computed + ) { + return; + } + + context.report({ + node, + message: + 'Unexpected dynamic reference inside json configuration object. Did you mean to use includeJsonLiteral?', + }); + }, + + 'CallExpression[callee.name=jsonLiteral]': function(node) { + const args = node.arguments; + + if (args.length === 1 && args[0].type !== 'Identifier') { + return; + } + + return context.report({ + node: args[0] || node, + message: + 'Expected json literal to pass in literal boolean, string, number, object, or array. Did you pass a reference to one?', + }); + }, + + 'CallExpression[callee.name=includeJsonLiteral]': function(node) { + const args = node.arguments; + + if (args.length !== 1 || args[0].type !== 'Identifier') { + return context.report({ + node: args[0] || node, + message: 'Expected reference identifier to a json literal value', + }); + } + + return verifyPath(node); + }, + }; +}; diff --git a/build-system/tasks/helpers.js b/build-system/tasks/helpers.js index 0bcd3d708a92..52ae74360daf 100644 --- a/build-system/tasks/helpers.js +++ b/build-system/tasks/helpers.js @@ -88,8 +88,8 @@ const BABELIFY_GLOBAL_TRANSFORM = { ignore: devDependencies(), // Ignore devDependencies }; -const BABELIFY_REPLACE_PLUGIN = { - plugins: [conf.getReplacePlugin()], +const BABELIFY_PLUGINS = { + plugins: [conf.getReplacePlugin(), conf.getJsonConfigurationPlugin()], }; const hostname = argv.hostname || 'cdn.ampproject.org'; @@ -437,7 +437,7 @@ function compileUnminifiedJs(srcDir, srcFilename, destDir, options) { const babelifyOptions = Object.assign( {}, BABELIFY_GLOBAL_TRANSFORM, - BABELIFY_REPLACE_PLUGIN + BABELIFY_PLUGINS ); let bundler = browserify(browserifyOptions).transform( @@ -773,7 +773,7 @@ function toPromise(readable) { module.exports = { BABELIFY_GLOBAL_TRANSFORM, - BABELIFY_REPLACE_PLUGIN, + BABELIFY_PLUGINS, WEB_PUSH_PUBLISHER_FILES, WEB_PUSH_PUBLISHER_VERSIONS, buildAlp, diff --git a/build-system/tasks/karma.conf.js b/build-system/tasks/karma.conf.js index 5d215e020974..a9d01f1cf632 100644 --- a/build-system/tasks/karma.conf.js +++ b/build-system/tasks/karma.conf.js @@ -15,10 +15,7 @@ */ 'use strict'; -const { - BABELIFY_GLOBAL_TRANSFORM, - BABELIFY_REPLACE_PLUGIN, -} = require('./helpers'); +const {BABELIFY_GLOBAL_TRANSFORM, BABELIFY_PLUGINS} = require('./helpers'); const {gitCommitterEmail} = require('../git'); const {isTravisBuild, travisJobNumber} = require('../travis'); @@ -42,7 +39,7 @@ const SAUCE_TIMEOUT_CONFIG = { const BABELIFY_CONFIG = Object.assign( {}, BABELIFY_GLOBAL_TRANSFORM, - BABELIFY_REPLACE_PLUGIN, + BABELIFY_PLUGINS, { sourceMapsAbsolute: true, } diff --git a/extensions/amp-a4a/0.1/callout-vendors.js b/extensions/amp-a4a/0.1/callout-vendors.js index 0090e343cc04..491420186f91 100644 --- a/extensions/amp-a4a/0.1/callout-vendors.js +++ b/extensions/amp-a4a/0.1/callout-vendors.js @@ -14,6 +14,7 @@ * limitations under the License. */ import {getMode} from '../../../src/mode'; +import {jsonConfiguration} from '../../../src/json'; ////////////////////////////////////////////////////////////////// // // @@ -36,7 +37,7 @@ import {getMode} from '../../../src/mode'; let RtcVendorDef; /** @const {!Object} */ -export const RTC_VENDORS = { +const RTC_VENDORS = jsonConfiguration({ //////////////////////////////////////////////////////////////////// // // // !!! IMPORTANT NOTE !!! // @@ -141,7 +142,7 @@ export const RTC_VENDORS = { macros: ['ADSLOT_ID'], disableKeyAppend: true, }, -}; +}); // DO NOT MODIFY: Setup for tests if (getMode().localDev || getMode().test) { @@ -157,3 +158,5 @@ if (getMode().localDev || getMode().test) { disableKeyAppend: true, }); } + +export {RTC_VENDORS}; diff --git a/extensions/amp-ad/0.1/amp-ad.js b/extensions/amp-ad/0.1/amp-ad.js index 0d3365c1100d..1093700313f6 100644 --- a/extensions/amp-ad/0.1/amp-ad.js +++ b/extensions/amp-ad/0.1/amp-ad.js @@ -75,7 +75,7 @@ export class AmpAd extends AMP.BaseElement { this.element.setAttribute('data-amp-slot-index', slotId); const useRemoteHtml = - !(adConfig[type] || {}).remoteHTMLDisabled && + !(adConfig[type] || {})['remoteHTMLDisabled'] && this.win.document.querySelector('meta[name=amp-3p-iframe-src]'); // TODO(tdrl): Check amp-ad registry to see if they have this already. // TODO(a4a-cam): Shorten this predicate. diff --git a/extensions/amp-analytics/0.1/vendors.js b/extensions/amp-analytics/0.1/vendors.js index 1e9ff76951ec..d6bf761b4c93 100644 --- a/extensions/amp-analytics/0.1/vendors.js +++ b/extensions/amp-analytics/0.1/vendors.js @@ -20,19 +20,22 @@ import { } from './iframe-transport-vendors'; import {getMode} from '../../../src/mode'; import {hasOwn} from '../../../src/utils/object'; +import { + includeJsonLiteral, + jsonConfiguration, + jsonLiteral, +} from '../../../src/json'; import {isCanary} from '../../../src/experiments'; -// Disable auto-sorting of imports from here on. -/* eslint-disable sort-imports-es6-autofix/sort-imports-es6 */ - -import {_FAKE_} from './vendors/_fake_.js'; import {ACQUIALIFT_CONFIG} from './vendors/acquialift'; +import {ADOBEANALYTICS_CONFIG} from './vendors/adobeanalytics'; +import {ADOBEANALYTICS_NATIVECONFIG_CONFIG} from './vendors/adobeanalytics_nativeConfig'; import {AFSANALYTICS_CONFIG} from './vendors/afsanalytics'; import {ALEXAMETRICS_CONFIG} from './vendors/alexametrics'; import {AMPLITUDE_CONFIG} from './vendors/amplitude'; import {ATINTERNET_CONFIG} from './vendors/atinternet'; -import {UMENGANALYTICS_CONFIG} from './vendors/umenganalytics'; import {BAIDUANALYTICS_CONFIG} from './vendors/baiduanalytics'; +import {BG_CONFIG} from './vendors/bg'; import {BURT_CONFIG} from './vendors/burt'; import {BYSIDE_CONFIG} from './vendors/byside'; import {CHARTBEAT_CONFIG} from './vendors/chartbeat'; @@ -46,25 +49,32 @@ import {EULERIANANALYTICS_CONFIG} from './vendors/euleriananalytics'; import {FACEBOOKPIXEL_CONFIG} from './vendors/facebookpixel'; import {GEMIUS_CONFIG} from './vendors/gemius'; import {GOOGLEADWORDS_CONFIG} from './vendors/googleadwords'; -import {GTAG_CONFIG} from './vendors/gtag'; import {GOOGLEANALYTICS_CONFIG} from './vendors/googleanalytics'; +import {GTAG_CONFIG} from './vendors/gtag'; +import {IBEATANALYTICS_CONFIG} from './vendors/ibeatanalytics'; +import {INFONLINE_CONFIG} from './vendors/infonline'; +import {IPLABEL_CONFIG} from './vendors/iplabel'; import {KEEN_CONFIG} from './vendors/keen'; import {KENSHOO_CONFIG} from './vendors/kenshoo'; import {KRUX_CONFIG} from './vendors/krux'; -import {IPLABEL_CONFIG} from './vendors/iplabel'; +import {LINKPULSE_CONFIG} from './vendors/linkpulse'; import {LOTAME_CONFIG} from './vendors/lotame'; import {MARINSOFTWARE_CONFIG} from './vendors/marinsoftware'; import {MEDIAMETRIE_CONFIG} from './vendors/mediametrie'; import {MEDIARITHMICS_CONFIG} from './vendors/mediarithmics'; import {MEDIATOR_CONFIG} from './vendors/mediator'; import {METRIKA_CONFIG} from './vendors/metrika'; +import {MOAT_CONFIG} from './vendors/moat'; import {MOBIFY_CONFIG} from './vendors/mobify'; import {MPARTICLE_CONFIG} from './vendors/mparticle'; +import {MPULSE_CONFIG} from './vendors/mpulse'; +import {NAVEGG_CONFIG} from './vendors/navegg'; import {NEWRELIC_CONFIG} from './vendors/newrelic'; import {NIELSEN_CONFIG} from './vendors/nielsen'; import {NIELSEN_MARKETING_CLOUD_CONFIG} from './vendors/nielsen-marketing-cloud'; import {OEWADIRECT_CONFIG} from './vendors/oewadirect'; import {OEWA_CONFIG} from './vendors/oewa'; +import {ORACLEINFINITYANALYTICS_CONFIG} from './vendors/oracleInfinityAnalytics'; import {PARSELY_CONFIG} from './vendors/parsely'; import {PERMUTIVE_CONFIG} from './vendors/permutive'; import {PIANO_CONFIG} from './vendors/piano'; @@ -72,35 +82,27 @@ import {PINPOLL_CONFIG} from './vendors/pinpoll'; import {PISTATS_CONFIG} from './vendors/piStats'; import {PRESSBOARD_CONFIG} from './vendors/pressboard'; import {QUANTCAST_CONFIG} from './vendors/quantcast'; +import {RAKAM_CONFIG} from './vendors/rakam'; +import {REPPUBLIKA_CONFIG} from './vendors/reppublika'; import {RETARGETLY_CONFIG} from './vendors/retargetly'; -import {ADOBEANALYTICS_CONFIG} from './vendors/adobeanalytics'; -import {ADOBEANALYTICS_NATIVECONFIG_CONFIG} from './vendors/adobeanalytics_nativeConfig'; -import {INFONLINE_CONFIG} from './vendors/infonline'; -import {SIMPLEREACH_CONFIG} from './vendors/simplereach'; import {SEGMENT_CONFIG} from './vendors/segment'; import {SHINYSTAT_CONFIG} from './vendors/shinystat'; +import {SIMPLEREACH_CONFIG} from './vendors/simplereach'; import {SNOWPLOW_CONFIG} from './vendors/snowplow'; import {TEAANALYTICS_CONFIG} from './vendors/teaanalytics'; import {TEALIUMCOLLECT_CONFIG} from './vendors/tealiumcollect'; import {TOP100_CONFIG} from './vendors/top100'; -import {TREASUREDATA_CONFIG} from './vendors/treasuredata'; -import {WEBTREKK_CONFIG} from './vendors/webtrekk'; -import {WEBTREKK_V2_CONFIG} from './vendors/webtrekk_v2'; -import {MPULSE_CONFIG} from './vendors/mpulse'; -import {LINKPULSE_CONFIG} from './vendors/linkpulse'; -import {RAKAM_CONFIG} from './vendors/rakam'; -import {IBEATANALYTICS_CONFIG} from './vendors/ibeatanalytics'; import {TOPMAILRU_CONFIG} from './vendors/topmailru'; -import {ORACLEINFINITYANALYTICS_CONFIG} from './vendors/oracleInfinityAnalytics'; -import {MOAT_CONFIG} from './vendors/moat'; -import {BG_CONFIG} from './vendors/bg'; +import {TREASUREDATA_CONFIG} from './vendors/treasuredata'; +import {UMENGANALYTICS_CONFIG} from './vendors/umenganalytics'; import {UPSCORE_CONFIG} from './vendors/upscore'; -import {REPPUBLIKA_CONFIG} from './vendors/reppublika'; -import {NAVEGG_CONFIG} from './vendors/navegg'; import {VPONANALYTICS_CONFIG} from './vendors/vponanalytics'; import {WEBENGAGE_CONFIG} from './vendors/webengage'; +import {WEBTREKK_CONFIG} from './vendors/webtrekk'; +import {WEBTREKK_V2_CONFIG} from './vendors/webtrekk_v2'; +import {_FAKE_} from './vendors/_fake_.js'; -const DEFAULT_CONFIG = { +const DEFAULT_CONFIG = jsonLiteral({ 'transport': {'beacon': true, 'xhrpost': true, 'image': true}, 'vars': { 'accessReaderId': 'ACCESS_READER_ID', @@ -171,91 +173,98 @@ const DEFAULT_CONFIG = { 'viewportHeight': 'VIEWPORT_HEIGHT', 'viewportWidth': 'VIEWPORT_WIDTH', }, -}; +}); /** * @const {!JsonObject} */ -// eslint-disable-next-line no-undef -export const ANALYTICS_CONFIG = ANALYTICS_VENDOR_SPLIT - ? /** @type {!JsonObject} */ ({'default': DEFAULT_CONFIG}) - : /** @type {!JsonObject} */ ({ - // Default parent configuration applied to all amp-analytics tags. - 'default': DEFAULT_CONFIG, - 'acquialift': ACQUIALIFT_CONFIG, - 'adobeanalytics': ADOBEANALYTICS_CONFIG, - 'adobeanalytics_nativeConfig': ADOBEANALYTICS_NATIVECONFIG_CONFIG, - 'afsanalytics': AFSANALYTICS_CONFIG, - 'alexametrics': ALEXAMETRICS_CONFIG, - 'amplitude': AMPLITUDE_CONFIG, - 'atinternet': ATINTERNET_CONFIG, - 'baiduanalytics': BAIDUANALYTICS_CONFIG, - 'bg': BG_CONFIG, - 'burt': BURT_CONFIG, - 'byside': BYSIDE_CONFIG, - 'chartbeat': CHARTBEAT_CONFIG, - 'clicky': CLICKY_CONFIG, - 'colanalytics': COLANALYTICS_CONFIG, - 'comscore': COMSCORE_CONFIG, - 'cxense': CXENSE_CONFIG, - 'dynatrace': DYNATRACE_CONFIG, - 'epica': EPICA_CONFIG, - 'euleriananalytics': EULERIANANALYTICS_CONFIG, - 'facebookpixel': FACEBOOKPIXEL_CONFIG, - 'gemius': GEMIUS_CONFIG, - 'googleadwords': GOOGLEADWORDS_CONFIG, - 'googleanalytics': GOOGLEANALYTICS_CONFIG, - 'gtag': GTAG_CONFIG, - 'ibeatanalytics': IBEATANALYTICS_CONFIG, - 'infonline': INFONLINE_CONFIG, - 'iplabel': IPLABEL_CONFIG, - 'keen': KEEN_CONFIG, - 'kenshoo': KENSHOO_CONFIG, - 'krux': KRUX_CONFIG, - 'linkpulse': LINKPULSE_CONFIG, - 'lotame': LOTAME_CONFIG, - 'marinsoftware': MARINSOFTWARE_CONFIG, - 'mediametrie': MEDIAMETRIE_CONFIG, - 'mediarithmics': MEDIARITHMICS_CONFIG, - 'mediator': MEDIATOR_CONFIG, - 'metrika': METRIKA_CONFIG, - 'moat': MOAT_CONFIG, - 'mobify': MOBIFY_CONFIG, - 'mparticle': MPARTICLE_CONFIG, - 'mpulse': MPULSE_CONFIG, - 'navegg': NAVEGG_CONFIG, - 'newrelic': NEWRELIC_CONFIG, - 'nielsen': NIELSEN_CONFIG, - 'nielsen-marketing-cloud': NIELSEN_MARKETING_CLOUD_CONFIG, - 'oewa': OEWA_CONFIG, - 'oewadirect': OEWADIRECT_CONFIG, - 'oracleInfinityAnalytics': ORACLEINFINITYANALYTICS_CONFIG, - 'parsely': PARSELY_CONFIG, - 'piStats': PISTATS_CONFIG, - 'permutive': PERMUTIVE_CONFIG, - 'piano': PIANO_CONFIG, - 'pinpoll': PINPOLL_CONFIG, - 'pressboard': PRESSBOARD_CONFIG, - 'quantcast': QUANTCAST_CONFIG, - 'retargetly': RETARGETLY_CONFIG, - 'rakam': RAKAM_CONFIG, - 'reppublika': REPPUBLIKA_CONFIG, - 'segment': SEGMENT_CONFIG, - 'shinystat': SHINYSTAT_CONFIG, - 'simplereach': SIMPLEREACH_CONFIG, - 'snowplow': SNOWPLOW_CONFIG, - 'teaanalytics': TEAANALYTICS_CONFIG, - 'tealiumcollect': TEALIUMCOLLECT_CONFIG, - 'top100': TOP100_CONFIG, - 'topmailru': TOPMAILRU_CONFIG, - 'treasuredata': TREASUREDATA_CONFIG, - 'umenganalytics': UMENGANALYTICS_CONFIG, - 'upscore': UPSCORE_CONFIG, - 'vponanalytics': VPONANALYTICS_CONFIG, - 'webengage': WEBENGAGE_CONFIG, - 'webtrekk': WEBTREKK_CONFIG, - 'webtrekk_v2': WEBTREKK_V2_CONFIG, - }); +export const ANALYTICS_CONFIG = + // eslint-disable-next-line no-undef + ANALYTICS_VENDOR_SPLIT + ? jsonConfiguration({'default': includeJsonLiteral(DEFAULT_CONFIG)}) + : jsonConfiguration({ + // Default parent configuration applied to all amp-analytics tags. + 'default': includeJsonLiteral(DEFAULT_CONFIG), + 'acquialift': includeJsonLiteral(ACQUIALIFT_CONFIG), + 'adobeanalytics': includeJsonLiteral(ADOBEANALYTICS_CONFIG), + 'adobeanalytics_nativeConfig': includeJsonLiteral( + ADOBEANALYTICS_NATIVECONFIG_CONFIG + ), + 'afsanalytics': includeJsonLiteral(AFSANALYTICS_CONFIG), + 'alexametrics': includeJsonLiteral(ALEXAMETRICS_CONFIG), + 'amplitude': includeJsonLiteral(AMPLITUDE_CONFIG), + 'atinternet': includeJsonLiteral(ATINTERNET_CONFIG), + 'baiduanalytics': includeJsonLiteral(BAIDUANALYTICS_CONFIG), + 'bg': includeJsonLiteral(BG_CONFIG), + 'burt': includeJsonLiteral(BURT_CONFIG), + 'byside': includeJsonLiteral(BYSIDE_CONFIG), + 'chartbeat': includeJsonLiteral(CHARTBEAT_CONFIG), + 'clicky': includeJsonLiteral(CLICKY_CONFIG), + 'colanalytics': includeJsonLiteral(COLANALYTICS_CONFIG), + 'comscore': includeJsonLiteral(COMSCORE_CONFIG), + 'cxense': includeJsonLiteral(CXENSE_CONFIG), + 'dynatrace': includeJsonLiteral(DYNATRACE_CONFIG), + 'epica': includeJsonLiteral(EPICA_CONFIG), + 'euleriananalytics': includeJsonLiteral(EULERIANANALYTICS_CONFIG), + 'facebookpixel': includeJsonLiteral(FACEBOOKPIXEL_CONFIG), + 'gemius': includeJsonLiteral(GEMIUS_CONFIG), + 'googleadwords': includeJsonLiteral(GOOGLEADWORDS_CONFIG), + 'googleanalytics': includeJsonLiteral(GOOGLEANALYTICS_CONFIG), + 'gtag': includeJsonLiteral(GTAG_CONFIG), + 'ibeatanalytics': includeJsonLiteral(IBEATANALYTICS_CONFIG), + 'infonline': includeJsonLiteral(INFONLINE_CONFIG), + 'iplabel': includeJsonLiteral(IPLABEL_CONFIG), + 'keen': includeJsonLiteral(KEEN_CONFIG), + 'kenshoo': includeJsonLiteral(KENSHOO_CONFIG), + 'krux': includeJsonLiteral(KRUX_CONFIG), + 'linkpulse': includeJsonLiteral(LINKPULSE_CONFIG), + 'lotame': includeJsonLiteral(LOTAME_CONFIG), + 'marinsoftware': includeJsonLiteral(MARINSOFTWARE_CONFIG), + 'mediametrie': includeJsonLiteral(MEDIAMETRIE_CONFIG), + 'mediarithmics': includeJsonLiteral(MEDIARITHMICS_CONFIG), + 'mediator': includeJsonLiteral(MEDIATOR_CONFIG), + 'metrika': includeJsonLiteral(METRIKA_CONFIG), + 'moat': includeJsonLiteral(MOAT_CONFIG), + 'mobify': includeJsonLiteral(MOBIFY_CONFIG), + 'mparticle': includeJsonLiteral(MPARTICLE_CONFIG), + 'mpulse': includeJsonLiteral(MPULSE_CONFIG), + 'navegg': includeJsonLiteral(NAVEGG_CONFIG), + 'newrelic': includeJsonLiteral(NEWRELIC_CONFIG), + 'nielsen': includeJsonLiteral(NIELSEN_CONFIG), + 'nielsen-marketing-cloud': includeJsonLiteral( + NIELSEN_MARKETING_CLOUD_CONFIG + ), + 'oewa': includeJsonLiteral(OEWA_CONFIG), + 'oewadirect': includeJsonLiteral(OEWADIRECT_CONFIG), + 'oracleInfinityAnalytics': includeJsonLiteral( + ORACLEINFINITYANALYTICS_CONFIG + ), + 'parsely': includeJsonLiteral(PARSELY_CONFIG), + 'piStats': includeJsonLiteral(PISTATS_CONFIG), + 'permutive': includeJsonLiteral(PERMUTIVE_CONFIG), + 'piano': includeJsonLiteral(PIANO_CONFIG), + 'pinpoll': includeJsonLiteral(PINPOLL_CONFIG), + 'pressboard': includeJsonLiteral(PRESSBOARD_CONFIG), + 'quantcast': includeJsonLiteral(QUANTCAST_CONFIG), + 'retargetly': includeJsonLiteral(RETARGETLY_CONFIG), + 'rakam': includeJsonLiteral(RAKAM_CONFIG), + 'reppublika': includeJsonLiteral(REPPUBLIKA_CONFIG), + 'segment': includeJsonLiteral(SEGMENT_CONFIG), + 'shinystat': includeJsonLiteral(SHINYSTAT_CONFIG), + 'simplereach': includeJsonLiteral(SIMPLEREACH_CONFIG), + 'snowplow': includeJsonLiteral(SNOWPLOW_CONFIG), + 'teaanalytics': includeJsonLiteral(TEAANALYTICS_CONFIG), + 'tealiumcollect': includeJsonLiteral(TEALIUMCOLLECT_CONFIG), + 'top100': includeJsonLiteral(TOP100_CONFIG), + 'topmailru': includeJsonLiteral(TOPMAILRU_CONFIG), + 'treasuredata': includeJsonLiteral(TREASUREDATA_CONFIG), + 'umenganalytics': includeJsonLiteral(UMENGANALYTICS_CONFIG), + 'upscore': includeJsonLiteral(UPSCORE_CONFIG), + 'vponanalytics': includeJsonLiteral(VPONANALYTICS_CONFIG), + 'webengage': includeJsonLiteral(WEBENGAGE_CONFIG), + 'webtrekk': includeJsonLiteral(WEBTREKK_CONFIG), + 'webtrekk_v2': includeJsonLiteral(WEBTREKK_V2_CONFIG), + }); // eslint-disable-next-line no-undef if (!ANALYTICS_VENDOR_SPLIT) { diff --git a/extensions/amp-analytics/0.1/vendors/acquialift.js b/extensions/amp-analytics/0.1/vendors/acquialift.js index b2c62e705734..706ea7e37ef8 100644 --- a/extensions/amp-analytics/0.1/vendors/acquialift.js +++ b/extensions/amp-analytics/0.1/vendors/acquialift.js @@ -14,7 +14,9 @@ * limitations under the License. */ -export const ACQUIALIFT_CONFIG = /** @type {!JsonObject} */ ({ +import {jsonLiteral} from '../../../../src/json'; + +const ACQUIALIFT_CONFIG = jsonLiteral({ 'vars': { 'decisionApiUrl': 'us-east-1-decisionapi.lift.acquia.com', 'accountId': 'xxxxxxxx', @@ -42,3 +44,5 @@ export const ACQUIALIFT_CONFIG = /** @type {!JsonObject} */ ({ }, }, }); + +export {ACQUIALIFT_CONFIG}; diff --git a/extensions/amp-analytics/0.1/vendors/adobeanalytics.js b/extensions/amp-analytics/0.1/vendors/adobeanalytics.js index 23ac497e103d..6240dde907d8 100644 --- a/extensions/amp-analytics/0.1/vendors/adobeanalytics.js +++ b/extensions/amp-analytics/0.1/vendors/adobeanalytics.js @@ -14,7 +14,9 @@ * limitations under the License. */ -export const ADOBEANALYTICS_CONFIG = /** @type {!JsonObject} */ ({ +import {jsonLiteral} from '../../../../src/json'; + +const ADOBEANALYTICS_CONFIG = jsonLiteral({ 'transport': {'xhrpost': false, 'beacon': false, 'image': true}, 'vars': { 'pageName': 'TITLE', @@ -44,3 +46,5 @@ export const ADOBEANALYTICS_CONFIG = /** @type {!JsonObject} */ ({ 'https://${host}${requestPath}?${basePrefix}&pe=lnk_${linkType}&pev1=${linkUrl}&pev2=${linkName}', }, }); + +export {ADOBEANALYTICS_CONFIG}; diff --git a/extensions/amp-analytics/0.1/vendors/adobeanalytics_nativeConfig.js b/extensions/amp-analytics/0.1/vendors/adobeanalytics_nativeConfig.js index da2ea41b8b93..a8ad5062e0c4 100644 --- a/extensions/amp-analytics/0.1/vendors/adobeanalytics_nativeConfig.js +++ b/extensions/amp-analytics/0.1/vendors/adobeanalytics_nativeConfig.js @@ -14,7 +14,9 @@ * limitations under the License. */ -export const ADOBEANALYTICS_NATIVECONFIG_CONFIG = /** @type {!JsonObject} */ ({ +import {jsonLiteral} from '../../../../src/json'; + +const ADOBEANALYTICS_NATIVECONFIG_CONFIG = jsonLiteral({ 'triggers': { 'pageLoad': { 'on': 'visible', @@ -22,3 +24,5 @@ export const ADOBEANALYTICS_NATIVECONFIG_CONFIG = /** @type {!JsonObject} */ ({ }, }, }); + +export {ADOBEANALYTICS_NATIVECONFIG_CONFIG}; diff --git a/extensions/amp-analytics/0.1/vendors/afsanalytics.js b/extensions/amp-analytics/0.1/vendors/afsanalytics.js index 36fc402fb5e0..350e0c194756 100644 --- a/extensions/amp-analytics/0.1/vendors/afsanalytics.js +++ b/extensions/amp-analytics/0.1/vendors/afsanalytics.js @@ -14,7 +14,9 @@ * limitations under the License. */ -export const AFSANALYTICS_CONFIG = /** @type {!JsonObject} */ ({ +import {jsonLiteral} from '../../../../src/json'; + +const AFSANALYTICS_CONFIG = jsonLiteral({ 'vars': { 'server': 'www', 'websiteid': 'xxxxxxxx', @@ -47,3 +49,5 @@ export const AFSANALYTICS_CONFIG = /** @type {!JsonObject} */ ({ }, }, }); + +export {AFSANALYTICS_CONFIG}; diff --git a/extensions/amp-analytics/0.1/vendors/alexametrics.js b/extensions/amp-analytics/0.1/vendors/alexametrics.js index bbd0ac8bb4b4..a55de3c68c10 100644 --- a/extensions/amp-analytics/0.1/vendors/alexametrics.js +++ b/extensions/amp-analytics/0.1/vendors/alexametrics.js @@ -14,7 +14,9 @@ * limitations under the License. */ -export const ALEXAMETRICS_CONFIG = /** @type {!JsonObject} */ ({ +import {jsonLiteral} from '../../../../src/json'; + +const ALEXAMETRICS_CONFIG = jsonLiteral({ 'requests': { 'base': 'https://${ampAtrkHost}/atrk.gif?account=${atrk_acct}&domain=${domain}', @@ -45,3 +47,5 @@ export const ALEXAMETRICS_CONFIG = /** @type {!JsonObject} */ ({ 'image': true, }, }); + +export {ALEXAMETRICS_CONFIG}; diff --git a/extensions/amp-analytics/0.1/vendors/amplitude.js b/extensions/amp-analytics/0.1/vendors/amplitude.js index 57a270c32875..ec43dce04caf 100644 --- a/extensions/amp-analytics/0.1/vendors/amplitude.js +++ b/extensions/amp-analytics/0.1/vendors/amplitude.js @@ -14,7 +14,9 @@ * limitations under the License. */ -export const AMPLITUDE_CONFIG = /** @type {!JsonObject} */ ({ +import {jsonLiteral} from '../../../../src/json'; + +const AMPLITUDE_CONFIG = jsonLiteral({ 'transport': { 'beacon': true, 'xhrpost': true, @@ -52,3 +54,5 @@ export const AMPLITUDE_CONFIG = /** @type {!JsonObject} */ ({ }, }, }); + +export {AMPLITUDE_CONFIG}; diff --git a/extensions/amp-analytics/0.1/vendors/atinternet.js b/extensions/amp-analytics/0.1/vendors/atinternet.js index 28774fdd5d75..553a907bd7f5 100644 --- a/extensions/amp-analytics/0.1/vendors/atinternet.js +++ b/extensions/amp-analytics/0.1/vendors/atinternet.js @@ -14,7 +14,9 @@ * limitations under the License. */ -export const ATINTERNET_CONFIG = /** @type {!JsonObject} */ ({ +import {jsonLiteral} from '../../../../src/json'; + +const ATINTERNET_CONFIG = jsonLiteral({ 'transport': {'beacon': false, 'xhrpost': false, 'image': true}, 'vars': { 'pixelPath': 'hit.xiti', @@ -34,3 +36,5 @@ export const ATINTERNET_CONFIG = /** @type {!JsonObject} */ ({ 'type=click&click=${type}${suffix}', }, }); + +export {ATINTERNET_CONFIG}; diff --git a/extensions/amp-analytics/0.1/vendors/baiduanalytics.js b/extensions/amp-analytics/0.1/vendors/baiduanalytics.js index 53dcc9f5aba3..001333798274 100644 --- a/extensions/amp-analytics/0.1/vendors/baiduanalytics.js +++ b/extensions/amp-analytics/0.1/vendors/baiduanalytics.js @@ -14,7 +14,9 @@ * limitations under the License. */ -export const BAIDUANALYTICS_CONFIG = /** @type {!JsonObject} */ ({ +import {jsonLiteral} from '../../../../src/json'; + +const BAIDUANALYTICS_CONFIG = jsonLiteral({ 'requests': { 'host': 'https://hm.baidu.com', 'base': '${host}/hm.gif?si=${token}&nv=0&st=4&v=pixel-1.0&rnd=${timestamp}', @@ -27,3 +29,5 @@ export const BAIDUANALYTICS_CONFIG = /** @type {!JsonObject} */ ({ 'image': true, }, }); + +export {BAIDUANALYTICS_CONFIG}; diff --git a/extensions/amp-analytics/0.1/vendors/bg.js b/extensions/amp-analytics/0.1/vendors/bg.js index 2c88980a93da..7701d2f1adeb 100644 --- a/extensions/amp-analytics/0.1/vendors/bg.js +++ b/extensions/amp-analytics/0.1/vendors/bg.js @@ -14,4 +14,8 @@ * limitations under the License. */ -export const BG_CONFIG = /** @type {!JsonObject} */ ({}); +import {jsonLiteral} from '../../../../src/json'; + +const BG_CONFIG = jsonLiteral({}); + +export {BG_CONFIG}; diff --git a/extensions/amp-analytics/0.1/vendors/burt.js b/extensions/amp-analytics/0.1/vendors/burt.js index 1f171145dd89..e89f25446a26 100644 --- a/extensions/amp-analytics/0.1/vendors/burt.js +++ b/extensions/amp-analytics/0.1/vendors/burt.js @@ -14,7 +14,9 @@ * limitations under the License. */ -export const BURT_CONFIG = /** @type {!JsonObject} */ ({ +import {jsonLiteral} from '../../../../src/json'; + +const BURT_CONFIG = jsonLiteral({ 'vars': { 'trackingKey': 'ignore', 'category': '', @@ -68,3 +70,5 @@ export const BURT_CONFIG = /** @type {!JsonObject} */ ({ 'image': true, }, }); + +export {BURT_CONFIG}; diff --git a/extensions/amp-analytics/0.1/vendors/byside.js b/extensions/amp-analytics/0.1/vendors/byside.js index 7a382b2d89b4..f45fb8f99e34 100644 --- a/extensions/amp-analytics/0.1/vendors/byside.js +++ b/extensions/amp-analytics/0.1/vendors/byside.js @@ -14,7 +14,9 @@ * limitations under the License. */ -export const BYSIDE_CONFIG = /** @type {!JsonObject} */ ({ +import {jsonLiteral} from '../../../../src/json'; + +const BYSIDE_CONFIG = jsonLiteral({ 'vars': { 'webcareZone': 'webcare', 'webcareId': '', @@ -63,3 +65,5 @@ export const BYSIDE_CONFIG = /** @type {!JsonObject} */ ({ 'image': true, }, }); + +export {BYSIDE_CONFIG}; diff --git a/extensions/amp-analytics/0.1/vendors/chartbeat.js b/extensions/amp-analytics/0.1/vendors/chartbeat.js index f9117c2c5d82..5916eabe2752 100644 --- a/extensions/amp-analytics/0.1/vendors/chartbeat.js +++ b/extensions/amp-analytics/0.1/vendors/chartbeat.js @@ -14,7 +14,9 @@ * limitations under the License. */ -export const CHARTBEAT_CONFIG = /** @type {!JsonObject} */ ({ +import {jsonLiteral} from '../../../../src/json'; + +const CHARTBEAT_CONFIG = jsonLiteral({ 'requests': { 'host': 'https://ping.chartbeat.net', 'basePrefix': @@ -76,3 +78,5 @@ export const CHARTBEAT_CONFIG = /** @type {!JsonObject} */ ({ 'image': true, }, }); + +export {CHARTBEAT_CONFIG}; diff --git a/extensions/amp-analytics/0.1/vendors/clicky.js b/extensions/amp-analytics/0.1/vendors/clicky.js index 5293ae50cd42..ba179effba7a 100644 --- a/extensions/amp-analytics/0.1/vendors/clicky.js +++ b/extensions/amp-analytics/0.1/vendors/clicky.js @@ -14,7 +14,9 @@ * limitations under the License. */ -export const CLICKY_CONFIG = /** @type {!JsonObject} */ ({ +import {jsonLiteral} from '../../../../src/json'; + +const CLICKY_CONFIG = jsonLiteral({ 'vars': { 'site_id': '', }, @@ -52,3 +54,5 @@ export const CLICKY_CONFIG = /** @type {!JsonObject} */ ({ 'image': true, }, }); + +export {CLICKY_CONFIG}; diff --git a/extensions/amp-analytics/0.1/vendors/colanalytics.js b/extensions/amp-analytics/0.1/vendors/colanalytics.js index a3b065eceb4b..16dd0f920796 100644 --- a/extensions/amp-analytics/0.1/vendors/colanalytics.js +++ b/extensions/amp-analytics/0.1/vendors/colanalytics.js @@ -14,7 +14,9 @@ * limitations under the License. */ -export const COLANALYTICS_CONFIG = /** @type {!JsonObject} */ ({ +import {jsonLiteral} from '../../../../src/json'; + +const COLANALYTICS_CONFIG = jsonLiteral({ 'requests': { 'host': 'https://ase.clmbtech.com', 'base': '${host}/message', @@ -49,3 +51,5 @@ export const COLANALYTICS_CONFIG = /** @type {!JsonObject} */ ({ 'image': true, }, }); + +export {COLANALYTICS_CONFIG}; diff --git a/extensions/amp-analytics/0.1/vendors/comscore.js b/extensions/amp-analytics/0.1/vendors/comscore.js index 3a2087a5d7d2..ca874fc9dca4 100644 --- a/extensions/amp-analytics/0.1/vendors/comscore.js +++ b/extensions/amp-analytics/0.1/vendors/comscore.js @@ -14,7 +14,9 @@ * limitations under the License. */ -export const COMSCORE_CONFIG = /** @type {!JsonObject} */ ({ +import {jsonLiteral} from '../../../../src/json'; + +const COMSCORE_CONFIG = jsonLiteral({ 'vars': { 'c2': '1000001', }, @@ -45,3 +47,5 @@ export const COMSCORE_CONFIG = /** @type {!JsonObject} */ ({ 'image': true, }, }); + +export {COMSCORE_CONFIG}; diff --git a/extensions/amp-analytics/0.1/vendors/cxense.js b/extensions/amp-analytics/0.1/vendors/cxense.js index b82c3452d1aa..3d2b1f27fa48 100644 --- a/extensions/amp-analytics/0.1/vendors/cxense.js +++ b/extensions/amp-analytics/0.1/vendors/cxense.js @@ -14,7 +14,9 @@ * limitations under the License. */ -export const CXENSE_CONFIG = /** @type {!JsonObject} */ ({ +import {jsonLiteral} from '../../../../src/json'; + +const CXENSE_CONFIG = jsonLiteral({ 'requests': { 'host': 'https://scomcluster.cxense.com', 'base': '${host}/Repo/rep.gif', @@ -37,3 +39,5 @@ export const CXENSE_CONFIG = /** @type {!JsonObject} */ ({ 'image': true, }, }); + +export {CXENSE_CONFIG}; diff --git a/extensions/amp-analytics/0.1/vendors/dynatrace.js b/extensions/amp-analytics/0.1/vendors/dynatrace.js index af3d414caf47..7945d74760e5 100644 --- a/extensions/amp-analytics/0.1/vendors/dynatrace.js +++ b/extensions/amp-analytics/0.1/vendors/dynatrace.js @@ -14,7 +14,9 @@ * limitations under the License. */ -export const DYNATRACE_CONFIG = /** @type {!JsonObject} */ ({ +import {jsonLiteral} from '../../../../src/json'; + +const DYNATRACE_CONFIG = jsonLiteral({ 'requests': { 'endpoint': '${protocol}://${tenant}${separator}${environment}:${port}/ampbf/${tenantpath}', @@ -77,3 +79,5 @@ export const DYNATRACE_CONFIG = /** @type {!JsonObject} */ ({ 'separator': '.', }, }); + +export {DYNATRACE_CONFIG}; diff --git a/extensions/amp-analytics/0.1/vendors/epica.js b/extensions/amp-analytics/0.1/vendors/epica.js index 68c60e24d726..6667ce08b7d4 100644 --- a/extensions/amp-analytics/0.1/vendors/epica.js +++ b/extensions/amp-analytics/0.1/vendors/epica.js @@ -14,7 +14,9 @@ * limitations under the License. */ -export const EPICA_CONFIG = /** @type {!JsonObject} */ ({ +import {jsonLiteral} from '../../../../src/json'; + +const EPICA_CONFIG = jsonLiteral({ 'transport': { 'beacon': false, 'xhrpost': false, @@ -46,3 +48,5 @@ export const EPICA_CONFIG = /** @type {!JsonObject} */ ({ }, }, }); + +export {EPICA_CONFIG}; diff --git a/extensions/amp-analytics/0.1/vendors/euleriananalytics.js b/extensions/amp-analytics/0.1/vendors/euleriananalytics.js index e4a47e95056f..6a9d8675cd80 100644 --- a/extensions/amp-analytics/0.1/vendors/euleriananalytics.js +++ b/extensions/amp-analytics/0.1/vendors/euleriananalytics.js @@ -14,7 +14,9 @@ * limitations under the License. */ -export const EULERIANANALYTICS_CONFIG = /** @type {!JsonObject} */ ({ +import {jsonLiteral} from '../../../../src/json'; + +const EULERIANANALYTICS_CONFIG = jsonLiteral({ 'vars': { 'analyticsHost': '', 'documentLocation': 'SOURCE_URL', @@ -45,3 +47,5 @@ export const EULERIANANALYTICS_CONFIG = /** @type {!JsonObject} */ ({ 'image': true, }, }); + +export {EULERIANANALYTICS_CONFIG}; diff --git a/extensions/amp-analytics/0.1/vendors/facebookpixel.js b/extensions/amp-analytics/0.1/vendors/facebookpixel.js index 1a5c684b0420..daa7712f5ea4 100644 --- a/extensions/amp-analytics/0.1/vendors/facebookpixel.js +++ b/extensions/amp-analytics/0.1/vendors/facebookpixel.js @@ -14,7 +14,9 @@ * limitations under the License. */ -export const FACEBOOKPIXEL_CONFIG = /** @type {!JsonObject} */ ({ +import {jsonLiteral} from '../../../../src/json'; + +const FACEBOOKPIXEL_CONFIG = jsonLiteral({ 'vars': { 'pixelId': 'PIXEL-ID', }, @@ -105,3 +107,5 @@ export const FACEBOOKPIXEL_CONFIG = /** @type {!JsonObject} */ ({ }, }, }); + +export {FACEBOOKPIXEL_CONFIG}; diff --git a/extensions/amp-analytics/0.1/vendors/gemius.js b/extensions/amp-analytics/0.1/vendors/gemius.js index b27a63a9f136..5770a2d758cc 100644 --- a/extensions/amp-analytics/0.1/vendors/gemius.js +++ b/extensions/amp-analytics/0.1/vendors/gemius.js @@ -14,7 +14,9 @@ * limitations under the License. */ -export const GEMIUS_CONFIG = /** @type {!JsonObject} */ ({ +import {jsonLiteral} from '../../../../src/json'; + +const GEMIUS_CONFIG = jsonLiteral({ 'vars': { 'dnt': '0', }, @@ -36,3 +38,5 @@ export const GEMIUS_CONFIG = /** @type {!JsonObject} */ ({ 'image': true, }, }); + +export {GEMIUS_CONFIG}; diff --git a/extensions/amp-analytics/0.1/vendors/googleadwords.js b/extensions/amp-analytics/0.1/vendors/googleadwords.js index c6b076f3c23f..2e622ecc6428 100644 --- a/extensions/amp-analytics/0.1/vendors/googleadwords.js +++ b/extensions/amp-analytics/0.1/vendors/googleadwords.js @@ -14,7 +14,9 @@ * limitations under the License. */ -export const GOOGLEADWORDS_CONFIG = /** @type {!JsonObject} */ ({ +import {jsonLiteral} from '../../../../src/json'; + +const GOOGLEADWORDS_CONFIG = jsonLiteral({ // https://developers.google.com/adwords/amp/landing-pages 'requests': { 'conversion_prefix': 'https://www.googleadservices.com/pagead/conversion/', @@ -51,3 +53,5 @@ export const GOOGLEADWORDS_CONFIG = /** @type {!JsonObject} */ ({ 'image': true, }, }); + +export {GOOGLEADWORDS_CONFIG}; diff --git a/extensions/amp-analytics/0.1/vendors/googleanalytics.js b/extensions/amp-analytics/0.1/vendors/googleanalytics.js index 3fcfdffdd45d..f9b059f0948c 100644 --- a/extensions/amp-analytics/0.1/vendors/googleanalytics.js +++ b/extensions/amp-analytics/0.1/vendors/googleanalytics.js @@ -14,7 +14,9 @@ * limitations under the License. */ -export const GOOGLEANALYTICS_CONFIG = /** @type {!JsonObject} */ ({ +import {jsonLiteral} from '../../../../src/json'; + +const GOOGLEANALYTICS_CONFIG = jsonLiteral({ 'vars': { 'eventValue': '0', 'documentLocation': 'SOURCE_URL', @@ -124,3 +126,5 @@ export const GOOGLEANALYTICS_CONFIG = /** @type {!JsonObject} */ ({ }, }, }); + +export {GOOGLEANALYTICS_CONFIG}; diff --git a/extensions/amp-analytics/0.1/vendors/gtag.js b/extensions/amp-analytics/0.1/vendors/gtag.js index 0ac94088b846..8436d2600fb7 100644 --- a/extensions/amp-analytics/0.1/vendors/gtag.js +++ b/extensions/amp-analytics/0.1/vendors/gtag.js @@ -14,7 +14,9 @@ * limitations under the License. */ -export const GTAG_CONFIG = /** @type {!JsonObject} */ ({ +import {jsonLiteral} from '../../../../src/json'; + +const GTAG_CONFIG = jsonLiteral({ 'configRewriter': { 'url': 'https://www.googletagmanager.com/gtag/amp', 'varGroups': { @@ -122,3 +124,5 @@ export const GTAG_CONFIG = /** @type {!JsonObject} */ ({ 'image': true, }, }); + +export {GTAG_CONFIG}; diff --git a/extensions/amp-analytics/0.1/vendors/ibeatanalytics.js b/extensions/amp-analytics/0.1/vendors/ibeatanalytics.js index a760206169e6..27c1484cdf09 100644 --- a/extensions/amp-analytics/0.1/vendors/ibeatanalytics.js +++ b/extensions/amp-analytics/0.1/vendors/ibeatanalytics.js @@ -14,7 +14,9 @@ * limitations under the License. */ -export const IBEATANALYTICS_CONFIG = /** @type {!JsonObject} */ ({ +import {jsonLiteral} from '../../../../src/json'; + +const IBEATANALYTICS_CONFIG = jsonLiteral({ 'requests': { 'host': 'https://ibeat.indiatimes.com', 'base': 'https://ibeat.indiatimes.com/iBeat/pageTrendlogAmp.html', @@ -50,3 +52,5 @@ export const IBEATANALYTICS_CONFIG = /** @type {!JsonObject} */ ({ }, }, }); + +export {IBEATANALYTICS_CONFIG}; diff --git a/extensions/amp-analytics/0.1/vendors/infonline.js b/extensions/amp-analytics/0.1/vendors/infonline.js index 3819a7890393..8e2389c17546 100644 --- a/extensions/amp-analytics/0.1/vendors/infonline.js +++ b/extensions/amp-analytics/0.1/vendors/infonline.js @@ -14,7 +14,9 @@ * limitations under the License. */ -export const INFONLINE_CONFIG = /** @type {!JsonObject} */ ({ +import {jsonLiteral} from '../../../../src/json'; + +const INFONLINE_CONFIG = jsonLiteral({ 'vars': { 'sv': 'ke', 'ap': '1', @@ -38,3 +40,5 @@ export const INFONLINE_CONFIG = /** @type {!JsonObject} */ ({ }, }, }); + +export {INFONLINE_CONFIG}; diff --git a/extensions/amp-analytics/0.1/vendors/iplabel.js b/extensions/amp-analytics/0.1/vendors/iplabel.js index 496a4d59f6e6..69db5a0a33b4 100644 --- a/extensions/amp-analytics/0.1/vendors/iplabel.js +++ b/extensions/amp-analytics/0.1/vendors/iplabel.js @@ -14,7 +14,9 @@ * limitations under the License. */ -export const IPLABEL_CONFIG = /** @type {!JsonObject} */ ({ +import {jsonLiteral} from '../../../../src/json'; + +const IPLABEL_CONFIG = jsonLiteral({ 'requests': { 'collectorUrl': 'm.col.ip-label.net', 'endpoint': 'https://${collectorUrl}/coll/', @@ -67,3 +69,5 @@ export const IPLABEL_CONFIG = /** @type {!JsonObject} */ ({ 'urlgroup': '', }, }); + +export {IPLABEL_CONFIG}; diff --git a/extensions/amp-analytics/0.1/vendors/keen.js b/extensions/amp-analytics/0.1/vendors/keen.js index 665b301c0073..7d3ab2ea4ed8 100644 --- a/extensions/amp-analytics/0.1/vendors/keen.js +++ b/extensions/amp-analytics/0.1/vendors/keen.js @@ -14,7 +14,9 @@ * limitations under the License. */ -export const KEEN_CONFIG = /** @type {!JsonObject} */ ({ +import {jsonLiteral} from '../../../../src/json'; + +const KEEN_CONFIG = jsonLiteral({ 'requests': { 'base': 'https://api.keen.io/3.0/projects/${projectId}/events', 'pageview': '${base}/pageviews?api_key=${writeKey}', @@ -72,3 +74,5 @@ export const KEEN_CONFIG = /** @type {!JsonObject} */ ({ 'useBody': true, }, }); + +export {KEEN_CONFIG}; diff --git a/extensions/amp-analytics/0.1/vendors/kenshoo.js b/extensions/amp-analytics/0.1/vendors/kenshoo.js index 83f3032ff133..047ee7140042 100644 --- a/extensions/amp-analytics/0.1/vendors/kenshoo.js +++ b/extensions/amp-analytics/0.1/vendors/kenshoo.js @@ -14,7 +14,9 @@ * limitations under the License. */ -export const KENSHOO_CONFIG = /** @type {!JsonObject} */ ({ +import {jsonLiteral} from '../../../../src/json'; + +const KENSHOO_CONFIG = jsonLiteral({ 'vars': { 'clientId': 'CLIENT_ID(ken_amp_id)', 'channelClickId': 'QUERY_PARAM(gclid)', @@ -56,3 +58,5 @@ export const KENSHOO_CONFIG = /** @type {!JsonObject} */ ({ }, }, }); + +export {KENSHOO_CONFIG}; diff --git a/extensions/amp-analytics/0.1/vendors/krux.js b/extensions/amp-analytics/0.1/vendors/krux.js index b5f4733a34d6..0348bcdf4ba4 100644 --- a/extensions/amp-analytics/0.1/vendors/krux.js +++ b/extensions/amp-analytics/0.1/vendors/krux.js @@ -14,7 +14,9 @@ * limitations under the License. */ -export const KRUX_CONFIG = /** @type {!JsonObject} */ ({ +import {jsonLiteral} from '../../../../src/json'; + +const KRUX_CONFIG = jsonLiteral({ 'requests': { 'beaconHost': 'https://beacon.krxd.net', 'timing': @@ -52,3 +54,5 @@ export const KRUX_CONFIG = /** @type {!JsonObject} */ ({ 'page.': '_kpa_', }, }); + +export {KRUX_CONFIG}; diff --git a/extensions/amp-analytics/0.1/vendors/linkpulse.js b/extensions/amp-analytics/0.1/vendors/linkpulse.js index 63071f87c508..3f7be8585eb4 100644 --- a/extensions/amp-analytics/0.1/vendors/linkpulse.js +++ b/extensions/amp-analytics/0.1/vendors/linkpulse.js @@ -14,7 +14,9 @@ * limitations under the License. */ -export const LINKPULSE_CONFIG = /** @type {!JsonObject} */ ({ +import {jsonLiteral} from '../../../../src/json'; + +const LINKPULSE_CONFIG = jsonLiteral({ 'vars': { 'id': '', 'pageUrl': 'CANONICAL_URL', @@ -84,3 +86,5 @@ export const LINKPULSE_CONFIG = /** @type {!JsonObject} */ ({ 'image': true, }, }); + +export {LINKPULSE_CONFIG}; diff --git a/extensions/amp-analytics/0.1/vendors/lotame.js b/extensions/amp-analytics/0.1/vendors/lotame.js index dff59bb6f560..75d553982141 100644 --- a/extensions/amp-analytics/0.1/vendors/lotame.js +++ b/extensions/amp-analytics/0.1/vendors/lotame.js @@ -14,7 +14,9 @@ * limitations under the License. */ -export const LOTAME_CONFIG = /** @type {!JsonObject} */ ({ +import {jsonLiteral} from '../../../../src/json'; + +const LOTAME_CONFIG = jsonLiteral({ 'requests': { 'pageview': 'https://bcp.crwdcntrl.net/amp?c=${account}&pv=y', }, @@ -30,3 +32,5 @@ export const LOTAME_CONFIG = /** @type {!JsonObject} */ ({ 'image': true, }, }); + +export {LOTAME_CONFIG}; diff --git a/extensions/amp-analytics/0.1/vendors/marinsoftware.js b/extensions/amp-analytics/0.1/vendors/marinsoftware.js index 214fb8b7c926..43b5cc4a24ae 100644 --- a/extensions/amp-analytics/0.1/vendors/marinsoftware.js +++ b/extensions/amp-analytics/0.1/vendors/marinsoftware.js @@ -14,7 +14,9 @@ * limitations under the License. */ -export const MARINSOFTWARE_CONFIG = /** @type {!JsonObject} */ ({ +import {jsonLiteral} from '../../../../src/json'; + +const MARINSOFTWARE_CONFIG = jsonLiteral({ 'requests': { 'base': 'https://tracker.marinsm.com/tp', 'baseParams': @@ -44,3 +46,5 @@ export const MARINSOFTWARE_CONFIG = /** @type {!JsonObject} */ ({ 'image': true, }, }); + +export {MARINSOFTWARE_CONFIG}; diff --git a/extensions/amp-analytics/0.1/vendors/mediametrie.js b/extensions/amp-analytics/0.1/vendors/mediametrie.js index c1ab050e2d68..3947b637fa04 100644 --- a/extensions/amp-analytics/0.1/vendors/mediametrie.js +++ b/extensions/amp-analytics/0.1/vendors/mediametrie.js @@ -14,7 +14,9 @@ * limitations under the License. */ -export const MEDIAMETRIE_CONFIG = /** @type {!JsonObject} */ ({ +import {jsonLiteral} from '../../../../src/json'; + +const MEDIAMETRIE_CONFIG = jsonLiteral({ 'requests': { 'host': 'https://prof.estat.com/m/web', 'pageview': @@ -46,3 +48,5 @@ export const MEDIAMETRIE_CONFIG = /** @type {!JsonObject} */ ({ 'image': true, }, }); + +export {MEDIAMETRIE_CONFIG}; diff --git a/extensions/amp-analytics/0.1/vendors/mediarithmics.js b/extensions/amp-analytics/0.1/vendors/mediarithmics.js index 5c61b8e36fa3..f5d9f7a0f6de 100644 --- a/extensions/amp-analytics/0.1/vendors/mediarithmics.js +++ b/extensions/amp-analytics/0.1/vendors/mediarithmics.js @@ -14,7 +14,9 @@ * limitations under the License. */ -export const MEDIARITHMICS_CONFIG = /** @type {!JsonObject} */ ({ +import {jsonLiteral} from '../../../../src/json'; + +const MEDIARITHMICS_CONFIG = jsonLiteral({ 'vars': { 'domain': 'events.mediarithmics.com', 'url': 'SOURCE_URL', @@ -42,3 +44,5 @@ export const MEDIARITHMICS_CONFIG = /** @type {!JsonObject} */ ({ 'image': true, }, }); + +export {MEDIARITHMICS_CONFIG}; diff --git a/extensions/amp-analytics/0.1/vendors/mediator.js b/extensions/amp-analytics/0.1/vendors/mediator.js index c56c07455134..514ba1245faa 100644 --- a/extensions/amp-analytics/0.1/vendors/mediator.js +++ b/extensions/amp-analytics/0.1/vendors/mediator.js @@ -14,7 +14,9 @@ * limitations under the License. */ -export const MEDIATOR_CONFIG = /** @type {!JsonObject} */ ({ +import {jsonLiteral} from '../../../../src/json'; + +const MEDIATOR_CONFIG = jsonLiteral({ 'requests': { 'host': '//collector.mediator.media/script/${mediator_id}/amp/', 'renderstart': '${host}init/?url=${canonicalUrl}', @@ -78,3 +80,5 @@ export const MEDIATOR_CONFIG = /** @type {!JsonObject} */ ({ }, }, }); + +export {MEDIATOR_CONFIG}; diff --git a/extensions/amp-analytics/0.1/vendors/metrika.js b/extensions/amp-analytics/0.1/vendors/metrika.js index c02dffd57364..34d09951364b 100644 --- a/extensions/amp-analytics/0.1/vendors/metrika.js +++ b/extensions/amp-analytics/0.1/vendors/metrika.js @@ -14,7 +14,9 @@ * limitations under the License. */ -export const METRIKA_CONFIG = /** @type {!JsonObject} */ ({ +import {jsonLiteral} from '../../../../src/json'; + +const METRIKA_CONFIG = jsonLiteral({ 'transport': {'beacon': true, 'xhrpost': true, 'image': false}, 'requests': { 'pageview': '${_watch}?browser-info=${_brInfo}&${_siteInfo}&${_suffix}', @@ -59,3 +61,5 @@ export const METRIKA_CONFIG = /** @type {!JsonObject} */ ({ }, }, }); + +export {METRIKA_CONFIG}; diff --git a/extensions/amp-analytics/0.1/vendors/moat.js b/extensions/amp-analytics/0.1/vendors/moat.js index b2b3e0bc91cf..08848a80ff8f 100644 --- a/extensions/amp-analytics/0.1/vendors/moat.js +++ b/extensions/amp-analytics/0.1/vendors/moat.js @@ -14,110 +14,132 @@ * limitations under the License. */ -export const MOAT_CONFIG = /** @type {!JsonObject} */ ({ +import {includeJsonLiteral, jsonLiteral} from '../../../../src/json'; + +const load = jsonLiteral( + JSON.stringify( + /** @type {!JsonObject} */ ({ + 'type': 'load', + 'pcode': '${pcode}', + 'l0t': '${l0t}', + 'acctType': '${acctType}', + 'adType': '${adType}', + 'qs': '${qs}', + 'element': { + 'src': '${htmlAttr(img,src,width)}', + 'viewer': '${viewer}', + }, + 'document': { + 'AMPDocumentHostname': '${ampdocHostname}', + 'AMPDocumentURL': '${ampdocUrl}', + 'canonicalHost': '${canonicalHost}', + 'canonicalHostname': '${canonicalHostname}', + 'canonicalPath': '${canonicalPath}', + 'canonicalURL': '${canonicalUrl}', + 'documentCharset': '${documentCharset}', + 'documentReferrer': '${documentReferrer}', + 'externalReferrer': '${externalReferrer}', + 'sourceURL': '${sourceUrl}', + 'sourceHost': '${sourceHost}', + 'sourceHostname': '${sourceHostname}', + 'sourcePath': '${sourcePath}', + 'title': '${title}', + 'viewer': '${viewer}', + }, + 'device': { + 'availableScreenHeight': '${availableScreenHeight}', + 'availableScreenWidth': '${availableScreenWidth}', + 'browserLanguage': '${browserLanguage}', + 'screenColorDepth': '${screenColorDepth}', + 'screenHeight': '${screenHeight}', + 'screenWidth': '${screenWidth}', + 'scrollHeight': '${scrollHeight}', + 'scrollWidth': '${scrollWidth}', + 'scrollLeft': '${scrollLeft}', + 'scrollTop': '${scrollTop}', + 'timezone': '${timezone}', + 'userAgent': '${userAgent}', + 'viewportHeight': '${viewportHeight}', + 'viewportWidth': '${viewportWidth}', + }, + 'requestCount': '${requestCount}', + 'timeStamp': '${timestamp}', + }) + ) +); + +const unload = jsonLiteral( + JSON.stringify( + /** @type {!JsonObject} */ ({ + 'type': 'unload', + 'pcode': '${pcode}', + 'l0t': '${l0t}', + 'requestCount': '${requestCount}', + 'timeStamp': '${timestamp}', + }) + ) +); + +const click = jsonLiteral( + JSON.stringify( + /** @type {!JsonObject} */ ({ + 'type': 'click', + 'pcode': '${pcode}', + 'l0t': '${l0t}', + 'requestCount': '${requestCount}', + 'timeStamp': '${timestamp}', + }) + ) +); + +const viewability = jsonLiteral( + JSON.stringify( + /** @type {!JsonObject} */ ({ + 'type': 'viewability', + 'pcode': '${pcode}', + 'l0t': '${l0t}', + 'backgroundState': '${backgroundState}', + 'intersectionRect': '${intersectionRect}', + 'intersectionRatio': '${intersectionRatio}', + 'maxVisiblePercentage': '${maxVisiblePercentage}', + 'minVisiblePercentage': '${minVisiblePercentage}', + 'x': '${elementX}', + 'y': '${elementY}', + 'height': '${elementHeight}', + 'width': '${elementWidth}', + 'viewportHeight': '${viewportHeight}', + 'viewportWidth': '${viewportWidth}', + 'opacity': '${opacity}', + 'timeStamp': '${timestamp}', + 'requestCount': '${requestCount}', + }) + ) +); + +const iframe = jsonLiteral( + JSON.stringify( + /** @type {!JsonObject} */ ({ + 'type': 'iframe', + 'pcode': '${pcode}', + 'height': '${elementHeight}', + 'width': '${elementWidth}', + 'x': '${elementX}', + 'y': '${elementY}', + 'requestCount': '${requestCount}', + }) + ) +); + +const MOAT_CONFIG = jsonLiteral({ 'vars': { 'element': ':root', }, 'requests': { - 'load': JSON.stringify( - /** @type {!JsonObject} */ ({ - 'type': 'load', - 'pcode': '${pcode}', - 'l0t': '${l0t}', - 'acctType': '${acctType}', - 'adType': '${adType}', - 'qs': '${qs}', - 'element': { - 'src': '${htmlAttr(img,src,width)}', - 'viewer': '${viewer}', - }, - 'document': { - 'AMPDocumentHostname': '${ampdocHostname}', - 'AMPDocumentURL': '${ampdocUrl}', - 'canonicalHost': '${canonicalHost}', - 'canonicalHostname': '${canonicalHostname}', - 'canonicalPath': '${canonicalPath}', - 'canonicalURL': '${canonicalUrl}', - 'documentCharset': '${documentCharset}', - 'documentReferrer': '${documentReferrer}', - 'externalReferrer': '${externalReferrer}', - 'sourceURL': '${sourceUrl}', - 'sourceHost': '${sourceHost}', - 'sourceHostname': '${sourceHostname}', - 'sourcePath': '${sourcePath}', - 'title': '${title}', - 'viewer': '${viewer}', - }, - 'device': { - 'availableScreenHeight': '${availableScreenHeight}', - 'availableScreenWidth': '${availableScreenWidth}', - 'browserLanguage': '${browserLanguage}', - 'screenColorDepth': '${screenColorDepth}', - 'screenHeight': '${screenHeight}', - 'screenWidth': '${screenWidth}', - 'scrollHeight': '${scrollHeight}', - 'scrollWidth': '${scrollWidth}', - 'scrollLeft': '${scrollLeft}', - 'scrollTop': '${scrollTop}', - 'timezone': '${timezone}', - 'userAgent': '${userAgent}', - 'viewportHeight': '${viewportHeight}', - 'viewportWidth': '${viewportWidth}', - }, - 'requestCount': '${requestCount}', - 'timeStamp': '${timestamp}', - }) - ), - 'unload': JSON.stringify( - /** @type {!JsonObject} */ ({ - 'type': 'unload', - 'pcode': '${pcode}', - 'l0t': '${l0t}', - 'requestCount': '${requestCount}', - 'timeStamp': '${timestamp}', - }) - ), - 'click': JSON.stringify( - /** @type {!JsonObject} */ ({ - 'type': 'click', - 'pcode': '${pcode}', - 'l0t': '${l0t}', - 'requestCount': '${requestCount}', - 'timeStamp': '${timestamp}', - }) - ), - 'viewability': JSON.stringify( - /** @type {!JsonObject} */ ({ - 'type': 'viewability', - 'pcode': '${pcode}', - 'l0t': '${l0t}', - 'backgroundState': '${backgroundState}', - 'intersectionRect': '${intersectionRect}', - 'intersectionRatio': '${intersectionRatio}', - 'maxVisiblePercentage': '${maxVisiblePercentage}', - 'minVisiblePercentage': '${minVisiblePercentage}', - 'x': '${elementX}', - 'y': '${elementY}', - 'height': '${elementHeight}', - 'width': '${elementWidth}', - 'viewportHeight': '${viewportHeight}', - 'viewportWidth': '${viewportWidth}', - 'opacity': '${opacity}', - 'timeStamp': '${timestamp}', - 'requestCount': '${requestCount}', - }) - ), - 'iframe': JSON.stringify( - /** @type {!JsonObject} */ ({ - 'type': 'iframe', - 'pcode': '${pcode}', - 'height': '${elementHeight}', - 'width': '${elementWidth}', - 'x': '${elementX}', - 'y': '${elementY}', - 'requestCount': '${requestCount}', - }) - ), + 'load': includeJsonLiteral(load), + 'unload': includeJsonLiteral(unload), + 'click': includeJsonLiteral(click), + 'viewability': includeJsonLiteral(viewability), + 'iframe': includeJsonLiteral(iframe), }, 'triggers': { 'load': { @@ -177,3 +199,5 @@ export const MOAT_CONFIG = /** @type {!JsonObject} */ ({ }, }, }); + +export {MOAT_CONFIG}; diff --git a/extensions/amp-analytics/0.1/vendors/mobify.js b/extensions/amp-analytics/0.1/vendors/mobify.js index 717bc272d08d..f3a9e6aaec65 100644 --- a/extensions/amp-analytics/0.1/vendors/mobify.js +++ b/extensions/amp-analytics/0.1/vendors/mobify.js @@ -14,7 +14,9 @@ * limitations under the License. */ -export const MOBIFY_CONFIG = /** @type {!JsonObject} */ ({ +import {jsonLiteral} from '../../../../src/json'; + +const MOBIFY_CONFIG = jsonLiteral({ 'vars': { 'projectSlug': 'mobify-project-id', 'templateName': 'page-type', @@ -66,3 +68,5 @@ export const MOBIFY_CONFIG = /** @type {!JsonObject} */ ({ 'image': true, }, }); + +export {MOBIFY_CONFIG}; diff --git a/extensions/amp-analytics/0.1/vendors/mparticle.js b/extensions/amp-analytics/0.1/vendors/mparticle.js index 5ad33f93ba51..1f8741cdd6dc 100644 --- a/extensions/amp-analytics/0.1/vendors/mparticle.js +++ b/extensions/amp-analytics/0.1/vendors/mparticle.js @@ -14,7 +14,9 @@ * limitations under the License. */ -export const MPARTICLE_CONFIG = /** @type {!JsonObject} */ ({ +import {jsonLiteral} from '../../../../src/json'; + +const MPARTICLE_CONFIG = jsonLiteral({ 'vars': { 'eventType': 'Unknown', 'debug': false, @@ -58,3 +60,5 @@ export const MPARTICLE_CONFIG = /** @type {!JsonObject} */ ({ 'image': true, }, }); + +export {MPARTICLE_CONFIG}; diff --git a/extensions/amp-analytics/0.1/vendors/mpulse.js b/extensions/amp-analytics/0.1/vendors/mpulse.js index 8dfe7bcae27a..0109c14bb340 100644 --- a/extensions/amp-analytics/0.1/vendors/mpulse.js +++ b/extensions/amp-analytics/0.1/vendors/mpulse.js @@ -14,7 +14,9 @@ * limitations under the License. */ -export const MPULSE_CONFIG = /** @type {!JsonObject} */ ({ +import {jsonLiteral} from '../../../../src/json'; + +const MPULSE_CONFIG = jsonLiteral({ 'requests': { 'onvisible': 'https://${beacon_url}?' + @@ -77,3 +79,5 @@ export const MPULSE_CONFIG = /** @type {!JsonObject} */ ({ 'custom_metric.': 'cmet.', }, }); + +export {MPULSE_CONFIG}; diff --git a/extensions/amp-analytics/0.1/vendors/navegg.js b/extensions/amp-analytics/0.1/vendors/navegg.js index f2fa45e83501..741657eab9a3 100644 --- a/extensions/amp-analytics/0.1/vendors/navegg.js +++ b/extensions/amp-analytics/0.1/vendors/navegg.js @@ -14,7 +14,9 @@ * limitations under the License. */ -export const NAVEGG_CONFIG = /** @type {!JsonObject} */ ({ +import {jsonLiteral} from '../../../../src/json'; + +const NAVEGG_CONFIG = jsonLiteral({ 'requests': { 'pageview': 'https://amp.navdmp.com/amp?' + @@ -38,3 +40,5 @@ export const NAVEGG_CONFIG = /** @type {!JsonObject} */ ({ 'image': {'suppressWarnings': true}, }, }); + +export {NAVEGG_CONFIG}; diff --git a/extensions/amp-analytics/0.1/vendors/newrelic.js b/extensions/amp-analytics/0.1/vendors/newrelic.js index ef879f0f0666..7850ae56b79e 100644 --- a/extensions/amp-analytics/0.1/vendors/newrelic.js +++ b/extensions/amp-analytics/0.1/vendors/newrelic.js @@ -14,7 +14,9 @@ * limitations under the License. */ -export const NEWRELIC_CONFIG = /** @type {!JsonObject} */ ({ +import {jsonLiteral} from '../../../../src/json'; + +const NEWRELIC_CONFIG = jsonLiteral({ 'requests': { 'pageview': 'https://${beacon}/amp?appId=${appId}' + @@ -57,3 +59,5 @@ export const NEWRELIC_CONFIG = /** @type {!JsonObject} */ ({ }, }, }); + +export {NEWRELIC_CONFIG}; diff --git a/extensions/amp-analytics/0.1/vendors/nielsen-marketing-cloud.js b/extensions/amp-analytics/0.1/vendors/nielsen-marketing-cloud.js index db50c6a3e462..1304e7feded8 100644 --- a/extensions/amp-analytics/0.1/vendors/nielsen-marketing-cloud.js +++ b/extensions/amp-analytics/0.1/vendors/nielsen-marketing-cloud.js @@ -14,7 +14,9 @@ * limitations under the License. */ -export const NIELSEN_MARKETING_CLOUD_CONFIG = /** @type {!JsonObject} */ ({ +import {jsonLiteral} from '../../../../src/json'; + +const NIELSEN_MARKETING_CLOUD_CONFIG = jsonLiteral({ 'transport': { 'beacon': false, 'xhrpost': false, @@ -36,3 +38,5 @@ export const NIELSEN_MARKETING_CLOUD_CONFIG = /** @type {!JsonObject} */ ({ }, }, }); + +export {NIELSEN_MARKETING_CLOUD_CONFIG}; diff --git a/extensions/amp-analytics/0.1/vendors/nielsen.js b/extensions/amp-analytics/0.1/vendors/nielsen.js index d28a217abc29..6306157f1757 100644 --- a/extensions/amp-analytics/0.1/vendors/nielsen.js +++ b/extensions/amp-analytics/0.1/vendors/nielsen.js @@ -14,7 +14,9 @@ * limitations under the License. */ -export const NIELSEN_CONFIG = /** @type {!JsonObject} */ ({ +import {jsonLiteral} from '../../../../src/json'; + +const NIELSEN_CONFIG = jsonLiteral({ 'vars': { 'sessionId': 'CLIENT_ID(imrworldwide)', 'prefix': '', @@ -51,3 +53,5 @@ export const NIELSEN_CONFIG = /** @type {!JsonObject} */ ({ 'referrerPolicy': 'no-referrer', }, }); + +export {NIELSEN_CONFIG}; diff --git a/extensions/amp-analytics/0.1/vendors/oewa.js b/extensions/amp-analytics/0.1/vendors/oewa.js index d4e0b9c032d6..f1eb3bdd283a 100644 --- a/extensions/amp-analytics/0.1/vendors/oewa.js +++ b/extensions/amp-analytics/0.1/vendors/oewa.js @@ -14,7 +14,9 @@ * limitations under the License. */ -export const OEWA_CONFIG = /** @type {!JsonObject} */ ({ +import {jsonLiteral} from '../../../../src/json'; + +const OEWA_CONFIG = jsonLiteral({ 'transport': {'beacon': false, 'xhrpost': false, 'image': true}, 'requests': { 'pageview': @@ -31,3 +33,5 @@ export const OEWA_CONFIG = /** @type {!JsonObject} */ ({ }, }, }); + +export {OEWA_CONFIG}; diff --git a/extensions/amp-analytics/0.1/vendors/oewadirect.js b/extensions/amp-analytics/0.1/vendors/oewadirect.js index fa8e8596175b..9ac077f45288 100644 --- a/extensions/amp-analytics/0.1/vendors/oewadirect.js +++ b/extensions/amp-analytics/0.1/vendors/oewadirect.js @@ -14,7 +14,9 @@ * limitations under the License. */ -export const OEWADIRECT_CONFIG = /** @type {!JsonObject} */ ({ +import {jsonLiteral} from '../../../../src/json'; + +const OEWADIRECT_CONFIG = jsonLiteral({ 'transport': {'beacon': false, 'xhrpost': false, 'image': true}, 'requests': { 'pageview': @@ -27,3 +29,5 @@ export const OEWADIRECT_CONFIG = /** @type {!JsonObject} */ ({ }, }, }); + +export {OEWADIRECT_CONFIG}; diff --git a/extensions/amp-analytics/0.1/vendors/oracleInfinityAnalytics.js b/extensions/amp-analytics/0.1/vendors/oracleInfinityAnalytics.js index b1bd566fcc71..0db11204e6ad 100644 --- a/extensions/amp-analytics/0.1/vendors/oracleInfinityAnalytics.js +++ b/extensions/amp-analytics/0.1/vendors/oracleInfinityAnalytics.js @@ -14,7 +14,9 @@ * limitations under the License. */ -export const ORACLEINFINITYANALYTICS_CONFIG = /** @type {!JsonObject} */ ({ +import {jsonLiteral} from '../../../../src/json'; + +const ORACLEINFINITYANALYTICS_CONFIG = jsonLiteral({ 'transport': { 'beacon': false, 'xhrpost': false, @@ -82,3 +84,5 @@ export const ORACLEINFINITYANALYTICS_CONFIG = /** @type {!JsonObject} */ ({ }, }, }); + +export {ORACLEINFINITYANALYTICS_CONFIG}; diff --git a/extensions/amp-analytics/0.1/vendors/parsely.js b/extensions/amp-analytics/0.1/vendors/parsely.js index 8ac942be4fbe..ea2f4808e54c 100644 --- a/extensions/amp-analytics/0.1/vendors/parsely.js +++ b/extensions/amp-analytics/0.1/vendors/parsely.js @@ -14,7 +14,9 @@ * limitations under the License. */ -export const PARSELY_CONFIG = /** @type {!JsonObject} */ ({ +import {jsonLiteral} from '../../../../src/json'; + +const PARSELY_CONFIG = jsonLiteral({ 'requests': { 'host': 'https://srv.pixel.parsely.com', 'basePrefix': @@ -57,3 +59,5 @@ export const PARSELY_CONFIG = /** @type {!JsonObject} */ ({ 'image': true, }, }); + +export {PARSELY_CONFIG}; diff --git a/extensions/amp-analytics/0.1/vendors/permutive.js b/extensions/amp-analytics/0.1/vendors/permutive.js index 7c364cbcd502..909eb32152ee 100644 --- a/extensions/amp-analytics/0.1/vendors/permutive.js +++ b/extensions/amp-analytics/0.1/vendors/permutive.js @@ -14,7 +14,9 @@ * limitations under the License. */ -export const PERMUTIVE_CONFIG = /** @type {!JsonObject} */ ({ +import {jsonLiteral} from '../../../../src/json'; + +const PERMUTIVE_CONFIG = jsonLiteral({ 'vars': { 'identity': '${clientId(_ga)}', }, @@ -72,3 +74,5 @@ export const PERMUTIVE_CONFIG = /** @type {!JsonObject} */ ({ 'properties.': '_ep_', }, }); + +export {PERMUTIVE_CONFIG}; diff --git a/extensions/amp-analytics/0.1/vendors/piStats.js b/extensions/amp-analytics/0.1/vendors/piStats.js index c33d89263922..80db6c147aa1 100644 --- a/extensions/amp-analytics/0.1/vendors/piStats.js +++ b/extensions/amp-analytics/0.1/vendors/piStats.js @@ -14,7 +14,9 @@ * limitations under the License. */ -export const PISTATS_CONFIG = /** @type {!JsonObject} */ ({ +import {jsonLiteral} from '../../../../src/json'; + +const PISTATS_CONFIG = jsonLiteral({ 'requests': { 'host': 'https://events.pi-stats.com', 'basePrefix': @@ -45,3 +47,5 @@ export const PISTATS_CONFIG = /** @type {!JsonObject} */ ({ 'image': true, }, }); + +export {PISTATS_CONFIG}; diff --git a/extensions/amp-analytics/0.1/vendors/piano.js b/extensions/amp-analytics/0.1/vendors/piano.js index 105e310df5f9..442a15e1c1fa 100644 --- a/extensions/amp-analytics/0.1/vendors/piano.js +++ b/extensions/amp-analytics/0.1/vendors/piano.js @@ -14,7 +14,9 @@ * limitations under the License. */ -export const PIANO_CONFIG = /** @type {!JsonObject} */ ({ +import {jsonLiteral} from '../../../../src/json'; + +const PIANO_CONFIG = jsonLiteral({ 'requests': { 'host': 'https://api-v3.tinypass.com', 'basePrefix': '/api/v3', @@ -29,3 +31,5 @@ export const PIANO_CONFIG = /** @type {!JsonObject} */ ({ 'screen=${screenWidth}x${screenHeight}${baseSuffix}', }, }); + +export {PIANO_CONFIG}; diff --git a/extensions/amp-analytics/0.1/vendors/pinpoll.js b/extensions/amp-analytics/0.1/vendors/pinpoll.js index 0e548ef6dbf0..61a049aae032 100644 --- a/extensions/amp-analytics/0.1/vendors/pinpoll.js +++ b/extensions/amp-analytics/0.1/vendors/pinpoll.js @@ -14,7 +14,9 @@ * limitations under the License. */ -export const PINPOLL_CONFIG = /** @type {!JsonObject} */ ({ +import {jsonLiteral} from '../../../../src/json'; + +const PINPOLL_CONFIG = jsonLiteral({ 'requests': { 'pageview': '${protocol}://${host}/${version}?' + @@ -44,3 +46,5 @@ export const PINPOLL_CONFIG = /** @type {!JsonObject} */ ({ 'host': 'pa.pinpoll.com', }, }); + +export {PINPOLL_CONFIG}; diff --git a/extensions/amp-analytics/0.1/vendors/pressboard.js b/extensions/amp-analytics/0.1/vendors/pressboard.js index 1a67b1477c0f..5c13767a4b5a 100644 --- a/extensions/amp-analytics/0.1/vendors/pressboard.js +++ b/extensions/amp-analytics/0.1/vendors/pressboard.js @@ -14,7 +14,9 @@ * limitations under the License. */ -export const PRESSBOARD_CONFIG = /** @type {!JsonObject} */ ({ +import {jsonLiteral} from '../../../../src/json'; + +const PRESSBOARD_CONFIG = jsonLiteral({ 'vars': { 'mediaId': '', 'campaignId': '', @@ -76,3 +78,5 @@ export const PRESSBOARD_CONFIG = /** @type {!JsonObject} */ ({ 'image': true, }, }); + +export {PRESSBOARD_CONFIG}; diff --git a/extensions/amp-analytics/0.1/vendors/quantcast.js b/extensions/amp-analytics/0.1/vendors/quantcast.js index 178ca4f66fc5..e79070640acb 100644 --- a/extensions/amp-analytics/0.1/vendors/quantcast.js +++ b/extensions/amp-analytics/0.1/vendors/quantcast.js @@ -14,7 +14,9 @@ * limitations under the License. */ -export const QUANTCAST_CONFIG = /** @type {!JsonObject} */ ({ +import {jsonLiteral} from '../../../../src/json'; + +const QUANTCAST_CONFIG = jsonLiteral({ 'vars': { 'labels': '', }, @@ -38,3 +40,5 @@ export const QUANTCAST_CONFIG = /** @type {!JsonObject} */ ({ 'image': true, }, }); + +export {QUANTCAST_CONFIG}; diff --git a/extensions/amp-analytics/0.1/vendors/rakam.js b/extensions/amp-analytics/0.1/vendors/rakam.js index 3738987c2a19..684cc0e3e816 100644 --- a/extensions/amp-analytics/0.1/vendors/rakam.js +++ b/extensions/amp-analytics/0.1/vendors/rakam.js @@ -14,7 +14,9 @@ * limitations under the License. */ -export const RAKAM_CONFIG = /** @type {!JsonObject} */ ({ +import {jsonLiteral} from '../../../../src/json'; + +const RAKAM_CONFIG = jsonLiteral({ 'vars': { 'deviceId': 'CLIENT_ID(rakam_device_id)', }, @@ -38,3 +40,5 @@ export const RAKAM_CONFIG = /** @type {!JsonObject} */ ({ 'https://${apiEndpoint}/event/pixel${base}&collection=${collection}', }, }); + +export {RAKAM_CONFIG}; diff --git a/extensions/amp-analytics/0.1/vendors/reppublika.js b/extensions/amp-analytics/0.1/vendors/reppublika.js index 8fb797407cc2..3fd3157210c0 100644 --- a/extensions/amp-analytics/0.1/vendors/reppublika.js +++ b/extensions/amp-analytics/0.1/vendors/reppublika.js @@ -14,7 +14,9 @@ * limitations under the License. */ -export const REPPUBLIKA_CONFIG = /** @type {!JsonObject} */ ({ +import {jsonLiteral} from '../../../../src/json'; + +const REPPUBLIKA_CONFIG = jsonLiteral({ 'requests': { 'host': 'https://t5.mindtake.com', 'basePrefix': '/tag/cid/', @@ -29,3 +31,5 @@ export const REPPUBLIKA_CONFIG = /** @type {!JsonObject} */ ({ 'image': true, }, }); + +export {REPPUBLIKA_CONFIG}; diff --git a/extensions/amp-analytics/0.1/vendors/retargetly.js b/extensions/amp-analytics/0.1/vendors/retargetly.js index 581a160df7e0..1d02095ebe62 100644 --- a/extensions/amp-analytics/0.1/vendors/retargetly.js +++ b/extensions/amp-analytics/0.1/vendors/retargetly.js @@ -14,7 +14,9 @@ * limitations under the License. */ -export const RETARGETLY_CONFIG = /** @type {!JsonObject} */ ({ +import {jsonLiteral} from '../../../../src/json'; + +const RETARGETLY_CONFIG = jsonLiteral({ 'requests': { 'host': 'https://api.retargetly.com', 'page': @@ -34,3 +36,5 @@ export const RETARGETLY_CONFIG = /** @type {!JsonObject} */ ({ }, }, }); + +export {RETARGETLY_CONFIG}; diff --git a/extensions/amp-analytics/0.1/vendors/segment.js b/extensions/amp-analytics/0.1/vendors/segment.js index c6e3f4bbf1eb..8ff4c7145c7f 100644 --- a/extensions/amp-analytics/0.1/vendors/segment.js +++ b/extensions/amp-analytics/0.1/vendors/segment.js @@ -14,7 +14,9 @@ * limitations under the License. */ -export const SEGMENT_CONFIG = /** @type {!JsonObject} */ ({ +import {jsonLiteral} from '../../../../src/json'; + +const SEGMENT_CONFIG = jsonLiteral({ 'transport': { 'beacon': false, 'xhrpost': false, @@ -59,3 +61,5 @@ export const SEGMENT_CONFIG = /** @type {!JsonObject} */ ({ }, }, }); + +export {SEGMENT_CONFIG}; diff --git a/extensions/amp-analytics/0.1/vendors/shinystat.js b/extensions/amp-analytics/0.1/vendors/shinystat.js index f0d37662b916..087bd3aa4b78 100644 --- a/extensions/amp-analytics/0.1/vendors/shinystat.js +++ b/extensions/amp-analytics/0.1/vendors/shinystat.js @@ -14,7 +14,9 @@ * limitations under the License. */ -export const SHINYSTAT_CONFIG = /** @type {!JsonObject} */ ({ +import {jsonLiteral} from '../../../../src/json'; + +const SHINYSTAT_CONFIG = jsonLiteral({ 'transport': { 'beacon': false, 'xhrpost': false, @@ -48,3 +50,5 @@ export const SHINYSTAT_CONFIG = /** @type {!JsonObject} */ ({ }, }, }); + +export {SHINYSTAT_CONFIG}; diff --git a/extensions/amp-analytics/0.1/vendors/simplereach.js b/extensions/amp-analytics/0.1/vendors/simplereach.js index b8a9270bf962..51f58da3ecdd 100644 --- a/extensions/amp-analytics/0.1/vendors/simplereach.js +++ b/extensions/amp-analytics/0.1/vendors/simplereach.js @@ -14,7 +14,9 @@ * limitations under the License. */ -export const SIMPLEREACH_CONFIG = /** @type {!JsonObject} */ ({ +import {jsonLiteral} from '../../../../src/json'; + +const SIMPLEREACH_CONFIG = jsonLiteral({ 'vars': { 'pid': '', 'published_at': '', @@ -57,3 +59,5 @@ export const SIMPLEREACH_CONFIG = /** @type {!JsonObject} */ ({ }, }, }); + +export {SIMPLEREACH_CONFIG}; diff --git a/extensions/amp-analytics/0.1/vendors/snowplow.js b/extensions/amp-analytics/0.1/vendors/snowplow.js index 4bc0a669f81a..7d0ee545ae07 100644 --- a/extensions/amp-analytics/0.1/vendors/snowplow.js +++ b/extensions/amp-analytics/0.1/vendors/snowplow.js @@ -14,7 +14,9 @@ * limitations under the License. */ -export const SNOWPLOW_CONFIG = /** @type {!JsonObject} */ ({ +import {jsonLiteral} from '../../../../src/json'; + +const SNOWPLOW_CONFIG = jsonLiteral({ 'vars': { 'duid': 'CLIENT_ID(_sp_id)', }, @@ -41,3 +43,5 @@ export const SNOWPLOW_CONFIG = /** @type {!JsonObject} */ ({ 'image': true, }, }); + +export {SNOWPLOW_CONFIG}; diff --git a/extensions/amp-analytics/0.1/vendors/teaanalytics.js b/extensions/amp-analytics/0.1/vendors/teaanalytics.js index 977296771267..554a28a35c68 100644 --- a/extensions/amp-analytics/0.1/vendors/teaanalytics.js +++ b/extensions/amp-analytics/0.1/vendors/teaanalytics.js @@ -14,7 +14,9 @@ * limitations under the License. */ -export const TEAANALYTICS_CONFIG = /** @type {!JsonObject} */ ({ +import {jsonLiteral} from '../../../../src/json'; + +const TEAANALYTICS_CONFIG = jsonLiteral({ vars: { userUniqueId: '${clientId(__tea_sdk__user_unique_id)}', debug: 0, @@ -45,3 +47,5 @@ export const TEAANALYTICS_CONFIG = /** @type {!JsonObject} */ ({ event: '${base}', }, }); + +export {TEAANALYTICS_CONFIG}; diff --git a/extensions/amp-analytics/0.1/vendors/tealiumcollect.js b/extensions/amp-analytics/0.1/vendors/tealiumcollect.js index 4539dbfbaadf..2876154e98f3 100644 --- a/extensions/amp-analytics/0.1/vendors/tealiumcollect.js +++ b/extensions/amp-analytics/0.1/vendors/tealiumcollect.js @@ -14,7 +14,9 @@ * limitations under the License. */ -export const TEALIUMCOLLECT_CONFIG = /** @type {!JsonObject} */ ({ +import {jsonLiteral} from '../../../../src/json'; + +const TEALIUMCOLLECT_CONFIG = jsonLiteral({ 'transport': { 'beacon': false, 'xhrpost': false, @@ -66,3 +68,5 @@ export const TEALIUMCOLLECT_CONFIG = /** @type {!JsonObject} */ ({ }, }, }); + +export {TEALIUMCOLLECT_CONFIG}; diff --git a/extensions/amp-analytics/0.1/vendors/top100.js b/extensions/amp-analytics/0.1/vendors/top100.js index 57985d364fe9..fc9a3aff2cb2 100644 --- a/extensions/amp-analytics/0.1/vendors/top100.js +++ b/extensions/amp-analytics/0.1/vendors/top100.js @@ -14,7 +14,9 @@ * limitations under the License. */ -export const TOP100_CONFIG = /** @type {!JsonObject} */ ({ +import {jsonLiteral} from '../../../../src/json'; + +const TOP100_CONFIG = jsonLiteral({ 'vars': { 'pid': '', 'rid': 'PAGE_VIEW_ID', @@ -54,3 +56,5 @@ export const TOP100_CONFIG = /** @type {!JsonObject} */ ({ 'image': true, }, }); + +export {TOP100_CONFIG}; diff --git a/extensions/amp-analytics/0.1/vendors/topmailru.js b/extensions/amp-analytics/0.1/vendors/topmailru.js index 26da8bc32850..e1dd146b0ddd 100644 --- a/extensions/amp-analytics/0.1/vendors/topmailru.js +++ b/extensions/amp-analytics/0.1/vendors/topmailru.js @@ -14,7 +14,9 @@ * limitations under the License. */ -export const TOPMAILRU_CONFIG = /** @type {!JsonObject} */ ({ +import {jsonLiteral} from '../../../../src/json'; + +const TOPMAILRU_CONFIG = jsonLiteral({ 'transport': { 'beacon': false, 'xhrpost': false, @@ -48,3 +50,5 @@ export const TOPMAILRU_CONFIG = /** @type {!JsonObject} */ ({ }, }, }); + +export {TOPMAILRU_CONFIG}; diff --git a/extensions/amp-analytics/0.1/vendors/treasuredata.js b/extensions/amp-analytics/0.1/vendors/treasuredata.js index b78d0def0cec..e788ec8d4d0f 100644 --- a/extensions/amp-analytics/0.1/vendors/treasuredata.js +++ b/extensions/amp-analytics/0.1/vendors/treasuredata.js @@ -14,7 +14,9 @@ * limitations under the License. */ -export const TREASUREDATA_CONFIG = /** @type {!JsonObject} */ ({ +import {jsonLiteral} from '../../../../src/json'; + +const TREASUREDATA_CONFIG = jsonLiteral({ 'vars': { 'host': 'in.treasuredata.com', 'writeKey': '', @@ -43,3 +45,5 @@ export const TREASUREDATA_CONFIG = /** @type {!JsonObject} */ ({ 'event': '${base}/${table}?${baseParams}', }, }); + +export {TREASUREDATA_CONFIG}; diff --git a/extensions/amp-analytics/0.1/vendors/umenganalytics.js b/extensions/amp-analytics/0.1/vendors/umenganalytics.js index c12e352a96dc..ae7fd0e872c4 100644 --- a/extensions/amp-analytics/0.1/vendors/umenganalytics.js +++ b/extensions/amp-analytics/0.1/vendors/umenganalytics.js @@ -14,7 +14,9 @@ * limitations under the License. */ -export const UMENGANALYTICS_CONFIG = /** @type {!JsonObject} */ ({ +import {jsonLiteral} from '../../../../src/json'; + +const UMENGANALYTICS_CONFIG = jsonLiteral({ 'vars': { 'siteid': '', 'initial_view_time': '', @@ -48,3 +50,5 @@ export const UMENGANALYTICS_CONFIG = /** @type {!JsonObject} */ ({ 'image': true, }, }); + +export {UMENGANALYTICS_CONFIG}; diff --git a/extensions/amp-analytics/0.1/vendors/upscore.js b/extensions/amp-analytics/0.1/vendors/upscore.js index 6b2fb1b1b82e..9cb0f84d884f 100644 --- a/extensions/amp-analytics/0.1/vendors/upscore.js +++ b/extensions/amp-analytics/0.1/vendors/upscore.js @@ -14,7 +14,9 @@ * limitations under the License. */ -export const UPSCORE_CONFIG = /**@type {!JsonObject} */ ({ +import {jsonLiteral} from '../../../../src/json'; + +const UPSCORE_CONFIG = jsonLiteral({ 'requests': { 'host': 'https://hit-pool.upscore.com/amp?', 'basePrefix': @@ -71,3 +73,5 @@ export const UPSCORE_CONFIG = /**@type {!JsonObject} */ ({ 'image': false, }, }); + +export {UPSCORE_CONFIG}; diff --git a/extensions/amp-analytics/0.1/vendors/vponanalytics.js b/extensions/amp-analytics/0.1/vendors/vponanalytics.js index 1523da8ee1b2..10b878dbfc0f 100644 --- a/extensions/amp-analytics/0.1/vendors/vponanalytics.js +++ b/extensions/amp-analytics/0.1/vendors/vponanalytics.js @@ -14,7 +14,9 @@ * limitations under the License. */ -export const VPONANALYTICS_CONFIG = /** @type {!JsonObject} */ ({ +import {jsonLiteral} from '../../../../src/json'; + +const VPONANALYTICS_CONFIG = jsonLiteral({ 'vars': { 'ctid': '${clientId(vpadn-ctid)}', }, @@ -62,3 +64,5 @@ export const VPONANALYTICS_CONFIG = /** @type {!JsonObject} */ ({ 'image': true, }, }); + +export {VPONANALYTICS_CONFIG}; diff --git a/extensions/amp-analytics/0.1/vendors/webengage.js b/extensions/amp-analytics/0.1/vendors/webengage.js index 6e7113dfac29..6c08229eaa20 100644 --- a/extensions/amp-analytics/0.1/vendors/webengage.js +++ b/extensions/amp-analytics/0.1/vendors/webengage.js @@ -14,7 +14,9 @@ * limitations under the License. */ -export const WEBENGAGE_CONFIG = /** @type {!JsonObject} */ ({ +import {jsonLiteral} from '../../../../src/json'; + +const WEBENGAGE_CONFIG = jsonLiteral({ 'requests': { 'base': 'https://c.${region}.webengage.com/amp?licenseCode=${licenseCode}&luid=${clientId(we_luid)}&pageUrl=${canonicalUrl}&pageTitle=${title}&referrer=${documentReferrer}&vh=${viewportHeight}&vw=${viewportWidth}&category=application', @@ -32,3 +34,5 @@ export const WEBENGAGE_CONFIG = /** @type {!JsonObject} */ ({ }, }, }); + +export {WEBENGAGE_CONFIG}; diff --git a/extensions/amp-analytics/0.1/vendors/webtrekk.js b/extensions/amp-analytics/0.1/vendors/webtrekk.js index f705ee86bdf5..5c25f83e8ffb 100644 --- a/extensions/amp-analytics/0.1/vendors/webtrekk.js +++ b/extensions/amp-analytics/0.1/vendors/webtrekk.js @@ -14,7 +14,9 @@ * limitations under the License. */ -export const WEBTREKK_CONFIG = /** @type {!JsonObject} */ ({ +import {jsonLiteral} from '../../../../src/json'; + +const WEBTREKK_CONFIG = jsonLiteral({ 'requests': { 'trackURL': 'https://${trackDomain}/${trackId}/wt', 'parameterPrefix': @@ -55,3 +57,5 @@ export const WEBTREKK_CONFIG = /** @type {!JsonObject} */ ({ 'image': true, }, }); + +export {WEBTREKK_CONFIG}; diff --git a/extensions/amp-analytics/0.1/vendors/webtrekk_v2.js b/extensions/amp-analytics/0.1/vendors/webtrekk_v2.js index 3a852c40cb63..6e46246a1393 100644 --- a/extensions/amp-analytics/0.1/vendors/webtrekk_v2.js +++ b/extensions/amp-analytics/0.1/vendors/webtrekk_v2.js @@ -14,7 +14,9 @@ * limitations under the License. */ -export const WEBTREKK_V2_CONFIG = /** @type {!JsonObject} */ ({ +import {jsonLiteral} from '../../../../src/json'; + +const WEBTREKK_V2_CONFIG = jsonLiteral({ 'vars': { 'actionName': 'webtrekk_ignore', 'contentId': '${title}', @@ -66,3 +68,5 @@ export const WEBTREKK_V2_CONFIG = /** @type {!JsonObject} */ ({ 'image': true, }, }); + +export {WEBTREKK_V2_CONFIG}; diff --git a/src/ad-cid.js b/src/ad-cid.js index 7fa11f270092..6b235657bc11 100644 --- a/src/ad-cid.js +++ b/src/ad-cid.js @@ -26,13 +26,13 @@ import {dev} from '../src/log'; */ export function getAdCid(adElement) { const config = adConfig[adElement.element.getAttribute('type')]; - if (!config || !config.clientIdScope) { + if (!config || !config['clientIdScope']) { return Promise.resolve(); } return getOrCreateAdCid( adElement.getAmpDoc(), - config.clientIdScope, - config.clientIdCookieName + config['clientIdScope'], + config['clientIdCookieName'] ); } diff --git a/src/json.js b/src/json.js index beda34676f10..9f82a2587b6a 100644 --- a/src/json.js +++ b/src/json.js @@ -27,7 +27,7 @@ import {isObject} from './types'; /** * JSON scalar. It's either string, number or boolean. - * @typedef {*} should be string|number|boolean + * @typedef {*} should be string|number|boolean|null */ let JSONScalarDef; @@ -223,3 +223,40 @@ function hasOwnProperty(obj, key) { key ); } + +/** + * This helper function handles configurations specified in a JSON format. + * + * It allows the configuration is to be written in plain JS (which has better + * dev ergonomics like comments and trailing commas), and allows the + * configuration to be transformed into an efficient JSON-parsed representation + * in the dist build. See https://v8.dev/blog/cost-of-javascript-2019#json + * + * @param {!Object} obj + * @return {!JsonObject} + */ +export function jsonConfiguration(obj) { + return /** @type {!JsonObject} */ (obj); +} + +/** + * This converts an Object into a suitable type to be used in `includeJsonLiteral`. + * This doesn't actually do any conversion, it only changes the closure type. + * + * @param {!Object|!Array|string|number|boolean|null} value + * @return {!InternalJsonLiteralTypeDef} + */ +export function jsonLiteral(value) { + return /** @type {!InternalJsonLiteralTypeDef} */ (value); +} + +/** + * Allows inclusion of a variable (that's wrapped in a jsonLiteral + * call) to be included inside a jsonConfiguration. + * + * @param {!InternalJsonLiteralTypeDef} value + * @return {*} + */ +export function includeJsonLiteral(value) { + return value; +}