From 06412406bbfb67d730371fccc1859ba30c7737a4 Mon Sep 17 00:00:00 2001 From: Zak Burke Date: Thu, 12 Oct 2023 11:57:36 -0400 Subject: [PATCH 1/4] bump minor to 10.1 for new development (#1350) --- CHANGELOG.md | 5 ++++- package.json | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0fac75302..c4ea299f8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,9 @@ # Change history for stripes-core -## 10.0.0 IN PROGRESS +## 10.1.0 IN PROGRESS + +## [10.0.0](https://github.com/folio-org/stripes-core/tree/v10.0.0) (2023-10-11) +[Full Changelog](https://github.com/folio-org/stripes-core/compare/v9.0.0...v10.0.0) * Close app-context menu when its wrapper is undefined, which it will be when switching among apps. Fixes STCOR-680. * Move `miragejs` to dev-deps; remove `clean` script and `rimraf`. Refs STCOR-668, STCOR-681. diff --git a/package.json b/package.json index fc02c6765..1c171d274 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@folio/stripes-core", - "version": "10.0.0", + "version": "10.1.0", "description": "The starting point for Stripes applications", "license": "Apache-2.0", "repository": "folio-org/stripes-core", From e3d47125caf62f26f1fd5e24d400eb606bbb3214 Mon Sep 17 00:00:00 2001 From: Mariia Aloshyna <55138456+mariia-aloshyna@users.noreply.github.com> Date: Fri, 13 Oct 2023 13:55:11 +0300 Subject: [PATCH 2/4] STCOR-747: Provide optional tenant argument to `useOkapiKy` hook (#1348) --- CHANGELOG.md | 2 + src/useOkapiKy.js | 6 +-- src/useOkapiKy.test.js | 86 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 91 insertions(+), 3 deletions(-) create mode 100644 src/useOkapiKy.test.js diff --git a/CHANGELOG.md b/CHANGELOG.md index c4ea299f8..99d023b3a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## 10.1.0 IN PROGRESS +* Provide optional tenant argument to `useOkapiKy` hook. Refs STCOR-747. + ## [10.0.0](https://github.com/folio-org/stripes-core/tree/v10.0.0) (2023-10-11) [Full Changelog](https://github.com/folio-org/stripes-core/compare/v9.0.0...v10.0.0) diff --git a/src/useOkapiKy.js b/src/useOkapiKy.js index c0bcda1c8..669ba7d6f 100644 --- a/src/useOkapiKy.js +++ b/src/useOkapiKy.js @@ -1,8 +1,8 @@ import ky from 'ky'; import { useStripes } from './StripesContext'; -export default () => { - const { locale = 'en', timeout = 30000, tenant, token, url } = useStripes().okapi; +export default (tenant) => { + const { locale = 'en', timeout = 30000, tenant: currentTenant, token, url } = useStripes().okapi; return ky.create({ prefixUrl: url, @@ -10,7 +10,7 @@ export default () => { beforeRequest: [ request => { request.headers.set('Accept-Language', locale); - request.headers.set('X-Okapi-Tenant', tenant); + request.headers.set('X-Okapi-Tenant', tenant ?? currentTenant); request.headers.set('X-Okapi-Token', token); } ] diff --git a/src/useOkapiKy.test.js b/src/useOkapiKy.test.js new file mode 100644 index 000000000..41fbc71a2 --- /dev/null +++ b/src/useOkapiKy.test.js @@ -0,0 +1,86 @@ +import ky from 'ky'; +import { renderHook, waitFor } from '@folio/jest-config-stripes/testing-library/react'; + +import { useStripes } from './StripesContext'; +import useOkapiKy from './useOkapiKy'; + +jest.mock('./StripesContext'); +jest.mock('ky', () => ({ + create: ({ ...av }) => av, +})); + +describe('useOkapiKy', () => { + it('pulls values from stripes object', async () => { + const okapi = { + locale: 'klingon', + tenant: 'tenant', + timeout: 271828, + token: 'token', + url: 'https://whatever.com' + }; + + const mockUseStripes = useStripes; + mockUseStripes.mockReturnValue({ okapi }); + + const r = { + headers: { + set: jest.fn(), + } + }; + + const { result } = renderHook(() => useOkapiKy()); + result.current.hooks.beforeRequest[0](r); + + expect(result.current.prefixUrl).toBe(okapi.url); + expect(result.current.timeout).toBe(okapi.timeout); + + expect(r.headers.set).toHaveBeenCalledWith('Accept-Language', okapi.locale); + expect(r.headers.set).toHaveBeenCalledWith('X-Okapi-Tenant', okapi.tenant); + expect(r.headers.set).toHaveBeenCalledWith('X-Okapi-Token', okapi.token); + }); + + it('provides default values if stripes lacks them', async () => { + const okapi = {}; + + const mockUseStripes = useStripes; + mockUseStripes.mockReturnValue({ okapi }); + + const r = { + headers: { + set: jest.fn(), + } + }; + + const { result } = renderHook(() => useOkapiKy()); + result.current.hooks.beforeRequest[0](r); + + expect(result.current.timeout).toBe(30000); + + expect(r.headers.set).toHaveBeenCalledWith('Accept-Language', 'en'); + }); + + it('overrides tenant', async () => { + const okapi = { + tenant: 'tenant', + timeout: 271828, + token: 'token', + url: 'https://whatever.com' + }; + + const mockUseStripes = useStripes; + mockUseStripes.mockReturnValue({ okapi }); + + const r = { + headers: { + set: jest.fn(), + } + }; + + const { result } = renderHook(() => useOkapiKy('monkey')); + result.current.hooks.beforeRequest[0](r); + + expect(r.headers.set).toHaveBeenCalledWith('X-Okapi-Tenant', 'monkey'); + }); +}); + + From 38729dbf061458f3cc5b530dc14e254dc5ed8623 Mon Sep 17 00:00:00 2001 From: Oleksandr Hladchenko <85172747+OleksandrHladchenko1@users.noreply.github.com> Date: Wed, 18 Oct 2023 14:10:45 +0300 Subject: [PATCH 3/4] STCOR-749: Allow to import validateUser function from @folio/stripes/core (#1351) --- CHANGELOG.md | 1 + index.js | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 99d023b3a..757b50590 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## 10.1.0 IN PROGRESS * Provide optional tenant argument to `useOkapiKy` hook. Refs STCOR-747. +* Avoid private path when import `validateUser` function. Refs STCOR-749. ## [10.0.0](https://github.com/folio-org/stripes-core/tree/v10.0.0) (2023-10-11) [Full Changelog](https://github.com/folio-org/stripes-core/compare/v9.0.0...v10.0.0) diff --git a/index.js b/index.js index ed599f10d..f9598cb04 100644 --- a/index.js +++ b/index.js @@ -9,7 +9,7 @@ export { useModules } from './src/ModulesContext'; export { withModule, withModules } from './src/components/Modules'; export { default as stripesConnect } from './src/stripesConnect'; export { default as Pluggable } from './src/Pluggable'; -export { updateUser, updateTenant } from './src/loginServices'; +export { updateUser, updateTenant, validateUser } from './src/loginServices'; export { default as coreEvents } from './src/events'; export { default as useOkapiKy } from './src/useOkapiKy'; export { default as withOkapiKy } from './src/withOkapiKy'; From 8d7ac446b13a6c79cc9c79174fc7f7e12e2da134 Mon Sep 17 00:00:00 2001 From: Mariia Aloshyna <55138456+mariia-aloshyna@users.noreply.github.com> Date: Wed, 18 Oct 2023 19:35:56 +0300 Subject: [PATCH 4/4] STCOR-747: Convert optional arg to object for useOkapiKy hook (#1352) --- src/useOkapiKy.js | 2 +- src/useOkapiKy.test.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/useOkapiKy.js b/src/useOkapiKy.js index 669ba7d6f..22fdef09e 100644 --- a/src/useOkapiKy.js +++ b/src/useOkapiKy.js @@ -1,7 +1,7 @@ import ky from 'ky'; import { useStripes } from './StripesContext'; -export default (tenant) => { +export default ({ tenant } = {}) => { const { locale = 'en', timeout = 30000, tenant: currentTenant, token, url } = useStripes().okapi; return ky.create({ diff --git a/src/useOkapiKy.test.js b/src/useOkapiKy.test.js index 41fbc71a2..1a58e3208 100644 --- a/src/useOkapiKy.test.js +++ b/src/useOkapiKy.test.js @@ -76,7 +76,7 @@ describe('useOkapiKy', () => { } }; - const { result } = renderHook(() => useOkapiKy('monkey')); + const { result } = renderHook(() => useOkapiKy({ tenant: 'monkey' })); result.current.hooks.beforeRequest[0](r); expect(r.headers.set).toHaveBeenCalledWith('X-Okapi-Tenant', 'monkey');