From 90a88d89aed2da5e05fd8491fc37912563e322b0 Mon Sep 17 00:00:00 2001 From: Jared Perreault Date: Tue, 1 Aug 2023 10:53:20 -0400 Subject: [PATCH 1/4] prevents removing dup message keys with GenericRemediator --- lib/idx/util.ts | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/lib/idx/util.ts b/lib/idx/util.ts index 7d3f1a34a..9c09b8081 100644 --- a/lib/idx/util.ts +++ b/lib/idx/util.ts @@ -67,19 +67,20 @@ export function getMessagesFromResponse(idxResponse: IdxResponse, options: RunOp messages = [...messages, ...fieldMessages] as never; } } - } - // API may return identical error on same field, filter by i18n key - const seen = {}; - messages = messages.reduce((filtered, message) => { - const key = message.i18n?.key; - if (key && seen[key]) { + // API may return identical error on same field, filter by i18n key + const seen = {}; + messages = messages.reduce((filtered, message) => { + const key = message.i18n?.key; + if (key && seen[key]) { + return filtered; + } + seen[key] = message; + filtered = [...filtered, message] as never; return filtered; - } - seen[key] = message; - filtered = [...filtered, message] as never; - return filtered; - }, []); + }, []); + } + return messages; } From 29e4afaafe6a68870947a032e819051d7a95f24f Mon Sep 17 00:00:00 2001 From: Jared Perreault Date: Thu, 10 Aug 2023 17:47:56 -0400 Subject: [PATCH 2/4] cleaner solution --- lib/idx/util.ts | 22 +++++++++++----------- test/spec/idx/util.ts | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 11 deletions(-) diff --git a/lib/idx/util.ts b/lib/idx/util.ts index 9c09b8081..dfce6ccd1 100644 --- a/lib/idx/util.ts +++ b/lib/idx/util.ts @@ -67,19 +67,19 @@ export function getMessagesFromResponse(idxResponse: IdxResponse, options: RunOp messages = [...messages, ...fieldMessages] as never; } } + } - // API may return identical error on same field, filter by i18n key - const seen = {}; - messages = messages.reduce((filtered, message) => { - const key = message.i18n?.key; - if (key && seen[key]) { - return filtered; - } - seen[key] = message; - filtered = [...filtered, message] as never; + // API may return identical error on same field, filter by i18n key + const seen = {}; + messages = messages.reduce((filtered, message) => { + const key = message.i18n?.key; + if (key && seen[key] && message.message === seen[key].message) { return filtered; - }, []); - } + } + seen[key] = message; + filtered = [...filtered, message] as never; + return filtered; + }, []); return messages; } diff --git a/test/spec/idx/util.ts b/test/spec/idx/util.ts index 2b4fd0305..89e91f4cd 100644 --- a/test/spec/idx/util.ts +++ b/test/spec/idx/util.ts @@ -120,6 +120,46 @@ describe('idx/util', () => { }]); }); + it('returns messages at the top level', () => { + const expected = [ + { + class: 'ERROR', + i18n: { + key: 'security.access_denied' + }, + message: 'You do not have permission to perform the requested action.' + }, + { + class: 'ERROR', + i18n: { + key: 'security.access_denied' + }, + message: 'some random text' + } + ]; + + const rawIdxState = RawIdxResponseFactory.build({ + messages: IdxMessagesFactory.build({ + value: [ + IdxErrorAccessDeniedFactory.build(), + IdxErrorAccessDeniedFactory.build(), + IdxErrorAccessDeniedFactory.build(), + IdxErrorAccessDeniedFactory.build({ + message: 'some random text' + }) + ] + }) + }); + const idxResponse = IdxResponseFactory.build({ + rawIdxState + }); + const res = getMessagesFromResponse(idxResponse, {}); + expect(res).toEqual(expected); + + const genericRemRes = getMessagesFromResponse(idxResponse, { useGenericRemediator: true }); + expect(genericRemRes).toEqual(expected); + }); + describe('form level messages', () => { let idxResponse; beforeEach(() => { From 9a99262049c2ab16f346bbba5d652bcbde999161 Mon Sep 17 00:00:00 2001 From: Jared Perreault Date: Thu, 10 Aug 2023 18:07:01 -0400 Subject: [PATCH 3/4] changelog --- CHANGELOG.md | 6 ++++++ README.md | 6 +++--- package.json | 2 +- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6a9b1d8cb..81d77f0a3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## 7.4.1 + +### Bug Fix + +- [#1446](https://github.com/okta/okta-auth-js/pull/1446) Fix: prevents incorrectly removing idx message duplicates + ## 7.4.0 ### Features diff --git a/README.md b/README.md index 647be2f7d..cad74e312 100644 --- a/README.md +++ b/README.md @@ -96,7 +96,7 @@ require('@okta/okta-auth-js/polyfill'); The built polyfill bundle is also available on our global CDN. Include the following script in your HTML file to load before any other scripts: ```html - + ``` > :warning: The version shown in this sample may be older than the current version. We recommend using the highest version available @@ -171,7 +171,7 @@ If you are using the JS on a web page from the browser, you can copy the `node_m The built library bundle is also available on our global CDN. Include the following script in your HTML file to load before your application script: ```html - + ``` > :warning: The version shown in this sample may be older than the current version. We recommend using the highest version available @@ -812,7 +812,7 @@ const config = { }; const authClient = new OktaAuth(config); -const tokens = await authClient.token.getWithoutPrompt(); +const { tokens } = await authClient.token.getWithoutPrompt(); authClient.tokenManager.setTokens(tokens); // storageProvider.setItem ``` diff --git a/package.json b/package.json index ebcf2a9d4..f4396dc10 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "private": true, "name": "@okta/okta-auth-js", "description": "The Okta Auth SDK", - "version": "7.4.0", + "version": "7.4.1", "homepage": "https://github.com/okta/okta-auth-js", "license": "Apache-2.0", "main": "build/cjs/exports/default.js", From 8ac9c6fcfcab1b86e8c63edbbaf16e395d619ba5 Mon Sep 17 00:00:00 2001 From: Jared Perreault Date: Thu, 10 Aug 2023 18:30:41 -0400 Subject: [PATCH 4/4] fixes test --- test/spec/idx/util.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/spec/idx/util.ts b/test/spec/idx/util.ts index 89e91f4cd..24c63eb17 100644 --- a/test/spec/idx/util.ts +++ b/test/spec/idx/util.ts @@ -120,7 +120,7 @@ describe('idx/util', () => { }]); }); - it('returns messages at the top level', () => { + it('removes duplicate messages', () => { const expected = [ { class: 'ERROR',