@squiz/resource-browser 2.2.1-rc.0 → 2.2.2-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc +39 -0
- package/CHANGELOG.md +4 -0
- package/build.js +15 -15
- package/lib/Plugin/Plugin.js +2 -2
- package/lib/ResourceBrowserContext/AuthProvider.js +1 -1
- package/package.json +13 -7
- package/src/Hooks/useAuth.spec.tsx +3 -3
- package/src/Plugin/Plugin.tsx +5 -1
- package/src/ResourceBrowserContext/AuthProvider.spec.tsx +5 -5
- package/src/ResourceBrowserContext/AuthProvider.tsx +2 -6
- package/src/index.tsx +0 -1
- package/src/types.ts +1 -1
- package/src/utils/authUtils.spec.ts +2 -2
- package/tsconfig.storybook.json +4 -0
- package/tsconfig.test.json +12 -0
package/.eslintrc
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
{
|
2
|
+
"extends": ["@squiz"],
|
3
|
+
"plugins": ["import", "prettier"],
|
4
|
+
"rules": {
|
5
|
+
"prettier/prettier": "error",
|
6
|
+
},
|
7
|
+
"settings": {
|
8
|
+
"import/parsers": {
|
9
|
+
"@typescript-eslint/parser": [".ts", ".tsx"],
|
10
|
+
},
|
11
|
+
"import/resolver": {
|
12
|
+
"typescript": {
|
13
|
+
"alwaysTryTypes": true,
|
14
|
+
},
|
15
|
+
},
|
16
|
+
},
|
17
|
+
"ignorePatterns": ["**/lib/"],
|
18
|
+
"overrides": [
|
19
|
+
{
|
20
|
+
"files": ["*.spec.ts", "*.spec.tsx"],
|
21
|
+
"rules": {
|
22
|
+
"no-var": 0,
|
23
|
+
"import/no-extraneous-dependencies": 0,
|
24
|
+
},
|
25
|
+
},
|
26
|
+
{
|
27
|
+
"files": ["*.config.ts", "*.config.js", "build.js"],
|
28
|
+
"rules": {
|
29
|
+
"import/no-extraneous-dependencies": 0,
|
30
|
+
},
|
31
|
+
},
|
32
|
+
{
|
33
|
+
"files": ["*.stories.ts", "*.stories.tsx"],
|
34
|
+
"rules": {
|
35
|
+
"import/no-extraneous-dependencies": 0,
|
36
|
+
},
|
37
|
+
},
|
38
|
+
],
|
39
|
+
}
|
package/CHANGELOG.md
CHANGED
@@ -3,6 +3,10 @@
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
5
5
|
|
6
|
+
## [2.2.2-rc.0](https://gitlab.squiz.net/dxp/dxp-shared-ui/resource-browser/compare/@squiz/resource-browser@2.2.1-rc.0...@squiz/resource-browser@2.2.2-rc.0) (2024-06-10)
|
7
|
+
|
8
|
+
**Note:** Version bump only for package @squiz/resource-browser
|
9
|
+
|
6
10
|
## [2.2.1-rc.0](https://gitlab.squiz.net/dxp/dxp-shared-ui/resource-browser/compare/@squiz/resource-browser@2.2.0-rc.0...@squiz/resource-browser@2.2.1-rc.0) (2024-06-07)
|
7
11
|
|
8
12
|
**Note:** Version bump only for package @squiz/resource-browser
|
package/build.js
CHANGED
@@ -4,18 +4,18 @@ const postcss = require('postcss');
|
|
4
4
|
const postcssConfig = require('./postcss.config').plugins;
|
5
5
|
|
6
6
|
esbuild
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
7
|
+
.build({
|
8
|
+
entryPoints: ['src/index.scss'],
|
9
|
+
bundle: true,
|
10
|
+
outdir: 'lib',
|
11
|
+
plugins: [
|
12
|
+
sassPlugin({
|
13
|
+
type: 'css',
|
14
|
+
transform: async (source) => {
|
15
|
+
const { css } = postcss(postcssConfig).process(source);
|
16
|
+
return css;
|
17
|
+
},
|
18
|
+
}),
|
19
|
+
],
|
20
|
+
})
|
21
|
+
.catch(() => process.exit(1));
|
package/lib/Plugin/Plugin.js
CHANGED
@@ -9,8 +9,8 @@ const ResourceBrowserInput_1 = require("../ResourceBrowserInput/ResourceBrowserI
|
|
9
9
|
const AuthProvider_1 = require("../ResourceBrowserContext/AuthProvider");
|
10
10
|
const PluginRender = ({ render, ...props }) => {
|
11
11
|
if (render) {
|
12
|
-
return react_1.default.createElement(AuthProvider_1.AuthProvider, { authConfig: props.source },
|
13
|
-
react_1.default.createElement(ResourceBrowserInput_1.ResourceBrowserInput, { ...props }));
|
12
|
+
return (react_1.default.createElement(AuthProvider_1.AuthProvider, { authConfig: props.source },
|
13
|
+
react_1.default.createElement(ResourceBrowserInput_1.ResourceBrowserInput, { ...props })));
|
14
14
|
}
|
15
15
|
else {
|
16
16
|
return react_1.default.createElement(react_1.default.Fragment, null);
|
@@ -41,6 +41,6 @@ const AuthProvider = ({ children, authConfig }) => {
|
|
41
41
|
if (!authConfiguration?.configuration) {
|
42
42
|
return react_1.default.createElement(react_1.default.Fragment, null, children);
|
43
43
|
}
|
44
|
-
return
|
44
|
+
return react_1.default.createElement(exports.AuthContext.Provider, { value: auth }, children);
|
45
45
|
};
|
46
46
|
exports.AuthProvider = AuthProvider;
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@squiz/resource-browser",
|
3
|
-
"version": "2.2.
|
3
|
+
"version": "2.2.2-rc.0",
|
4
4
|
"main": "lib/index.js",
|
5
5
|
"types": "lib/index.d.ts",
|
6
6
|
"private": false,
|
@@ -12,26 +12,31 @@
|
|
12
12
|
"compile:code": "tsc",
|
13
13
|
"compile:styles": "node build.js",
|
14
14
|
"storybook": "storybook dev -p 6006",
|
15
|
-
"test": "
|
15
|
+
"test": "npm run test:unit && npm run test:eslint",
|
16
16
|
"test:unit": "jest",
|
17
|
+
"test:eslint": "eslint .",
|
17
18
|
"test:watch": "jest --watch"
|
18
19
|
},
|
19
20
|
"dependencies": {
|
20
21
|
"@emotion/styled": "^11.11.5",
|
21
22
|
"@mui/icons-material": "5.11.16",
|
22
23
|
"@react-aria/interactions": "^3.21.1",
|
23
|
-
"@react-types/
|
24
|
+
"@react-types/overlays": "^3.8.7",
|
25
|
+
"@react-types/shared": "^3.23.1",
|
24
26
|
"@squiz/dx-json-schema-lib": "^1.67.0",
|
25
27
|
"@squiz/generic-browser-lib": "^1.66.0",
|
26
|
-
"@squiz/resource-browser-ui-lib": "^0.8.
|
28
|
+
"@squiz/resource-browser-ui-lib": "^0.8.3-rc.0",
|
27
29
|
"clsx": "^2.1.0",
|
28
30
|
"expiry-map": "^2.0.0",
|
29
31
|
"p-memoize": "^4.0.4",
|
32
|
+
"react": "^16.14.0 || ^17 || ^18",
|
30
33
|
"react-aria": "3.23.1",
|
34
|
+
"react-dom": "^16.14.0 || ^17 || ^18",
|
31
35
|
"react-responsive": "9.0.2",
|
32
36
|
"react-stately": "3.21.0"
|
33
37
|
},
|
34
38
|
"devDependencies": {
|
39
|
+
"@squiz/eslint-config": "^1.7.0",
|
35
40
|
"@storybook/addon-essentials": "^7.5.3",
|
36
41
|
"@storybook/addon-interactions": "^7.5.3",
|
37
42
|
"@storybook/addon-links": "^7.5.3",
|
@@ -46,9 +51,12 @@
|
|
46
51
|
"@types/postcss-js": "4.0.0",
|
47
52
|
"@types/react": "^18.2.45",
|
48
53
|
"@types/react-dom": "^18.2.18",
|
54
|
+
"@typescript-eslint/parser": "^7.12.0",
|
49
55
|
"autoprefixer": "10.4.14",
|
50
56
|
"esbuild": "^0.19.3",
|
51
57
|
"esbuild-sass-plugin": "^2.8.0",
|
58
|
+
"eslint-import-resolver-typescript": "^3.6.1",
|
59
|
+
"eslint-plugin-import": "^2.29.1",
|
52
60
|
"jest": "29.4.1",
|
53
61
|
"jest-environment-jsdom": "29.4.1",
|
54
62
|
"postcss": "8.4.31",
|
@@ -56,8 +64,6 @@
|
|
56
64
|
"postcss-nested": "6.0.1",
|
57
65
|
"postcss-prefix-selector": "1.16.0",
|
58
66
|
"prop-types": "15.8.1",
|
59
|
-
"react": "^18.0.0",
|
60
|
-
"react-dom": "^18.0.0",
|
61
67
|
"storybook": "^7.5.3",
|
62
68
|
"tailwindcss": "3.3.1",
|
63
69
|
"ts-jest": "29.0.5",
|
@@ -81,5 +87,5 @@
|
|
81
87
|
"volta": {
|
82
88
|
"node": "18.18.0"
|
83
89
|
},
|
84
|
-
"gitHead": "
|
90
|
+
"gitHead": "5d66e140b42ee6c9794ca079b1049289ca4f74f8"
|
85
91
|
}
|
@@ -14,7 +14,7 @@ describe('useAuth', () => {
|
|
14
14
|
authUrl: 'https://auth.example.com',
|
15
15
|
clientId: 'example-client-id',
|
16
16
|
redirectUrl: 'https://example.com/callback',
|
17
|
-
scope: 'offline_access'
|
17
|
+
scope: 'offline_access',
|
18
18
|
};
|
19
19
|
|
20
20
|
beforeEach(() => {
|
@@ -55,7 +55,7 @@ describe('useAuth', () => {
|
|
55
55
|
|
56
56
|
Object.defineProperty(popupMock, 'closed', {
|
57
57
|
get: jest.fn(() => false),
|
58
|
-
set: jest.fn()
|
58
|
+
set: jest.fn(),
|
59
59
|
});
|
60
60
|
|
61
61
|
const consoleSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
|
@@ -93,7 +93,7 @@ describe('useAuth', () => {
|
|
93
93
|
expect(window.open).toHaveBeenCalledWith(
|
94
94
|
`${authConfig.authUrl}?client_id=${authConfig.clientId}&scope=offline_access&redirect_uri=${encodeURIComponent(authConfig.redirectUrl)}&response_type=code&state=state`,
|
95
95
|
'Login',
|
96
|
-
'width=600,height=600'
|
96
|
+
'width=600,height=600',
|
97
97
|
);
|
98
98
|
|
99
99
|
act(() => {
|
package/src/Plugin/Plugin.tsx
CHANGED
@@ -14,7 +14,11 @@ export type PluginRenderType = ResourceBrowserInputProps & {
|
|
14
14
|
};
|
15
15
|
export const PluginRender = ({ render, ...props }: PluginRenderType) => {
|
16
16
|
if (render) {
|
17
|
-
return
|
17
|
+
return (
|
18
|
+
<AuthProvider authConfig={props.source}>
|
19
|
+
<ResourceBrowserInput {...props} />
|
20
|
+
</AuthProvider>
|
21
|
+
);
|
18
22
|
} else {
|
19
23
|
return <></>;
|
20
24
|
}
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import React from 'react';
|
2
2
|
import { render, screen, fireEvent } from '@testing-library/react';
|
3
3
|
import { AuthProvider, useAuthContext } from './AuthProvider';
|
4
|
-
import {AuthenticationConfiguration, ResourceBrowserSourceWithConfig} from '../types';
|
4
|
+
import { AuthenticationConfiguration, ResourceBrowserSourceWithConfig } from '../types';
|
5
5
|
import { useAuth } from '../Hooks/useAuth';
|
6
6
|
|
7
7
|
jest.mock('../Hooks/useAuth');
|
@@ -13,13 +13,13 @@ describe('AuthContext', () => {
|
|
13
13
|
authUrl: 'https://auth.example.com',
|
14
14
|
clientId: 'example-client-id',
|
15
15
|
redirectUrl: 'https://example.com/callback',
|
16
|
-
scope: 'offline'
|
16
|
+
scope: 'offline',
|
17
17
|
};
|
18
18
|
|
19
|
-
const sourceConfig: ResourceBrowserSourceWithConfig
|
19
|
+
const sourceConfig: ResourceBrowserSourceWithConfig = {
|
20
20
|
id: '1',
|
21
21
|
type: 'dam',
|
22
|
-
configuration: authConfig
|
22
|
+
configuration: authConfig,
|
23
23
|
};
|
24
24
|
|
25
25
|
const authState = {
|
@@ -49,7 +49,7 @@ describe('AuthContext', () => {
|
|
49
49
|
render(
|
50
50
|
<AuthProvider authConfig={sourceConfig}>
|
51
51
|
<TestComponent />
|
52
|
-
</AuthProvider
|
52
|
+
</AuthProvider>,
|
53
53
|
);
|
54
54
|
|
55
55
|
expect(screen.getByText(/Token: testAuthToken/)).toBeInTheDocument();
|
@@ -24,7 +24,7 @@ interface AuthProviderProps {
|
|
24
24
|
authConfig?: ResourceBrowserSource | null;
|
25
25
|
}
|
26
26
|
|
27
|
-
export const AuthProvider = (
|
27
|
+
export const AuthProvider = ({ children, authConfig }: AuthProviderProps) => {
|
28
28
|
const authConfiguration = authConfig as ResourceBrowserSourceWithConfig;
|
29
29
|
const auth = useAuth(authConfiguration?.configuration);
|
30
30
|
|
@@ -32,9 +32,5 @@ export const AuthProvider = ( {children, authConfig}: AuthProviderProps ) => {
|
|
32
32
|
return <>{children}</>;
|
33
33
|
}
|
34
34
|
|
35
|
-
return
|
36
|
-
<AuthContext.Provider value={auth}>
|
37
|
-
{children}
|
38
|
-
</AuthContext.Provider>
|
39
|
-
);
|
35
|
+
return <AuthContext.Provider value={auth}>{children}</AuthContext.Provider>;
|
40
36
|
};
|
package/src/index.tsx
CHANGED
package/src/types.ts
CHANGED
@@ -7,7 +7,7 @@ global.fetch = jest.fn();
|
|
7
7
|
describe('auth-utils', () => {
|
8
8
|
beforeEach(() => {
|
9
9
|
// Clear all cookies before each test
|
10
|
-
document.cookie.split(';').forEach(cookie => {
|
10
|
+
document.cookie.split(';').forEach((cookie) => {
|
11
11
|
const eqPos = cookie.indexOf('=');
|
12
12
|
const name = eqPos > -1 ? cookie.substr(0, eqPos) : cookie;
|
13
13
|
document.cookie = `${name}=;expires=Thu, 01 Jan 1970 00:00:00 GMT;path=/`;
|
@@ -47,7 +47,7 @@ describe('auth-utils', () => {
|
|
47
47
|
authUrl: 'https://auth.example.com',
|
48
48
|
clientId: 'example-client-id',
|
49
49
|
redirectUrl: 'https://example.com/callback',
|
50
|
-
scope: 'offline_access'
|
50
|
+
scope: 'offline_access',
|
51
51
|
};
|
52
52
|
|
53
53
|
it('should throw an error if authConfig is not provided', async () => {
|