Skip to content

Commit

Permalink
dont export generateRandomId from calypso-analytics
Browse files Browse the repository at this point in the history
  • Loading branch information
roo2 committed Feb 6, 2020
1 parent 890151e commit a452f92
Show file tree
Hide file tree
Showing 6 changed files with 269 additions and 31 deletions.
2 changes: 1 addition & 1 deletion client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
},
"main": "server/index.js",
"dependencies": {
"@automattic/calypso-analytics": "file:../packages/calypso-analytics",
"@automattic/calypso-polyfills": "file:../packages/calypso-polyfills",
"@automattic/color-studio": "2.2.0",
"@automattic/components": "file:../packages/components",
Expand All @@ -24,7 +25,6 @@
"@automattic/react-virtualized": "9.21.2",
"@automattic/tree-select": "file:../packages/tree-select",
"@babel/runtime": "7.8.4",
"@automattic/calypso-analytics": "file:../packages/calypso-analytics",
"@emotion/core": "10.0.22",
"@emotion/styled": "10.0.23",
"@github/webauthn-json": "0.4.1",
Expand Down
18 changes: 16 additions & 2 deletions client/reader/search-stream/suggestion-provider.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,29 @@
*/
import { connect } from 'react-redux';
import React, { Component } from 'react';
import { map, sampleSize } from 'lodash';
import { map, sampleSize, times } from 'lodash';

/**
* Internal Dependencies
*/
import { getLocaleSlug } from 'lib/i18n-utils';
import { suggestions } from 'reader/search-stream/suggestions';
import getReaderFollowedTags from 'state/selectors/get-reader-followed-tags';
import { createRandomId } from '@automattic/calypso-analytics';

function createRandomId( randomBytesLength = 9 ) {
// 9 * 4/3 = 12
// this is to avoid getting padding of a random byte string when it is base64 encoded
let randomBytes;

if ( window.crypto && window.crypto.getRandomValues ) {
randomBytes = new Uint8Array( randomBytesLength );
window.crypto.getRandomValues( randomBytes );
} else {
randomBytes = times( randomBytesLength, () => Math.floor( Math.random() * 256 ) );
}

return window.btoa( String.fromCharCode.apply( String, randomBytes ) );
}

/**
* Build suggestions from subscribed tags
Expand Down
243 changes: 234 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions packages/calypso-analytics/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@
"prepare": "transpile"
},
"dependencies": {
"@automattic/load-script": "file:../load-script",
"debug": "^4.1.1",
"hash.js": "^1.1.7",
"lodash": "^4.17.15",
"qs": "^6.9.1",
"debug": "^4.1.1",
"@automattic/load-script": "file:../load-script"
"qs": "^6.9.1"
}
}
1 change: 0 additions & 1 deletion packages/calypso-analytics/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,4 @@ export {
initializeAnalytics,
getTracksAnonymousUserId,
analyticsEvents,
createRandomId,
} from './tracks';
Loading

0 comments on commit a452f92

Please sign in to comment.