bv-ui-core 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (122) hide show
  1. package/.eslintrc +40 -0
  2. package/.travis.yml +5 -0
  3. package/CONTRIBUTING.md +98 -0
  4. package/LICENSE.md +13 -0
  5. package/OWNERS +2 -0
  6. package/README.md +63 -0
  7. package/catalog-info.yaml +30 -0
  8. package/karma.conf.js +130 -0
  9. package/lib/README.md +61 -0
  10. package/lib/api/.babelrc +3 -0
  11. package/lib/api/.eslintrc +9 -0
  12. package/lib/api/README.md +134 -0
  13. package/lib/api/index.js +15 -0
  14. package/lib/api/statistics.js +148 -0
  15. package/lib/application/README.md +96 -0
  16. package/lib/application/index.js +171 -0
  17. package/lib/body/README.md +13 -0
  18. package/lib/body/index.js +19 -0
  19. package/lib/bvFetch/README.md +101 -0
  20. package/lib/bvFetch/index.js +383 -0
  21. package/lib/checkHighContrast/README.md +26 -0
  22. package/lib/checkHighContrast/index.js +36 -0
  23. package/lib/cookie/README.md +29 -0
  24. package/lib/cookie/index.js +111 -0
  25. package/lib/cookieConsent/README.md +41 -0
  26. package/lib/cookieConsent/index.js +227 -0
  27. package/lib/cssLoadChecker/README.md +19 -0
  28. package/lib/cssLoadChecker/index.js +72 -0
  29. package/lib/date.now/README.md +11 -0
  30. package/lib/date.now/index.js +40 -0
  31. package/lib/domainPolice/README.md +66 -0
  32. package/lib/domainPolice/index.js +95 -0
  33. package/lib/evented/README.md +42 -0
  34. package/lib/evented/index.js +135 -0
  35. package/lib/getOriginalConstructor/README.md +16 -0
  36. package/lib/getOriginalConstructor/index.js +52 -0
  37. package/lib/global/README.md +10 -0
  38. package/lib/global/index.js +48 -0
  39. package/lib/ie/README.md +13 -0
  40. package/lib/ie/index.js +25 -0
  41. package/lib/loader/README.md +73 -0
  42. package/lib/loader/index.js +358 -0
  43. package/lib/logger/README.md +82 -0
  44. package/lib/logger/index.js +180 -0
  45. package/lib/messageFormat/README.md +10 -0
  46. package/lib/messageFormat/index.js +42 -0
  47. package/lib/namespacer/README.md +57 -0
  48. package/lib/namespacer/index.js +98 -0
  49. package/lib/performance/README.md +35 -0
  50. package/lib/performance/entries.js +5 -0
  51. package/lib/performance/getEntries.js +42 -0
  52. package/lib/performance/getEntriesByName.js +61 -0
  53. package/lib/performance/getEntriesByType.js +55 -0
  54. package/lib/performance/index.js +11 -0
  55. package/lib/performance/mark.js +97 -0
  56. package/lib/performance/measure.js +106 -0
  57. package/lib/performance/now.js +63 -0
  58. package/lib/pixelsDisplayed/README.md +19 -0
  59. package/lib/pixelsDisplayed/index.js +113 -0
  60. package/lib/polyfills/README.md +39 -0
  61. package/lib/polyfills/fetch/Headers.js +3 -0
  62. package/lib/polyfills/fetch/Request.js +3 -0
  63. package/lib/polyfills/fetch/Response.js +3 -0
  64. package/lib/polyfills/fetch/fetch.js +3 -0
  65. package/lib/polyfills/fetch/index.js +57 -0
  66. package/lib/polyfills/promise.js +265 -0
  67. package/lib/queryShadowDom/README.md +50 -0
  68. package/lib/queryShadowDom/index.js +93 -0
  69. package/lib/region/README.md +64 -0
  70. package/lib/region/europe/index.js +94 -0
  71. package/lib/region/europe/territories.js +40 -0
  72. package/lib/region/index.js +123 -0
  73. package/lib/staticAssetLoader/README.md +116 -0
  74. package/lib/staticAssetLoader/index.js +248 -0
  75. package/lib/waitForBody/README.md +21 -0
  76. package/lib/waitForBody/index.js +36 -0
  77. package/mkdocs.yaml +5 -0
  78. package/package.json +55 -0
  79. package/test/.eslintrc +5 -0
  80. package/test/fixtures/lib.loader.document-is-wrong-in-ie8.js +5 -0
  81. package/test/fixtures/lib.loader.loadscript-attribute.js +3 -0
  82. package/test/fixtures/lib.loader.loadscript.js +3 -0
  83. package/test/fixtures/lib.loader.loadstylesheet.css +3 -0
  84. package/test/unit/api/.eslintrc +6 -0
  85. package/test/unit/api/index.spec.js +37 -0
  86. package/test/unit/api/response.json +67 -0
  87. package/test/unit/api/statistics.spec.js +218 -0
  88. package/test/unit/application/index.spec.js +313 -0
  89. package/test/unit/body/index.spec.js +15 -0
  90. package/test/unit/bvFetch/index.spec.js +246 -0
  91. package/test/unit/checkHighContrast/index.spec.js +16 -0
  92. package/test/unit/cookie/index.spec.js +191 -0
  93. package/test/unit/cookieConsent/index.spec.js +119 -0
  94. package/test/unit/cssLoadChecker/index.spec.js +75 -0
  95. package/test/unit/date.now/index.spec.js +21 -0
  96. package/test/unit/domainPolice/index.spec.js +141 -0
  97. package/test/unit/evented/index.spec.js +59 -0
  98. package/test/unit/getOriginalConstructor/index.spec.js +60 -0
  99. package/test/unit/global/index.spec.js +84 -0
  100. package/test/unit/ie/index.spec.js +14 -0
  101. package/test/unit/loader/index.spec.js +644 -0
  102. package/test/unit/logger/index.spec.js +141 -0
  103. package/test/unit/messageFormat/index.spec.js +31 -0
  104. package/test/unit/mochaInit.js +8 -0
  105. package/test/unit/namespacer/index.spec.js +100 -0
  106. package/test/unit/performance/getEntries.spec.js +30 -0
  107. package/test/unit/performance/getEntriesByName.spec.js +88 -0
  108. package/test/unit/performance/getEntriesByType.spec.js +48 -0
  109. package/test/unit/performance/index.spec.js +35 -0
  110. package/test/unit/performance/mark.spec.js +40 -0
  111. package/test/unit/performance/measure.spec.js +50 -0
  112. package/test/unit/performance/now.spec.js +21 -0
  113. package/test/unit/pixelsDisplayed/index.spec.js +271 -0
  114. package/test/unit/polyfills/fetch/Headers.js +12 -0
  115. package/test/unit/polyfills/fetch/Request.js +12 -0
  116. package/test/unit/polyfills/fetch/Response.js +12 -0
  117. package/test/unit/polyfills/fetch/fetch.js +12 -0
  118. package/test/unit/polyfills/fetch/index.js +61 -0
  119. package/test/unit/polyfills/promise.spec.js +48 -0
  120. package/test/unit/region/europe/index.spec.js +70 -0
  121. package/test/unit/region/index.spec.js +113 -0
  122. package/test/unit/staticAssetLoader/index.spec.js +215 -0
