Skip to content

Commit

Permalink
Fix deprecation upgrade code for speech credentials (#2824)
Browse files Browse the repository at this point in the history
* Fix credentials function and allow empty reference grammar ID

* Add entry

* Add more tests

* Update entry

* Fix ESLint

* Use .eslintignore
  • Loading branch information
compulim authored and corinagum committed Jan 17, 2020
1 parent 5d26068 commit 0b0708f
Show file tree
Hide file tree
Showing 16 changed files with 295 additions and 20 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Fixes [#2145](https://github.com/microsoft/BotFramework-WebChat/issues/2145). Updated Adaptive Cards styles to include action styles, by [@tdurnford](https://github.com/tdurnford) in PR [#2810](https://github.com/microsoft/BotFramework-WebChat/pull/2810)
- Fixes [#2459](https://github.com/microsoft/BotFramework-WebChat/issues/2459). Updated Cognitive Services Speech Services to use latest fetch credentials signature, by [@compulim](https://github.com/compulim) in PR [#2740](https://github.com/microsoft/BotFramework-WebChat/pull/2759)
- Fixes [#1673](https://github.com/microsoft/BotFramework-WebChat/issues/1673). Configured suggested action and carousel flippers to blur on click, by [@tdunford](https://github.com/tdurnford) in PR [#2801](https://github.com/microsoft/BotFramework-WebChat/pull/2801)
- Fixes [#2822](https://github.com/microsoft/BotFramework-WebChat/issues/2822). Fixed `credentials` should return `authorizationToken` and `subscriptionKey` as string and allow empty LUIS reference grammar ID, by [@compulim](https://github.com/compulim) in PR [#2824](https://github.com/microsoft/BotFramework-WebChat/pull/2824)

### Changed

Expand Down
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,7 @@ import ReactWebChat, { createDirectLine } from 'botframework-webchat';
export default () => {
const directLine = useMemo(() => createDirectLine({ token: 'YOUR_DIRECT_LINE_TOKEN' }), []);

return (
<ReactWebChat directLine={ directLine } userID="YOUR_USER_ID" />
);
return <ReactWebChat directLine={directLine} userID="YOUR_USER_ID" />;
};
```

Expand Down
9 changes: 9 additions & 0 deletions packages/bundle/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/src/__tests__/**/*
/src/**/*.spec.js
/src/**/*.spec.jsx
/src/**/*.spec.ts
/src/**/*.spec.tsx
/src/**/*.test.js
/src/**/*.test.jsx
/src/**/*.test.ts
/src/**/*.test.tsx
2 changes: 1 addition & 1 deletion packages/bundle/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"build:babel": "babel src --extensions .js,.ts,.tsx --ignore **/*.spec.js,**/*.spec.ts,**/*.spec.tsx,**/*.test.js,**/*.test.ts,**/*.test.tsx,__tests__/**/*.js,__tests__/**/*.ts,__tests__/**/*.tsx --out-dir lib --verbose",
"build:typescript": "tsc --project src/tsconfig.json",
"build:webpack": "webpack-cli",
"eslint": "eslint src/**/*.js src/**/*.ts --ignore-pattern *.spec.[jt]sx? --ignore-pattern *.test.[jt]sx? --ignore-pattern __tests__",
"eslint": "eslint src/**/*.js src/**/*.ts",
"prestart": "npm run build:babel",
"start": "concurrently --kill-others --names \"babel,tsc,webpack\" \"npm run start:babel\" \"npm run start:typescript\" \"npm run start:webpack\"",
"start:babel": "npm run build:babel -- --skip-initial-build --watch",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { AudioConfig } from 'microsoft-cognitiveservices-speech-sdk/distrib/lib/src/sdk/Audio/AudioConfig';
import createPonyfill from 'web-speech-cognitive-services/lib/SpeechServices';

async function resolveFunction(fnOrValue) {
return await (typeof fnOrValue === 'function' ? fnOrValue() : fnOrValue);
function resolveFunction(fnOrValue) {
return typeof fnOrValue === 'function' ? fnOrValue() : fnOrValue;
}

export default function createCognitiveServicesSpeechServicesPonyfillFactory({
Expand All @@ -25,15 +25,15 @@ export default function createCognitiveServicesSpeechServicesPonyfillFactory({
credentials = async () => {
if (authorizationToken) {
return {
authorizationToken: resolveFunction(authorizationToken),
authorizationToken: await resolveFunction(authorizationToken),
region
};
} else {
return {
region,
subscriptionKey: resolveFunction(subscriptionKey)
};
}

return {
region,
subscriptionKey: await resolveFunction(subscriptionKey)
};
};
}

Expand All @@ -57,12 +57,12 @@ export default function createCognitiveServicesSpeechServicesPonyfillFactory({
};
}

return ({ referenceGrammarID }) => {
return ({ referenceGrammarID } = {}) => {
const ponyfill = createPonyfill({
audioConfig,
credentials,
enableTelemetry,
referenceGrammars: [`luis/${referenceGrammarID}-PRODUCTION`],
referenceGrammars: referenceGrammarID ? [`luis/${referenceGrammarID}-PRODUCTION`] : [],
speechRecognitionEndpointId,
speechSynthesisDeploymentId,
speechSynthesisOutputFormat,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,220 @@
let consoleWarns;
let createCognitiveServicesSpeechServicesPonyfillFactory;
let createPonyfill;
let originalConsole;

async function resolveFunctionOrValue(fnOrValue) {
return await (typeof fnOrValue === 'function' ? fnOrValue() : fnOrValue);
}

beforeEach(() => {
jest.mock('web-speech-cognitive-services/lib/SpeechServices', () => jest.fn(() => ({})));

originalConsole = console;
consoleWarns = [];

console = {
...console,
warn: text => consoleWarns.push(text)
};

createPonyfill = require('web-speech-cognitive-services/lib/SpeechServices');
createCognitiveServicesSpeechServicesPonyfillFactory = require('./createCognitiveServicesSpeechServicesPonyfillFactory')
.default;
});

afterEach(() => {
console = originalConsole;

jest.resetModules();
});

test('upgrading string-based authorizationToken to credentials', async () => {
const ponyfillFactory = createCognitiveServicesSpeechServicesPonyfillFactory({
authorizationToken: 'a1b2c3d',
region: 'westus2'
});

ponyfillFactory();

const { credentials } = createPonyfill.mock.calls[0][0];

await expect(resolveFunctionOrValue(credentials)).resolves.toEqual({
authorizationToken: 'a1b2c3d',
region: 'westus2'
});

expect(consoleWarns[0]).toMatchInlineSnapshot(
`"botframework-webchat: \\"authorizationToken\\", \\"region\\", and \\"subscriptionKey\\" are being deprecated and will be removed on or after 2020-12-17. Please use \\"credentials\\" instead."`
);
});

test('upgrading Promise-based authorizationToken to credentials', async () => {
const ponyfillFactory = createCognitiveServicesSpeechServicesPonyfillFactory({
authorizationToken: (async () => 'a1b2c3d')(),
region: 'westus2'
});

ponyfillFactory();

const { credentials } = createPonyfill.mock.calls[0][0];

await expect(resolveFunctionOrValue(credentials)).resolves.toEqual({
authorizationToken: 'a1b2c3d',
region: 'westus2'
});

expect(consoleWarns[0]).toMatchInlineSnapshot(
`"botframework-webchat: \\"authorizationToken\\", \\"region\\", and \\"subscriptionKey\\" are being deprecated and will be removed on or after 2020-12-17. Please use \\"credentials\\" instead."`
);
});

test('upgrading function-based authorizationToken to credentials', async () => {
const ponyfillFactory = createCognitiveServicesSpeechServicesPonyfillFactory({
authorizationToken: () => 'a1b2c3d',
region: 'westus2'
});

ponyfillFactory();

const { credentials } = createPonyfill.mock.calls[0][0];

await expect(resolveFunctionOrValue(credentials)).resolves.toEqual({
authorizationToken: 'a1b2c3d',
region: 'westus2'
});

expect(consoleWarns[0]).toMatchInlineSnapshot(
`"botframework-webchat: \\"authorizationToken\\", \\"region\\", and \\"subscriptionKey\\" are being deprecated and will be removed on or after 2020-12-17. Please use \\"credentials\\" instead."`
);
});

test('upgrading Promise function-based authorizationToken to credentials', async () => {
const ponyfillFactory = createCognitiveServicesSpeechServicesPonyfillFactory({
authorizationToken: async () => 'a1b2c3d',
region: 'westus2'
});

ponyfillFactory();

const { credentials } = createPonyfill.mock.calls[0][0];

await expect(resolveFunctionOrValue(credentials)).resolves.toEqual({
authorizationToken: 'a1b2c3d',
region: 'westus2'
});

expect(consoleWarns[0]).toMatchInlineSnapshot(
`"botframework-webchat: \\"authorizationToken\\", \\"region\\", and \\"subscriptionKey\\" are being deprecated and will be removed on or after 2020-12-17. Please use \\"credentials\\" instead."`
);
});

test('upgrading string-based subscriptionKey to credentials', async () => {
const ponyfillFactory = createCognitiveServicesSpeechServicesPonyfillFactory({
region: 'westus2',
subscriptionKey: 'a1b2c3d'
});

ponyfillFactory();

const { credentials } = createPonyfill.mock.calls[0][0];

await expect(resolveFunctionOrValue(credentials)).resolves.toEqual({
region: 'westus2',
subscriptionKey: 'a1b2c3d'
});

expect(consoleWarns[0]).toMatchInlineSnapshot(
`"botframework-webchat: \\"authorizationToken\\", \\"region\\", and \\"subscriptionKey\\" are being deprecated and will be removed on or after 2020-12-17. Please use \\"credentials\\" instead."`
);
});

test('upgrading string-based subscriptionKey to credentials', async () => {
const ponyfillFactory = createCognitiveServicesSpeechServicesPonyfillFactory({
region: 'westus2',
subscriptionKey: (async () => 'a1b2c3d')()
});

ponyfillFactory();

const { credentials } = createPonyfill.mock.calls[0][0];

await expect(resolveFunctionOrValue(credentials)).resolves.toEqual({
region: 'westus2',
subscriptionKey: 'a1b2c3d'
});

expect(consoleWarns[0]).toMatchInlineSnapshot(
`"botframework-webchat: \\"authorizationToken\\", \\"region\\", and \\"subscriptionKey\\" are being deprecated and will be removed on or after 2020-12-17. Please use \\"credentials\\" instead."`
);
});

test('upgrading function-based subscriptionKey to credentials', async () => {
const ponyfillFactory = createCognitiveServicesSpeechServicesPonyfillFactory({
region: 'westus2',
subscriptionKey: () => 'a1b2c3d'
});

ponyfillFactory();

const { credentials } = createPonyfill.mock.calls[0][0];

await expect(resolveFunctionOrValue(credentials)).resolves.toEqual({
region: 'westus2',
subscriptionKey: 'a1b2c3d'
});

expect(consoleWarns[0]).toMatchInlineSnapshot(
`"botframework-webchat: \\"authorizationToken\\", \\"region\\", and \\"subscriptionKey\\" are being deprecated and will be removed on or after 2020-12-17. Please use \\"credentials\\" instead."`
);
});

test('upgrading Promise function-based subscriptionKey to credentials', async () => {
const ponyfillFactory = createCognitiveServicesSpeechServicesPonyfillFactory({
region: 'westus2',
subscriptionKey: async () => 'a1b2c3d'
});

ponyfillFactory();

const { credentials } = createPonyfill.mock.calls[0][0];

await expect(resolveFunctionOrValue(credentials)).resolves.toEqual({
region: 'westus2',
subscriptionKey: 'a1b2c3d'
});

expect(consoleWarns[0]).toMatchInlineSnapshot(
`"botframework-webchat: \\"authorizationToken\\", \\"region\\", and \\"subscriptionKey\\" are being deprecated and will be removed on or after 2020-12-17. Please use \\"credentials\\" instead."`
);
});

test('providing reference grammar ID', () => {
const ponyfillFactory = createCognitiveServicesSpeechServicesPonyfillFactory({
credentials: {
authorizationToken: 'a1b2c3d',
region: 'westus2'
}
});

ponyfillFactory({ referenceGrammarID: 'a1b2c3d' });

const { referenceGrammars } = createPonyfill.mock.calls[0][0];

expect(referenceGrammars).toEqual(['luis/a1b2c3d-PRODUCTION']);
});

test('not providing reference grammar ID', () => {
const ponyfillFactory = createCognitiveServicesSpeechServicesPonyfillFactory({
credentials: {
authorizationToken: 'a1b2c3d',
region: 'westus2'
}
});

ponyfillFactory({});

const { referenceGrammars } = createPonyfill.mock.calls[0][0];

expect(referenceGrammars).toEqual([]);
});
9 changes: 9 additions & 0 deletions packages/component/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/src/__tests__/**/*
/src/**/*.spec.js
/src/**/*.spec.jsx
/src/**/*.spec.ts
/src/**/*.spec.tsx
/src/**/*.test.js
/src/**/*.test.jsx
/src/**/*.test.ts
/src/**/*.test.tsx
2 changes: 1 addition & 1 deletion packages/component/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"build": "npm run build:typescript && npm run build:babel",
"build:babel": "babel src --extensions .js,.ts,.tsx --ignore **/*.spec.js,**/*.spec.ts,**/*.spec.tsx,**/*.test.js,**/*.test.ts,**/*.test.tsx,__tests__/**/*.js,__tests__/**/*.ts,__tests__/**/*.tsx --out-dir lib --verbose",
"build:typescript": "tsc --project src/tsconfig.json",
"eslint": "eslint src/**/*.js src/**/*.ts --ignore-pattern *.spec.[jt]sx? --ignore-pattern *.test.[jt]sx? --ignore-pattern __tests__",
"eslint": "eslint src/**/*.js src/**/*.ts",
"prestart": "npm run build:babel",
"start": "concurrently --kill-others --names \"babel,tsc\" \"npm run start:babel\" \"npm run start:typescript\"",
"start:babel": "npm run build:babel -- --skip-initial-build --watch",
Expand Down
9 changes: 9 additions & 0 deletions packages/core/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/src/__tests__/**/*
/src/**/*.spec.js
/src/**/*.spec.jsx
/src/**/*.spec.ts
/src/**/*.spec.tsx
/src/**/*.test.js
/src/**/*.test.jsx
/src/**/*.test.ts
/src/**/*.test.tsx
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"build": "npm run build:typescript && npm run build:babel",
"build:babel": "babel src --extensions .js,.ts,.tsx --ignore **/*.spec.js,**/*.spec.ts,**/*.spec.tsx,**/*.test.js,**/*.test.ts,**/*.test.tsx,__tests__/**/*.js,__tests__/**/*.ts,__tests__/**/*.tsx --out-dir lib --verbose",
"build:typescript": "tsc --project src/tsconfig.json",
"eslint": "eslint src/**/*.js src/**/*.ts --ignore-pattern *.spec.[jt]sx? --ignore-pattern *.test.[jt]sx? --ignore-pattern __tests__",
"eslint": "eslint src/**/*.js src/**/*.ts",
"prestart": "npm run build:babel",
"start": "concurrently --kill-others --names \"babel,tsc\" \"npm run start:babel\" \"npm run start:typescript\"",
"start:babel": "npm run build:babel -- --skip-initial-build --watch",
Expand Down
9 changes: 9 additions & 0 deletions packages/directlinespeech/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/src/__tests__/**/*
/src/**/*.spec.js
/src/**/*.spec.jsx
/src/**/*.spec.ts
/src/**/*.spec.tsx
/src/**/*.test.js
/src/**/*.test.jsx
/src/**/*.test.ts
/src/**/*.test.tsx
2 changes: 1 addition & 1 deletion packages/directlinespeech/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"build:webpack": "concurrently --names \"dev,prod\" \"npm run build:webpack:development\" \"npm run build:webpack:production\"",
"build:webpack:development": "cross-env node_env=development webpack-cli",
"build:webpack:production": "cross-env node_env=production webpack-cli",
"eslint": "eslint src/**/*.js --ignore-pattern *.spec.js --ignore-pattern *.test.js --ignore-pattern __tests__",
"eslint": "eslint src/**/*.js",
"prestart": "npm run build:babel",
"start": "npm run start:babel && concurrently --kill-others --names \"babel,serve,webpack\" \"npm run start:babel:watch\" \"npm run start:serve\" \"npm run start:webpack\"",
"start:babel": "npm run build:babel --",
Expand Down
9 changes: 9 additions & 0 deletions packages/isomorphic-react-dom/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/src/__tests__/**/*
/src/**/*.spec.js
/src/**/*.spec.jsx
/src/**/*.spec.ts
/src/**/*.spec.tsx
/src/**/*.test.js
/src/**/*.test.jsx
/src/**/*.test.ts
/src/**/*.test.tsx
9 changes: 9 additions & 0 deletions packages/isomorphic-react/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/src/__tests__/**/*
/src/**/*.spec.js
/src/**/*.spec.jsx
/src/**/*.spec.ts
/src/**/*.spec.tsx
/src/**/*.test.js
/src/**/*.test.jsx
/src/**/*.test.ts
/src/**/*.test.tsx
2 changes: 1 addition & 1 deletion samples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ Here you can find all hosted samples of [Web Chat](https://github.com/microsoft/
| [`06.recomposing-ui/b.speech-ui`](https://github.com/microsoft/BotFramework-WebChat/tree/master/samples/06.recomposing-ui/b.speech-ui) | Advanced tutorial: Demonstrates how to fully customize key components of your bot, in this case speech, which entirely replaces the text-based transcript UI and instead shows a simple speech button with the bot's response. | [Speech UI Demo](https://microsoft.github.io/BotFramework-WebChat/06.recomposing-ui/b.speech-ui) |
| [`06.recomposing-ui/c.smart-display`](https://github.com/microsoft/BotFramework-WebChat/tree/master/samples/06.recomposing-ui/c.smart-display) | Demonstrates how to compose Web Chat UI into a Smart Display | [Smart Display Demo](https://microsoft.github.io/BotFramework-WebChat/06.recomposing-ui/c.smart-display) |
| [`06.recomposing-ui/d.plain-ui`](https://github.com/microsoft/BotFramework-WebChat/tree/master/samples/06.recomposing-ui/d.plain-ui) | Advanced tutorial: Demonstrates how to customize the Web Chat UI by building from ground up instead of needing to rewrite entire Web Chat components. | [Plain UI Demo](https://microsoft.github.io/BotFramework-WebChat/06.recomposing-ui/d.plain-ui) |
| **Advanced Web Chat apps** | | |
| **Advanced Web Chat apps** | | |
| [`07.advanced-web-chat-apps/a.upload-to-azure-storage`](https://github.com/microsoft/BotFramework-WebChat/tree/master/samples/07.advanced-web-chat-apps/a.upload-to-azure-storage) | Demonstrates how to use upload attachments directly to Azure Storage | [Upload to Azure Storage Demo](https://microsoft.github.io/BotFramework-WebChat/07.advanced-web-chat-apps/a.upload-to-azure-storage) |
| [`07.advanced-web-chat-apps/b.sso-for-enterprise`](https://github.com/microsoft/BotFramework-WebChat/tree/master/samples/07.advanced-web-chat-apps/b.sso-for-enterprise) | Demonstrates how to use single sign-on for enterprise single-page applications using OAuth | [Single Sign-On for Enterprise Single-Page Applications Demo](https://microsoft.github.io/BotFramework-WebChat/07.advanced-web-chat-apps/b.sso-for-enterprise) |
| [`07.advanced-web-chat-apps/c.sso-for-intranet`](https://github.com/microsoft/BotFramework-WebChat/tree/master/samples/07.advanced-web-chat-apps/c.sso-for-intranet) | Demonstrates how to use single sign-on for Intranet apps using Azure Active Directory | [Single Sign-On for Intranet Apps Demo](https://microsoft.github.io/BotFramework-WebChat/07.advanced-web-chat-apps/c.sso-for-intranet) |
Expand Down
Loading

0 comments on commit 0b0708f

Please sign in to comment.