How to use the math-random function in math-random

To help you get started, we’ve selected a few math-random examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github microsoft / botframework-solutions / solutions / testharnesses / typescript / assistant-WebChat / packages / app / src / index.js View on Github external
import * as serviceWorker from './serviceWorker';
import App from './App';

import connectUsingSecret from './redux/actions/connectUsingSecret';
import connectUsingTokenServer from './redux/actions/connectUsingTokenServer';
import enableSpeechUsingSecret from './redux/actions/enableSpeechUsingSecret';
import enableSpeechUsingTokenServer from './redux/actions/enableSpeechUsingTokenServer';
import createStore from './redux/createStore';

const store = createStore();

// TODO: Move it somewhere
const { directLineSecret, speechServicesSubscriptionKey } = store.getState();

if (directLineSecret) {
  store.dispatch(connectUsingSecret(directLineSecret, random().toString(36).substr(2, 10)));
} else {
  store.dispatch(connectUsingTokenServer());
}

if (speechServicesSubscriptionKey) {
  store.dispatch(enableSpeechUsingSecret(speechServicesSubscriptionKey));
} else {
  store.dispatch(enableSpeechUsingTokenServer());
}

ReactDOM.render(
  
    
  ,
  document.getElementById('root')
);
github microsoft / botframework-solutions / solutions / testharnesses / typescript / assistant-WebChat / packages / server / src / index.js View on Github external
server.post('/api/directline/token', async (_, res) => {
    // TODO: We should rate-limit to prevent abuse
    try {
      const userID = `dl_${ random().toString(36).substr(2, 10) }`;
      const tokenRes = await fetch('https://directline.botframework.com/v3/directline/tokens/generate', {
        body: JSON.stringify({
          User: { Id: userID }
        }),
        headers: {
          authorization: `Bearer ${ directLineSecret }`,
          'content-type': 'application/json'
        },
        method: 'POST'
      });

      if (!tokenRes.ok) {
        return res.send(503, { message: 'failed to exchange Direct Line secret', innerStatus: tokenRes.status });
      }

      const { expires_in: expiresIn, token } = JSON.parse(await tokenRes.text());
github microsoft / botframework-solutions / solutions / testharnesses / typescript / assistant-WebChat / packages / app / src / redux / actions / connectUsingSecret.js View on Github external
export default function (secret, userID = `dl_${ random().toString(36).substr(2, 10) }`) {
  return async dispatch => {
    dispatch({ type: CONNECT_PENDING });

    try {
      const tokenRes = await fetch('https://directline.botframework.com/v3/directline/tokens/generate', {
        body: JSON.stringify({
          User: { Id: userID }
        }),
        headers: {
          authorization: `Bearer ${ secret }`,
          'content-type': 'application/json'
        },
        method: 'POST'
      });

      if (!tokenRes.ok) {
github microsoft / BotFramework-WebChat / packages / core / src / utils / uniqueID.js View on Github external
export default function uniqueID() {
  return (
    Date.now() +
    random()
      .toString(36)
      .substr(2)
  );
}

math-random

math-random is an isomorphic, drop-in replacement for `Math.random` that uses cryptographically secure random number generation, where available

CC0-1.0
Latest version published 4 years ago

Package Health Score

65 / 100
Full package analysis