package/.eslintrc ADDED
@@ -0,0 +1,40 @@
1
+ {
2
+ "env": {
3
+ "node": true,
4
+ "browser": true,
5
+ "es6": true
6
+ },
7
+ "rules": {
8
+ "brace-style": [2, "stroustrup", { "allowSingleLine": true }],
9
+ "consistent-return": 0,
10
+ "curly": 2,
11
+ "eqeqeq": 2,
12
+ "indent": [2, 2, { "SwitchCase": 1 }],
13
+ "key-spacing": [2, {
14
+ "beforeColon": false,
15
+ "afterColon": true
16
+ }],
17
+ "keyword-spacing": [2, {"before": true, "after": true, "overrides": {}}],
18
+ "no-multiple-empty-lines": 2,
19
+ "no-throw-literal": 2,
20
+ "no-underscore-dangle": 0,
21
+ "no-unused-vars": [2, {
22
+ "vars": "all",
23
+ "args": "none"
24
+ }],
25
+ "no-use-before-define": [2, "nofunc"],
26
+ "object-curly-spacing": [2, "always"],
27
+ "quote-props": [2, "as-needed"],
28
+ "quotes": [2, "single"],
29
+ "radix": 2,
30
+ "space-before-blocks": [2, "always"],
31
+ "space-before-function-paren": [2, "always"],
32
+ "space-in-parens": [2, "never"],
33
+ "space-unary-ops": [2, {
34
+ "words": true,
35
+ "nonwords": false
36
+ }],
37
+ "strict": [2, "never"],
38
+ "wrap-iife": [2, "inside"]
39
+ }
40
+ }
package/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ language: node_js
2
+ node_js:
3
+ - "10"
4
+ install:
5
+ - npm install
@@ -0,0 +1,98 @@
1
+ # Contributing to bv-ui-core
2
+
3
+ ## Owners
4
+
5
+ - Reason (@reason-bv)
6
+ - Dan Heberden (@danheberden)
7
+
8
+ ## Getting Started
9
+
10
+ Start by creating a fork of this repo, cloning it locally, and installing the required Node modules:
11
+
12
+ ```sh
13
+ git clone git@github.com:<yourusername>/bv-ui-core.git
14
+ cd bv-ui-core
15
+ npm install
16
+ ```
17
+
18
+ Verify the installation by running `npm run dev`. This should open Chrome to the test page; you will need to open the browser's console to see the test results.
19
+
20
+ If you would like to submit a change to the repo, open a pull request *from a branch on your fork*. Do not create new branches on the main repo.
21
+
22
+ ## Adding New Modules
23
+
24
+ If you want to submit a new module, be certain to open an issue explaining the rationale for adding the module, as well as the proposed API for the module. **Please do not start the discussion with a pull request.**
25
+
26
+ Given that the modules in this repo are intended for use in user interfaces, please be extremely mindful of adding dependencies. Wherever possible, a module should allow dependencies to be passed to it as arguments:
27
+
28
+ ```js
29
+ module.exports = function myModule ($) {
30
+ return {
31
+ awesome: function (arg) {
32
+ return $(arg);
33
+ }
34
+ };
35
+ };
36
+ ```
37
+
38
+ ## File Structure
39
+
40
+ For a module `foo`, *at least* the following files should exist:
41
+
42
+ - `lib/foo/index.js`
43
+ - `lib/foo/README.md`
44
+ - `test/unit/foo/index.js`
45
+
46
+ ## Commit Hooks
47
+
48
+ This project uses [ghooks](https://github.com/gtramontina/ghooks) to manage Git hooks. The hooks run linting before each commit, and run the tests before each push.
49
+
50
+ ## Style
51
+
52
+ The coding style for this project is checked with [ESLint](http://eslint.org/), and defined by the .eslintrc file. To run ESLint:
53
+
54
+ ```
55
+ npm run lint
56
+ ```
57
+
58
+ If you see no output, no problems were found.
59
+
60
+ ## Tests
61
+
62
+ This project uses [tape](https://github.com/substack/tape). To run the tests:
63
+
64
+ ```bash
65
+ npm test
66
+ ```
67
+
68
+ To run the tests in a browser while you are doing development:
69
+
70
+ ```bash
71
+ npm run dev
72
+ ```
73
+
74
+ Note that the results appear in the console, not in the browser itself.
75
+
76
+ ## Local Development with Another Project
77
+
78
+ If you are working on this project alongside a project that uses it, you will likely want to use [`npm link`][npm-link]. It allows you to install an NPM package in your project from the local file system, rather than pulling the package down from NPM.
79
+
80
+ Assuming that you've checked out `bv-ui-core` to `~/code/bv-ui-core` and your project is at `~/code/my-project`, you can run the following commands in the shell to get your project to use the local bv-ui-core:
81
+
82
+ ```bash
83
+ cd ~/code/bv-ui-core
84
+ npm link
85
+ cd ~/code/my-project
86
+ npm link bv-ui-core
87
+ ```
88
+
89
+ Alternatively, you can combine the two steps into one:
90
+
91
+ ```bash
92
+ cd ~/code/my-project
93
+ npm link ../bv-ui-core
94
+ ```
95
+
96
+ See the [`npm link` documentation][npm-link] for more details.
97
+
98
+ [npm-link]: https://docs.npmjs.com/cli/link
package/LICENSE.md ADDED
@@ -0,0 +1,13 @@
1
+ Copyright 2015 Bazaarvoice, Inc.
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
package/OWNERS ADDED
@@ -0,0 +1,2 @@
1
+ # Owning team.
2
+ firebird-devs@bazaarvoice.com
package/README.md ADDED
@@ -0,0 +1,63 @@
1
+ ![](https://travis-ci.org/bazaarvoice/bv-ui-core.svg)
2
+
3
+ # bv-ui-core
4
+
5
+ This project provides a central location for common Bazaarvoice UI code. It is
6
+ intended to be installed into a project via NPM. Individual modules are authored
7
+ as CommonJS modules, to be consumed by Webpack or another build tool that can
8
+ ingest CommonJS.
9
+
10
+ **This is a public repository.** Please see the [contribution guidelines][1] for
11
+ details on contributing to this repo.
12
+
13
+ ## Installation
14
+
15
+ You will need NPM to add this to your project; it is installed when you install
16
+ Node, so it is likely that you already have it. If not, you can install Node
17
+ using an [installer][2], or by using your favorite package manager (such as
18
+ Homebrew).
19
+
20
+ Once you have NPM, you can install bv-ui-core as follows:
21
+
22
+ ```bash
23
+ npm install --save bv-ui-core
24
+ ```
25
+
26
+ ## Usage
27
+
28
+ Require bv-ui-core modules into your code:
29
+
30
+ ```javascript
31
+ var someModule = require('bv-ui-core/lib/someModule');
32
+ someModule.doThings();
33
+ ```
34
+
35
+ For details on how to use a specific module, see the README document in the
36
+ module's directory.
37
+
38
+ ## Modules
39
+
40
+ - [body](./lib/body)
41
+ - [bvFetch](./lib/bvFetch/)
42
+ - [checkHighContrast](./lib/checkHighContrast)
43
+ - [cookie](./lib/cookie)
44
+ - [cookieConsent](./lib/cookieConsent)
45
+ - [cssLoadChecker](./lib/cssLoadChecker)
46
+ - [date.now](./lib/date.now)
47
+ - [domainPolice](./lib/domainPolice)
48
+ - [evented](./lib/evented)
49
+ - [getOriginalConstructor](./lib/getOriginalConstructor)
50
+ - [global](./lib/global)
51
+ - [ie](./lib/ie)
52
+ - [loader](./lib/loader)
53
+ - [logger](./lib/logger)
54
+ - [namespacer](./lib/namespacer)
55
+ - [performance](./lib/performance)
56
+ - [polyfills](./lib/polyfills)
57
+ - [pixelsDisplayed](./lib/pixelsDisplayed)
58
+ - [staticAssetLoader](./lib/staticAssetLoader)
59
+ - [waitForBody](./lib/waitForBody)
60
+ - [queryShadowDom](./lib/queryShadowDom)
61
+
62
+ [1]: ./CONTRIBUTING.md
63
+ [2]: https://nodejs.org/download/
@@ -0,0 +1,30 @@
1
+ apiVersion: backstage.io/v1alpha1
2
+ kind: Component
3
+ metadata:
4
+ name: bv-ui-core
5
+ github.com/project-slug: bazaarvoice/bv-ui-core
6
+ description: This project provides a central location for common Bazaarvoice UI code. It is intended to be installed into a project via NPM. Individual modules are authored as CommonJS modules, to be consumed by Webpack or another build tool that can ingest CommonJS.
7
+ annotations:
8
+ backstage.io/techdocs-ref: dir:.
9
+ github.com/project-slug: bazaarvoice/bv-ui-core
10
+ links:
11
+ - url: https://bazaarvoice.slack.com/app_redirect?channel=sme-swat
12
+ title: Slack channel
13
+ icon: send
14
+ - url: https://sonarqube.qa.bazaarvoice.com/dashboard?id=bazaarvoice_bv-ui-core
15
+ title: SonarQube
16
+ icon: dashboard
17
+ labels:
18
+ tech: javascript
19
+ tags:
20
+ - javascript
21
+ - nodejs
22
+ spec:
23
+ type: library
24
+ system: swat
25
+ lifecycle: production
26
+ owner: swat
27
+
28
+
29
+
30
+
package/karma.conf.js ADDED
@@ -0,0 +1,130 @@
1
+ /**
2
+ * @fileOverview
3
+ * Karma configuration.
4
+ */
5
+
6
+ module.exports = function (config) {
7
+ config.set({
8
+
9
+ // Base path that will be used to resolve all patterns (eg. files, exclude).
10
+ basePath: '',
11
+
12
+ // Frameworks to use.
13
+ // See: https://npmjs.org/browse/keyword/karma-adapter
14
+ frameworks: ['mocha', 'chai', 'sinon-chai'],
15
+
16
+ client: {
17
+ mocha: {
18
+ // Change Karma's debug.html to the mocha web reporter.
19
+ reporter: 'html',
20
+ ui: 'bdd'
21
+ }
22
+ },
23
+ // list of files / patterns to load in the browser.
24
+ files: [
25
+ // We need the polyfill for testing es6 modules.
26
+ 'node_modules/babel-polyfill/dist/polyfill.js',
27
+ // Loaded into the browser test page.
28
+ 'test/unit/mochaInit.js',
29
+ 'test/unit/**/*.spec.js',
30
+
31
+ // Made available but not loaded. Note that the path for loading these
32
+ // files is prefixed with 'base/'.
33
+ {
34
+ pattern: 'test/fixtures/**',
35
+ included: false,
36
+ served: true,
37
+ watched: true,
38
+ nocache: true
39
+ },
40
+ ],
41
+
42
+ // List of files to exclude.
43
+ exclude: [],
44
+
45
+ // Preprocess matching files before serving them to the browser.
46
+ // See: https://npmjs.org/browse/keyword/karma-preprocessor
47
+ preprocessors: {
48
+ 'test/**/*.js': ['webpack']
49
+ },
50
+
51
+ coverageReporter: {
52
+ type: 'text',
53
+ dir: 'coverage/'
54
+ },
55
+
56
+ webpack: {
57
+ node: {
58
+ fs: 'empty'
59
+ },
60
+ // https://github.com/deepsweet/istanbul-instrumenter-loader allows
61
+ // code coverage of just the things we want.
62
+ module: {
63
+ loaders: [{
64
+ test: /\.js$/,
65
+ exclude: /(node_modules|bower_components)/,
66
+ loader: 'babel-loader',
67
+ query: {
68
+ plugins: ['lodash'],
69
+ presets: ['es2015']
70
+ }
71
+ }],
72
+ postLoaders: [{
73
+ test: /\.js$/,
74
+ exclude: /(test|node_modules)\//,
75
+ loader: 'istanbul-instrumenter'
76
+ }]
77
+ }
78
+ },
79
+
80
+ webpackMiddleware: {
81
+ noInfo: true
82
+ },
83
+
84
+ // Test results reporter to use. Possible values: 'dots', 'progress'.
85
+ // See: https://npmjs.org/browse/keyword/karma-reporter
86
+ reporters: [
87
+ 'dots',
88
+ 'coverage'
89
+ ],
90
+
91
+ // Web server port.
92
+ port: 9876,
93
+
94
+ // Enable / disable colors in the output (reporters and logs).
95
+ colors: true,
96
+
97
+ // Level of logging.
98
+ //
99
+ // possible values:
100
+ // config.LOG_DISABLE
101
+ // config.LOG_ERROR
102
+ // config.LOG_WARN
103
+ // config.LOG_INFO
104
+ // config.LOG_DEBUG
105
+ logLevel: config.LOG_INFO,
106
+
107
+ // Enable / disable watching file and executing tests whenever any file
108
+ // changes.
109
+ autoWatch: true,
110
+ customLaunchers: {
111
+ ChromeHeadless: {
112
+ base: 'Chrome',
113
+ flags: [
114
+ '--no-sandbox',
115
+ '--headless',
116
+ '--disable-gpu',
117
+ '--remote-debugging-port=9222'
118
+ ]
119
+ }
120
+ },
121
+
122
+ // Start these browsers.
123
+ // See: https://npmjs.org/browse/keyword/karma-launcher
124
+ browsers: ['ChromeHeadless'],
125
+
126
+ // Continuous Integration mode. If true, Karma captures browsers, runs the
127
+ // tests and exits.
128
+ singleRun: false
129
+ });
130
+ };
package/lib/README.md ADDED
@@ -0,0 +1,61 @@
1
+ ![](https://travis-ci.org/bazaarvoice/bv-ui-core.svg)
2
+
3
+ # bv-ui-core
4
+
5
+ This project provides a central location for common Bazaarvoice UI code. It is
6
+ intended to be installed into a project via NPM. Individual modules are authored
7
+ as CommonJS modules, to be consumed by Webpack or another build tool that can
8
+ ingest CommonJS.
9
+
10
+ **This is a public repository.** Please see the [contribution guidelines][1] for
11
+ details on contributing to this repo.
12
+
13
+ ## Installation
14
+
15
+ You will need NPM to add this to your project; it is installed when you install
16
+ Node, so it is likely that you already have it. If not, you can install Node
17
+ using an [installer][2], or by using your favorite package manager (such as
18
+ Homebrew).
19
+
20
+ Once you have NPM, you can install bv-ui-core as follows:
21
+
22
+ ```bash
23
+ npm install --save bv-ui-core
24
+ ```
25
+
26
+ ## Usage
27
+
28
+ Require bv-ui-core modules into your code:
29
+
30
+ ```javascript
31
+ var someModule = require('bv-ui-core/lib/someModule');
32
+ someModule.doThings();
33
+ ```
34
+
35
+ For details on how to use a specific module, see the README document in the
36
+ module's directory.
37
+
38
+ ## Modules
39
+
40
+ - [body](./lib/body)
41
+ - [checkHighContrast](./lib/checkHighContrast)
42
+ - [cookie](./lib/cookie)
43
+ - [cookieConsent](./lib/cookieConsent)
44
+ - [cssLoadChecker](./lib/cssLoadChecker)
45
+ - [date.now](./lib/date.now)
46
+ - [domainPolice](./lib/domainPolice)
47
+ - [evented](./lib/evented)
48
+ - [getOriginalConstructor](./lib/getOriginalConstructor)
49
+ - [global](./lib/global)
50
+ - [ie](./lib/ie)
51
+ - [loader](./lib/loader)
52
+ - [logger](./lib/logger)
53
+ - [namespacer](./lib/namespacer)
54
+ - [performance](./lib/performance)
55
+ - [polyfills](./lib/polyfills)
56
+ - [pixelsDisplayed](./lib/pixelsDisplayed)
57
+ - [staticAssetLoader](./lib/staticAssetLoader)
58
+ - [waitForBody](./lib/waitForBody)
59
+
60
+ [1]: ./CONTRIBUTING.md
61
+ [2]: https://nodejs.org/download/
@@ -0,0 +1,3 @@
1
+ {
2
+ "presets": ["es2015"]
3
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "env": {
3
+ "es6": true,
4
+ "browser": true
5
+ },
6
+ "parserOptions": {
7
+ "sourceType": "module"
8
+ }
9
+ }
@@ -0,0 +1,134 @@
1
+ ## API
2
+
3
+ This module acts as a javascript wrapper around api.bazaarvoice.com. For more
4
+ information about the API, please see the [API documentation][0].
5
+
6
+ ### Requirements
7
+
8
+ This module is written using ES6. In order to use the source you may need to
9
+ provide your own transpiler, depending on your supported browsers.
10
+
11
+ We also take advantage of some built-ins that you may need to polyfill:
12
+
13
+ - `fetch`: http://caniuse.com/#feat=fetch
14
+ - `Promise`: http://caniuse.com/#feat=promises
15
+
16
+ #### How to Use
17
+
18
+ Before using, you'll need to load up the API module:
19
+
20
+ ```javascript
21
+ const api = require('bv-ui-core/lib/api')
22
+ ```
23
+
24
+ Or if you know the specific type of request you are going to make, you can do the following:
25
+
26
+ ```javascript
27
+ const getStatistics = require('bv-ui-core/lib/api/statistics')
28
+ ```
29
+
30
+ ## METHODS
31
+
32
+ Supported methods:
33
+ * [statistics/getStatistics](#getstatistics)
34
+
35
+ ---
36
+
37
+ ### getStatistics
38
+
39
+ Returns the statistics for a given list of products.
40
+
41
+ #### Syntax
42
+
43
+ ```javascript
44
+ api.get('statistics', options)
45
+
46
+ // or
47
+ const getStatistics = require('bv-ui-core/lib/api/statistics')
48
+ getStatistics(options)
49
+ ```
50
+
51
+ #### Parameters
52
+
53
+ ##### options
54
+
55
+ An object with key/value pairs of inputs. Most values are required.
56
+
57
+ ##### options.productIds
58
+
59
+ An array of product ids to query for. A warning will be emitted if over 100 products are requested.
60
+
61
+ ##### options.environment
62
+
63
+ A string representing the data environment. Accepts `qa`, `staging` or
64
+ `production`.
65
+
66
+ ##### options.key
67
+
68
+ Your api key.
69
+
70
+ ##### options.type
71
+
72
+ A string representing the type of statistics you want to query for. Currently
73
+ accepts `Reviews` or `NativeReviews`.
74
+
75
+ Using `Reviews` returns statistics for all content, including syndicated
76
+ content (if enabled on your API key). If you only want statistics for reviews
77
+ you own that were written for the products specified, use `NativeReviews`
78
+ instead.
79
+
80
+ ##### options.filters (optional)
81
+
82
+ An object representing filters keyed by the name of the filter. `ContentLocale `
83
+ can be provided to specify a locale subset for the statistics. If no
84
+ `ContentLocale` is provided, will return the global statistics for each product
85
+ in the query.
86
+
87
+ Example:
88
+
89
+ ```javascript
90
+ getStatistics({
91
+ ...
92
+ filters: {
93
+ ContentLocale: 'en_US'
94
+ }
95
+ })
96
+
97
+ // Results in a call to
98
+ // api.bazaarvoice.com?...&filter=ContentLocale:en_US
99
+ ```
100
+
101
+
102
+ #### Description
103
+
104
+ The getStatistics call will return an array of Results or the error message
105
+ (if any) from the API.
106
+
107
+ #### Examples
108
+
109
+ ```javascript
110
+ //Get all syndicated review statistics for product1, product2
111
+ //and product3 from the en_US locale.
112
+ getStatistics({
113
+ productIds: ['product1', 'product2', 'product3'],
114
+ environment: 'qa',
115
+ key: 'clients_api_key',
116
+ type: 'Reviews',
117
+ filters: {
118
+ ContentLocale: 'en_US'
119
+ }
120
+ }).then(results => {
121
+ // Do something with results array.
122
+ }, error => {
123
+ // Do something with the error.
124
+ // Format will be:
125
+ // {
126
+ // Message: 'foo',
127
+ // Code: 'BAR'
128
+ // }
129
+ })
130
+ ```
131
+
132
+ ---
133
+
134
+ [0]: https://developer.bazaarvoice.com/docs/read/conversations
@@ -0,0 +1,15 @@
1
+ import { default as getStatistics } from './statistics'
2
+
3
+ const typeMap = {
4
+ statistics: getStatistics
5
+ }
6
+
7
+ function get (type, options = {}) {
8
+ const call = typeMap[type]
9
+ if (!call) {
10
+ throw new TypeError(`Unsupported method: ${type}`)
11
+ }
12
+ return call(options)
13
+ }
14
+
15
+ export { get, getStatistics }