diff --git a/.github/actions/setup-node/action.yml b/.github/actions/setup-node/action.yml new file mode 100644 index 0000000000..89bd8521e1 --- /dev/null +++ b/.github/actions/setup-node/action.yml @@ -0,0 +1,32 @@ +name: 'Setup nodejs' +description: 'Setup nodejs' +author: 'Talend' +secrets: + NPM_TOKEN: + description: 'The NPM token to use' +runs: + using: 'composite' + steps: + - name: Set up Node.js + uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d #v3.8.1 + with: + node-version: '20' + registry-url: 'https://registry.npmjs.org/' + scope: '@talend' + + - name: Install yarn + shell: bash + run: npm i -g yarn + + - name: Get yarn cache directory path + id: yarn-cache-dir-path + shell: bash + run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT + + - uses: actions/cache@704facf57e6136b1bc63b828d79edcd491f0ee84 #v3.3.2 + id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`) + with: + path: ${{ steps.yarn-cache-dir-path.outputs.dir }} + key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} + restore-keys: | + ${{ runner.os }}-yarn- diff --git a/.github/workflows/changeset.yml b/.github/workflows/changeset.yml index 5a55cab4a2..91147291ee 100644 --- a/.github/workflows/changeset.yml +++ b/.github/workflows/changeset.yml @@ -29,14 +29,9 @@ jobs: fetch-depth: 0 persist-credentials: false - - name: Setup Node.js - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d # v3.8.1 - with: - node-version: 18 - registry-url: "https://registry.npmjs.org/" - scope: "@talend" - cache: "yarn" - + - name: Use Node.js + uses: ./.github/actions/setup-node + - name: Install Dependencies run: yarn --frozen-lockfile diff --git a/.github/workflows/dependencies.yml b/.github/workflows/dependencies.yml index 83ec2f6039..be1104fe28 100644 --- a/.github/workflows/dependencies.yml +++ b/.github/workflows/dependencies.yml @@ -22,12 +22,7 @@ jobs: uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac #v4.0.0 - name: Use Node.js - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d # v3.8.1 - with: - node-version: 18 - registry-url: "https://registry.npmjs.org/" - scope: "@talend" - cache: "yarn" + uses: ./.github/actions/setup-node - name: Upgrade dependencies run: | diff --git a/.github/workflows/design-system-component-testing.yml b/.github/workflows/design-system-component-testing.yml index 6eb5a721fe..f8c47c05f7 100644 --- a/.github/workflows/design-system-component-testing.yml +++ b/.github/workflows/design-system-component-testing.yml @@ -24,12 +24,8 @@ jobs: - name: Checkout repository uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac #v4.0.0 - - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d # v3.8.1 - with: - node-version: 18 - registry-url: "https://registry.npmjs.org/" - scope: "@talend" - cache: "yarn" + - name: Use Node.js + uses: ./.github/actions/setup-node - uses: actions/cache@704facf57e6136b1bc63b828d79edcd491f0ee84 #v3.3.2 with: diff --git a/.github/workflows/icons.yml b/.github/workflows/icons.yml index c6104b3f40..04d6a4b7b2 100644 --- a/.github/workflows/icons.yml +++ b/.github/workflows/icons.yml @@ -25,12 +25,8 @@ jobs: persist-credentials: false - name: Use Node.js - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d # v3.8.1 - with: - node-version: 18 - check-latest: true - cache: "yarn" - + uses: ./.github/actions/setup-node + - name: Download icons run: npx @talend/figma-icons-downloader env: diff --git a/.github/workflows/pr-lint.yml b/.github/workflows/pr-lint.yml index f172765eef..9dcc3c90db 100644 --- a/.github/workflows/pr-lint.yml +++ b/.github/workflows/pr-lint.yml @@ -28,14 +28,8 @@ jobs: fetch-depth: 0 # otherwise, you will failed to push refs to dest repo - name: Use Node.js - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d # v3.8.1 - with: - node-version: 18 - check-latest: true - registry-url: "https://registry.npmjs.org/" - scope: "@talend" - cache: "yarn" - + uses: ./.github/actions/setup-node + - name: Install run: yarn install --frozen-lockfile --ignore-scripts diff --git a/.github/workflows/pr-playground.yml b/.github/workflows/pr-playground.yml index 0798d9371d..374f049c24 100644 --- a/.github/workflows/pr-playground.yml +++ b/.github/workflows/pr-playground.yml @@ -27,12 +27,8 @@ jobs: uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac #v4.0.0 - name: Use Node.js - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d # v3.8.1 - with: - node-version: 18 - registry-url: "https://registry.npmjs.org/" - scope: "@talend" - cache: "yarn" + uses: ./.github/actions/setup-node + - name: Install and build playground id: build diff --git a/.github/workflows/pr-test.yml b/.github/workflows/pr-test.yml index b271fedefb..f4a95de179 100644 --- a/.github/workflows/pr-test.yml +++ b/.github/workflows/pr-test.yml @@ -24,13 +24,7 @@ jobs: uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac #v4.0.0 - name: Use Node.js - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d # v3.8.1 - with: - node-version: 18 - check-latest: true - registry-url: "https://registry.npmjs.org/" - scope: "@talend" - cache: "yarn" + uses: ./.github/actions/setup-node - name: Install run: yarn install --frozen-lockfile diff --git a/.github/workflows/surge-cleanup.yml b/.github/workflows/surge-cleanup.yml index fc3a610663..4bc6b29e9d 100644 --- a/.github/workflows/surge-cleanup.yml +++ b/.github/workflows/surge-cleanup.yml @@ -13,10 +13,8 @@ jobs: environment: pull_request_unsafe steps: - - name: Use Node.js - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d # v3.8.1 - with: - node-version: 18 - - - name: Push to surge - run: npx surge teardown ${{ github.event.pull_request.number }}.talend.surge.sh --token ${{ secrets.SURGE_TOKEN }} + - name: Use Node.js + uses: ./.github/actions/setup-node + + - name: Push to surge + run: npx surge teardown ${{ github.event.pull_request.number }}.talend.surge.sh --token ${{ secrets.SURGE_TOKEN }} diff --git a/.github/workflows/tests-cron.yml b/.github/workflows/tests-cron.yml index 20362c668b..1641011e9d 100644 --- a/.github/workflows/tests-cron.yml +++ b/.github/workflows/tests-cron.yml @@ -20,12 +20,7 @@ jobs: uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac #v4.0.0 - name: Use Node.js - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d # v3.8.1 - with: - node-version: 18 - registry-url: "https://registry.npmjs.org/" - scope: "@talend" - cache: "yarn" + uses: ./.github/actions/setup-node - name: Install and tests run: | diff --git a/.github/workflows/visual-testing.yml b/.github/workflows/visual-testing.yml index 95d824a139..7d2a26b583 100644 --- a/.github/workflows/visual-testing.yml +++ b/.github/workflows/visual-testing.yml @@ -32,10 +32,8 @@ jobs: with: fetch-depth: 0 - - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d # v3.8.1 - with: - node-version: 18 - cache: "yarn" + - name: Use Node.js + uses: ./.github/actions/setup-node - name: Install dependencies run: yarn --frozen-lock diff --git a/.github/workflows/yarn-deduplicate.yml b/.github/workflows/yarn-deduplicate.yml index 601eab816f..d9dfb8526d 100644 --- a/.github/workflows/yarn-deduplicate.yml +++ b/.github/workflows/yarn-deduplicate.yml @@ -29,12 +29,7 @@ jobs: fetch-depth: 0 # otherwise, you will failed to push refs to dest repo - name: Use Node.js - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d # v3.8.1 - with: - node-version: 18 - registry-url: "https://registry.npmjs.org/" - scope: "@talend" - cache: "yarn" + uses: ./.github/actions/setup-node - name: yarn-deduplicate id: deduplicate diff --git a/fork/bootstrap-sass/CHANGELOG.md b/fork/bootstrap-sass/CHANGELOG.md index f6634c90ed..768f54ad9e 100644 --- a/fork/bootstrap-sass/CHANGELOG.md +++ b/fork/bootstrap-sass/CHANGELOG.md @@ -1,5 +1,16 @@ # Changelog +## 3.5.0 + +### Minor Changes + +- 9d137cb98: \* 275e7da72 2023-08-03 feat(TDOPS-4875): use elevation tokens (#4821) + - bfc02c4fb 2023-07-24 feat(ARCH-720): use design-tokens for colors (#4779) + - c18aabb97 2023-01-12 feat(ARCH-662/scripts-core): move to ESM and remove presets (#4531) + - aa5223cf3 2021-12-20 chore(ARCH-404/CI): decrease time needed (#3564) + - 4842bffc2 2021-11-02 chore: wake up the playground to test UMDs (#3428) + - 667cd0a50 2021-10-05 chore: upgrade dependencies (#3459) + ## 3.4.8 ### Patch Changes diff --git a/fork/bootstrap-sass/package.json b/fork/bootstrap-sass/package.json index 664cff8d3c..bf65b31c98 100644 --- a/fork/bootstrap-sass/package.json +++ b/fork/bootstrap-sass/package.json @@ -1,6 +1,6 @@ { "name": "@talend/bootstrap-sass", - "version": "3.4.8", + "version": "3.5.0", "description": "bootstrap-sass is a Sass-powered version of Bootstrap 3, ready to drop right into your Sass powered applications.", "main": "assets/javascripts/bootstrap.js", "style": "assets/stylesheets/_bootstrap.scss", diff --git a/fork/dynamic-cdn-webpack-plugin/src/find.js b/fork/dynamic-cdn-webpack-plugin/src/find.js index cc51eeb70c..c2a93405b0 100644 --- a/fork/dynamic-cdn-webpack-plugin/src/find.js +++ b/fork/dynamic-cdn-webpack-plugin/src/find.js @@ -34,14 +34,12 @@ function findPackagesFromScopeFolder(scope, name, scopeFolderPath) { // just add the path to the found list return accu.concat(subFolderPath); } - // TODO CHECKJM Not compatible with pnpm + // TODO NOT COMPATIBLE WITH PNPM // the scope or package name is not the one we look for // if there is a nested node modules folder, we dive into it for the search const nestedNodeModulesPath = path.join(subFolderPath, 'node_modules'); if (fs.existsSync(nestedNodeModulesPath)) { - return accu.concat( - findPackagesFromNonScopeFolder(scope, name, nestedNodeModulesPath, []), - ); + return accu.concat(findPackagesFromNonScopeFolder(scope, name, nestedNodeModulesPath, [])); } return accu; }, []); @@ -62,32 +60,22 @@ function findPackagesFromNonScopeFolder(scope, name, nonScopeFolderPath) { // for scope folders, we need a special treatment to avoid getting scoped packages when we don't want a scoped one. // ex: search for `classnames`, we don't want to find `@types/classnames` in the result return accu.concat( - findPackagesFromScopeFolder( - scope, - name, - path.join(nonScopeFolderPath, subFolder.name), - ), + findPackagesFromScopeFolder(scope, name, path.join(nonScopeFolderPath, subFolder.name)), ); } else if (!scope && subFolder.name === name) { // we want a NON scoped package, we are in a non scoped folder, and the names match return accu.concat(path.join(nonScopeFolderPath, subFolder.name)); } - const nestedNodeModulesPath = path.join( - nonScopeFolderPath, - subFolder.name, - 'node_modules', - ); + const nestedNodeModulesPath = path.join(nonScopeFolderPath, subFolder.name, 'node_modules'); if (fs.existsSync(nestedNodeModulesPath)) { - return accu.concat( - findPackagesFromNonScopeFolder(scope, name, nestedNodeModulesPath), - ); + return accu.concat(findPackagesFromNonScopeFolder(scope, name, nestedNodeModulesPath)); } return accu; }, []); } function findPackages(scope, name, buff = []) { - console.log('findPackages', scope, name, buff) + console.log('findPackages', scope, name, buff); // https://nodejs.org/dist/latest-v14.x/docs/api/modules.html#modules_require_resolve_paths_request const roots = require.resolve.paths(name).filter(p => fs.existsSync(p)); if (roots === null) { diff --git a/packages/components/CHANGELOG.md b/packages/components/CHANGELOG.md index 120810182c..4b781da04c 100644 --- a/packages/components/CHANGELOG.md +++ b/packages/components/CHANGELOG.md @@ -1,5 +1,13 @@ # @talend/react-components +## 11.4.4 + +### Patch Changes + +- 1cb4b7b29: fix(TFD-16296): Add ellipsis on collapsible panel header +- Updated dependencies [9d137cb98] + - @talend/bootstrap-theme@8.2.0 + ## 11.4.3 ### Patch Changes diff --git a/packages/components/package.json b/packages/components/package.json index 35f1555e76..480f878828 100644 --- a/packages/components/package.json +++ b/packages/components/package.json @@ -35,7 +35,7 @@ "dependencies": { "@popperjs/core": "^2.11.8", "@talend/assets-api": "^1.2.2", - "@talend/bootstrap-theme": "^8.1.3", + "@talend/bootstrap-theme": "^8.2.0", "@talend/design-tokens": "^2.9.0", "@talend/react-a11y": "^1.1.0", "@talend/icons": "^6.60.1", @@ -70,12 +70,12 @@ }, "devDependencies": { "@storybook/addon-actions": "^7.4.1", - "@talend/bootstrap-theme": "^8.1.3", + "@talend/bootstrap-theme": "^8.2.0", "@talend/design-system": "^7.15.1", "@talend/locales-design-system": "^7.3.0", "@talend/locales-tui-components": "^9.5.0", "@talend/scripts-core": "^15.0.0", - "@talend/scripts-config-react-webpack": "^16.0.0", + "@talend/scripts-config-react-webpack": "^16.1.0", "@testing-library/jest-dom": "^5.17.0", "@testing-library/react": "^12.1.5", "@testing-library/user-event": "^13.5.0", @@ -110,5 +110,5 @@ "publishConfig": { "access": "public" }, - "version": "11.4.3" + "version": "11.4.4" } diff --git a/packages/components/src/CollapsiblePanel/CollapsiblePanel.module.scss b/packages/components/src/CollapsiblePanel/CollapsiblePanel.module.scss index 9d5d3bafbf..e6209d3b2d 100644 --- a/packages/components/src/CollapsiblePanel/CollapsiblePanel.module.scss +++ b/packages/components/src/CollapsiblePanel/CollapsiblePanel.module.scss @@ -173,6 +173,13 @@ $tc-collapsible-panel-padding-larger: $padding-larger !default; display: flex; align-items: center; justify-content: space-between; + min-width: 0; // trick to avoid conflict between flex and overflow + + > * { + white-space: nowrap; + overflow: hidden; + text-overflow: ellipsis; + } } } } diff --git a/packages/components/src/CollapsiblePanel/CollapsiblePanel.stories.js b/packages/components/src/CollapsiblePanel/CollapsiblePanel.stories.js index 5f82d51240..192752ac0d 100644 --- a/packages/components/src/CollapsiblePanel/CollapsiblePanel.stories.js +++ b/packages/components/src/CollapsiblePanel/CollapsiblePanel.stories.js @@ -172,6 +172,18 @@ export const Header = () => (

Collapsible Panel Headers

+ + Panel content + { + if (request.method === HTTP_METHODS.GET) { + // your custom logic here + } + + return response; +}); +``` + +You can add multiple interceptors. Each will be called in the order of registration and will receive the same request parameter, but response parameter will be the one returned by previous interceptor. If interceptor returns void, then it'll return received response. + +Once your interceptor is not needed anymore, you can unregister it with `removeHttpResponseInterceptor` function of `@talend/http` package. + +You can identify some requests in interceptor by using `context` property in fetch function config: + +```es6 +import { addHttpResponseInterceptor, http, HTTP_METHODS } from '@talend/http'; + +http.get('/api/v1/data', { context: { intercept: true } }); + +addHttpResponseInterceptor('my-interceptor', async (response: Response, request: TalendRequest) => { + const { context } = request; + if (request.method === HTTP_METHODS.GET && context.intercept) { + // your custom logic here + } + return response; +}); +``` diff --git a/packages/http/package.json b/packages/http/package.json index 6e85a7ffab..faec72768e 100644 --- a/packages/http/package.json +++ b/packages/http/package.json @@ -1,6 +1,6 @@ { "name": "@talend/http", - "version": "2.3.0", + "version": "2.4.0", "description": "HTTP helper", "license": "Apache-2.0", "repository": { diff --git a/packages/http/src/config.test.ts b/packages/http/src/config.test.ts index 4f2513d6a7..f9d83f0a69 100644 --- a/packages/http/src/config.test.ts +++ b/packages/http/src/config.test.ts @@ -6,7 +6,10 @@ import { removeHttpResponseInterceptor, setDefaultConfig, setDefaultLanguage, + applyInterceptors, } from './config'; +import { HTTP_METHODS, HTTP_STATUS } from './http.constants'; +import { TalendRequest } from './http.types'; describe('Configuration service', () => { describe('setDefaultLanguage', () => { @@ -93,5 +96,70 @@ describe('Configuration service', () => { ); expect(HTTP_RESPONSE_INTERCEPTORS).toEqual({ myInterceptor2: interceptor2 }); }); + it('should apply all interceptors', async () => { + const request: TalendRequest = { + url: '/api/v1/data', + method: HTTP_METHODS.GET, + }; + const response = { + ok: true, + status: HTTP_STATUS.OK, + body: [1, 2, 3], + } as unknown as Response; + + const interceptor1 = jest + .fn() + .mockImplementation((resp, _) => Promise.resolve({ ...resp, body: [...resp.body, 4] })); + addHttpResponseInterceptor('interceptor-1', interceptor1); + + const interceptor2 = jest.fn().mockImplementation((resp, req) => + Promise.resolve({ + ...resp, + body: { interceptor: `interceptor2-${req.method}`, original: resp.body }, + }), + ); + addHttpResponseInterceptor('interceptor-2', interceptor2); + + const interceptedResponse = await applyInterceptors(request, response); + + expect(interceptor1).toHaveBeenCalledWith(response, request); + expect(interceptor2).toHaveBeenLastCalledWith( + expect.objectContaining({ body: [1, 2, 3, 4] }), + request, + ); + expect(interceptedResponse).toEqual({ + ...response, + body: { interceptor: 'interceptor2-GET', original: [1, 2, 3, 4] }, + }); + }); + it('should return response if no interceptors', () => { + const request: TalendRequest = { + url: '/api/v1/data', + method: HTTP_METHODS.GET, + }; + const response = { + ok: true, + status: HTTP_STATUS.OK, + body: [1, 2, 3], + } as unknown as Response; + + expect(applyInterceptors(request, response)).resolves.toEqual(response); + }); + it('should return response if interceptor returns void', async () => { + const request: TalendRequest = { + url: '/api/v1/data', + method: HTTP_METHODS.GET, + }; + const response = { + ok: true, + status: HTTP_STATUS.OK, + body: [1, 2, 3], + } as unknown as Response; + const interceptor = jest.fn().mockImplementation(() => {}); + addHttpResponseInterceptor('interceptor', interceptor); + const gotResponse = await applyInterceptors(request, response); + expect(gotResponse).toEqual(response); + expect(interceptor).toHaveBeenCalledWith(response, request); + }); }); }); diff --git a/packages/http/src/config.ts b/packages/http/src/config.ts index bd12d85b01..dbccd101cc 100644 --- a/packages/http/src/config.ts +++ b/packages/http/src/config.ts @@ -1,4 +1,4 @@ -import { TalendRequestInit } from './http.types'; +import { TalendRequest, TalendRequestInit } from './http.types'; /** * Storage point for the doc setup using `setDefaultConfig` @@ -7,12 +7,11 @@ export const HTTP: { defaultConfig?: TalendRequestInit | null } = { defaultConfig: null, }; -export const HTTP_RESPONSE_INTERCEPTORS: Record void> = {}; +export type Interceptor = (response: Response, request: TalendRequest) => Promise | void; -export function addHttpResponseInterceptor( - name: string, - interceptor: (response: Response) => void, -) { +export const HTTP_RESPONSE_INTERCEPTORS: Record = {}; + +export function addHttpResponseInterceptor(name: string, interceptor: Interceptor) { if (HTTP_RESPONSE_INTERCEPTORS[name]) { throw new Error(`Interceptor ${name} already exists`); } @@ -26,6 +25,14 @@ export function removeHttpResponseInterceptor(name: string) { delete HTTP_RESPONSE_INTERCEPTORS[name]; } +export function applyInterceptors(request: TalendRequest, response: Response): Promise { + return Object.values(HTTP_RESPONSE_INTERCEPTORS).reduce( + (promise, interceptor) => + promise.then(resp => interceptor(resp, request) || Promise.resolve(response)), + Promise.resolve(response), + ); +} + /** * setDefaultHeader - define a default config to use with the saga http * this default config is stored in this module for the whole application diff --git a/packages/http/src/http.common.test.ts b/packages/http/src/http.common.test.ts index 2905f1d31b..f4baf5071c 100644 --- a/packages/http/src/http.common.test.ts +++ b/packages/http/src/http.common.test.ts @@ -1,7 +1,13 @@ import fetchMock from 'fetch-mock'; import { Response, Headers } from 'node-fetch'; -import { HTTP, getDefaultConfig, setDefaultConfig } from './config'; +import { + HTTP, + getDefaultConfig, + setDefaultConfig, + HTTP_RESPONSE_INTERCEPTORS, + addHttpResponseInterceptor, +} from './config'; import { httpFetch, handleBody, encodePayload, handleHttpResponse } from './http.common'; import { HTTP_METHODS, HTTP_STATUS } from './http.constants'; import { TalendHttpError } from './http.types'; @@ -48,7 +54,10 @@ describe('handleBody', () => { const blob = jest.fn(() => Promise.resolve()); - await handleBody({ blob, headers } as any); + await handleBody({ + headers, + clone: jest.fn().mockReturnValue({ blob }), + } as any); expect(blob).toHaveBeenCalled(); }); @@ -71,6 +80,12 @@ describe('handleBody', () => { expect(result.data).toBe(''); }); + it("should manage response's body and return a clone with unused body", async () => { + const result = await handleBody(new Response('ok') as any); + expect(result.data).toBe('ok'); + expect(result.response.bodyUsed).toBe(false); + }); + describe('#handleHttpResponse', () => { it('should handle the response with 2xx code', async () => { const headers = new Headers(); @@ -328,3 +343,44 @@ describe('#httpFetch', () => { expect(mockCalls[0][1]?.headers).toEqual({ Accept: 'application/json' }); }); }); + +describe('#httpFetch with interceptors', () => { + beforeEach(() => { + for (const key in HTTP_RESPONSE_INTERCEPTORS) { + if (HTTP_RESPONSE_INTERCEPTORS.hasOwnProperty(key)) { + delete HTTP_RESPONSE_INTERCEPTORS[key]; + } + } + }); + + afterEach(() => { + fetchMock.restore(); + }); + + it('should call interceptor', async () => { + const interceptor = jest.fn().mockImplementation((res, _) => res); + addHttpResponseInterceptor('interceptor', interceptor); + + const url = '/foo'; + fetchMock.mock(url, { body: defaultBody, status: 200 }); + + await httpFetch(url, {}, HTTP_METHODS.GET, {}); + expect(interceptor).toHaveBeenCalled(); + }); + + it('should have access to context in interceptor', async () => { + const interceptor = jest.fn().mockImplementation((res, _) => res); + addHttpResponseInterceptor('interceptor', interceptor); + + const url = '/foo'; + const context = { async: true }; + const response = { body: defaultBody, status: 200 }; + fetchMock.mock(url, response); + + await httpFetch(url, { context }, HTTP_METHODS.GET, {}); + expect(interceptor).toHaveBeenCalledWith( + expect.anything(), + expect.objectContaining({ url, context, method: HTTP_METHODS.GET }), + ); + }); +}); diff --git a/packages/http/src/http.common.ts b/packages/http/src/http.common.ts index 9ebc480229..ee6b27e221 100644 --- a/packages/http/src/http.common.ts +++ b/packages/http/src/http.common.ts @@ -1,4 +1,4 @@ -import { HTTP, HTTP_RESPONSE_INTERCEPTORS } from './config'; +import { applyInterceptors, HTTP } from './config'; import { mergeCSRFToken } from './csrfHandling'; import { HTTP_STATUS, testHTTPCode } from './http.constants'; import { TalendHttpResponse, TalendRequestInit } from './http.types'; @@ -40,17 +40,18 @@ export function encodePayload(headers: HeadersInit, payload: any) { * @return {Promise} A promise that resolves with the result of parsing the body */ export async function handleBody(response: Response) { + const clonedResponse = response.clone(); const { headers } = response; const contentType = headers.get('Content-Type'); if (contentType && contentType.includes('application/json')) { - return response.json().then(data => ({ data, response })); + return clonedResponse.json().then(data => ({ data, response })); } if (contentType && contentType.includes('application/zip')) { - return response.blob().then(data => ({ data, response })); + return clonedResponse.blob().then(data => ({ data, response })); } - return response.text().then(data => ({ data, response })); + return clonedResponse.text().then(data => ({ data, response })); } /** @@ -118,17 +119,21 @@ export async function httpFetch( }, }; - const response = await fetch( - url, - handleCSRFToken({ - ...params, - body: encodePayload(params.headers || {}, payload), - }), - ); - - Object.values(HTTP_RESPONSE_INTERCEPTORS).forEach(interceptor => { - interceptor(response); + const { context, ...init } = handleCSRFToken({ + ...params, + body: encodePayload(params.headers || {}, payload), }); + const response = await fetch(url, init).then(resp => + applyInterceptors( + { + url, + ...init, + context, + }, + resp, + ), + ); + return handleHttpResponse(response); } diff --git a/packages/http/src/http.types.ts b/packages/http/src/http.types.ts index 71294103ab..8c75665703 100644 --- a/packages/http/src/http.types.ts +++ b/packages/http/src/http.types.ts @@ -10,8 +10,13 @@ export type TalendRequestInitSecurity = { export interface TalendRequestInit extends RequestInit { security?: TalendRequestInitSecurity; + context?: Record; } +export type TalendRequest = { + url: string; +} & TalendRequestInit; + export interface TalendHttpError extends Error { response: Response; data: T; diff --git a/packages/theme/CHANGELOG.md b/packages/theme/CHANGELOG.md index dc42b90347..439f4ce705 100644 --- a/packages/theme/CHANGELOG.md +++ b/packages/theme/CHANGELOG.md @@ -1,5 +1,16 @@ # @talend/bootstrap-theme +## 8.2.0 + +### Minor Changes + +- 9d137cb98: feat: upgrade some webpack loader + +### Patch Changes + +- Updated dependencies [9d137cb98] + - @talend/bootstrap-sass@3.5.0 + ## 8.1.3 ### Patch Changes diff --git a/packages/theme/package.json b/packages/theme/package.json index 42f9f3b753..20d253e75e 100644 --- a/packages/theme/package.json +++ b/packages/theme/package.json @@ -27,31 +27,30 @@ "url": "https://github.com/Talend/ui.git" }, "dependencies": { - "@talend/bootstrap-sass": "^3.4.8", + "@talend/bootstrap-sass": "^3.5.0", "@talend/design-tokens": "^2.9.0" }, "devDependencies": { "@talend/scripts-core": "^15.0.0", "copy-webpack-plugin": "^10.2.4", "css-minimizer-webpack-plugin": "^4.2.2", + "css-loader": "^4.3.0", + "file-loader": "^6.2.0", "html-webpack-plugin": "^5.5.3", + "mini-css-extract-plugin": "^2.7.6", + "postcss": "^8.4.31", + "postcss-loader": "^7.3.3", "postcss-preset-env": "^7.8.3", "rimraf": "^3.0.2", - "mini-css-extract-plugin":"2.7.6", - "webpack": "^5.58.2", - "file-loader":"^6.2.0", - "sass-loader":"^12.6.0", - "sass":"^1.67.0", - "style-loader":"^3.3.3", - "css-loader": "^4.3.0", - "postcss-loader": "^7.3.3" - - - + "sass": "^1.68.0", + "sass-loader": "^13.3.2", + "style-loader": "^3.3.3", + "webpack": "^5.88.2", + "webpack-cli": "^4.10.0" }, "peerDependencies": {}, "publishConfig": { "access": "public" }, - "version": "8.1.3" + "version": "8.2.0" } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index cdb92b554c..c5108cb5eb 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -448,7 +448,7 @@ importers: specifier: ^1.2.2 version: link:../assets-api '@talend/bootstrap-theme': - specifier: ^8.1.3 + specifier: ^8.2.0 version: link:../theme '@talend/design-tokens': specifier: ^2.9.0 @@ -557,7 +557,7 @@ importers: specifier: ^9.5.0 version: 9.5.0 '@talend/scripts-config-react-webpack': - specifier: ^16.0.0 + specifier: ^16.1.0 version: link:../../tools/scripts-config-react-webpack '@talend/scripts-core': specifier: ^15.0.0 @@ -900,7 +900,7 @@ importers: version: 7.4.1 '@storybook/preset-scss': specifier: ^1.0.3 - version: 1.0.3(css-loader@4.3.0)(sass-loader@12.6.0)(style-loader@3.3.3) + version: 1.0.3(css-loader@4.3.0)(sass-loader@13.3.2)(style-loader@3.3.3) '@storybook/react-webpack5': specifier: ^7.4.1 version: 7.4.1(@babel/core@7.22.20)(@swc/core@1.3.70)(@types/react-dom@17.0.20)(@types/react@17.0.65)(esbuild@0.18.15)(react-dom@17.0.2)(react@17.0.2)(typescript@5.2.2) @@ -1015,7 +1015,7 @@ importers: version: 7.4.1 '@storybook/preset-scss': specifier: ^1.0.3 - version: 1.0.3(css-loader@4.3.0)(sass-loader@12.6.0)(style-loader@3.3.3) + version: 1.0.3(css-loader@4.3.0)(sass-loader@13.3.2)(style-loader@3.3.3) '@storybook/react': specifier: ^7.4.1 version: 7.4.1(react-dom@17.0.2)(react@17.0.2)(typescript@5.2.2) @@ -1874,7 +1874,7 @@ importers: version: 7.4.1 '@storybook/preset-scss': specifier: ^1.0.3 - version: 1.0.3(css-loader@4.3.0)(sass-loader@12.6.0)(style-loader@3.3.3) + version: 1.0.3(css-loader@4.3.0)(sass-loader@13.3.2)(style-loader@3.3.3) '@storybook/react-webpack5': specifier: ^7.4.1 version: 7.4.1(@babel/core@7.22.20)(@swc/core@1.3.70)(@types/react-dom@17.0.20)(@types/react@17.0.65)(esbuild@0.18.15)(react-dom@17.0.2)(react@17.0.2)(typescript@5.2.2) @@ -1927,7 +1927,7 @@ importers: packages/theme: dependencies: '@talend/bootstrap-sass': - specifier: ^3.4.8 + specifier: ^3.5.0 version: link:../../fork/bootstrap-sass '@talend/design-tokens': specifier: ^2.9.0 @@ -1952,8 +1952,11 @@ importers: specifier: ^5.5.3 version: 5.5.3(webpack@5.88.2) mini-css-extract-plugin: - specifier: 2.7.6 + specifier: ^2.7.6 version: 2.7.6(webpack@5.88.2) + postcss: + specifier: ^8.4.31 + version: 8.4.31 postcss-loader: specifier: ^7.3.3 version: 7.3.3(postcss@8.4.31)(typescript@5.2.2)(webpack@5.88.2) @@ -1964,17 +1967,20 @@ importers: specifier: ^3.0.2 version: 3.0.2 sass: - specifier: ^1.67.0 - version: 1.67.0 + specifier: ^1.68.0 + version: 1.69.3 sass-loader: - specifier: ^12.6.0 - version: 12.6.0(sass@1.67.0)(webpack@5.88.2) + specifier: ^13.3.2 + version: 13.3.2(sass@1.69.3)(webpack@5.88.2) style-loader: specifier: ^3.3.3 version: 3.3.3(webpack@5.88.2) webpack: - specifier: ^5.58.2 + specifier: ^5.88.2 version: 5.88.2(webpack-cli@4.10.0) + webpack-cli: + specifier: ^4.10.0 + version: 4.10.0(webpack-bundle-analyzer@4.9.1)(webpack@5.88.2) packages/utils: dependencies: @@ -2420,7 +2426,7 @@ importers: specifier: ^2.7.6 version: 2.7.6(webpack@5.88.2) postcss: - specifier: '>=8.4.31' + specifier: ^8.4.31 version: 8.4.31 postcss-loader: specifier: ^7.3.3 @@ -2435,11 +2441,11 @@ importers: specifier: ^5.0.0 version: 5.0.0 sass: - specifier: ^1.67.0 - version: 1.67.0 + specifier: ^1.68.0 + version: 1.69.3 sass-loader: - specifier: ^12.6.0 - version: 12.6.0(sass@1.67.0)(webpack@5.88.2) + specifier: ^13.3.2 + version: 13.3.2(sass@1.69.3)(webpack@5.88.2) source-map-loader: specifier: ^4.0.1 version: 4.0.1(webpack@5.88.2) @@ -2499,7 +2505,7 @@ importers: version: 0.2.2 '@storybook/preset-scss': specifier: ^1.0.3 - version: 1.0.3(css-loader@4.3.0)(sass-loader@12.6.0)(style-loader@3.3.3) + version: 1.0.3(css-loader@4.3.0)(sass-loader@13.3.2)(style-loader@3.3.3) '@storybook/react': specifier: ^7.4.1 version: 7.4.1(react-dom@17.0.2)(react@17.0.2)(typescript@5.2.2) @@ -7746,7 +7752,7 @@ packages: - webpack-hot-middleware - webpack-plugin-serve - /@storybook/preset-scss@1.0.3(css-loader@4.3.0)(sass-loader@12.6.0)(style-loader@3.3.3): + /@storybook/preset-scss@1.0.3(css-loader@4.3.0)(sass-loader@13.3.2)(style-loader@3.3.3): resolution: {integrity: sha512-o9Iz6wxPeNENrQa2mKlsDKynBfqU2uWaRP80HeWp4TkGgf7/x3DVF2O7yi9N0x/PI1qzzTTpxlQ90D62XmpiTw==} peerDependencies: css-loader: '*' @@ -7754,7 +7760,7 @@ packages: style-loader: '*' dependencies: css-loader: 4.3.0(webpack@5.88.2) - sass-loader: 12.6.0(webpack@5.88.2) + sass-loader: 13.3.2(webpack@5.88.2) style-loader: 3.3.3(webpack@5.88.2) /@storybook/preview-api@7.4.0: @@ -17754,10 +17760,6 @@ packages: engines: {node: '>=6'} dev: true - /klona@2.0.6: - resolution: {integrity: sha512-dhG34DXATL5hSxJbIexCft8FChFXtmskoZYnoPWjXQuebWYCNkVeV3KkGegCK9CP1oswI/vQibS2GY7Em/sJJA==} - engines: {node: '>= 8'} - /known-css-properties@0.28.0: resolution: {integrity: sha512-9pSL5XB4J+ifHP0e0jmmC98OGC1nL8/JjS+fi6mnTlIf//yt/MfVLtKg7S6nCtj/8KTcWX7nRlY0XywoYY1ISQ==} dev: false @@ -22339,12 +22341,12 @@ packages: - supports-color dev: true - /sass-loader@12.6.0(sass@1.67.0)(webpack@5.88.2): - resolution: {integrity: sha512-oLTaH0YCtX4cfnJZxKSLAyglED0naiYfNG1iXfU5w1LNZ+ukoA5DtyDIN5zmKVZwYNJP4KRc5Y3hkWga+7tYfA==} - engines: {node: '>= 12.13.0'} + /sass-loader@13.3.2(sass@1.69.3)(webpack@5.88.2): + resolution: {integrity: sha512-CQbKl57kdEv+KDLquhC+gE3pXt74LEAzm+tzywcA0/aHZuub8wTErbjAoNI57rPUWRYRNC5WUnNl8eGJNbDdwg==} + engines: {node: '>= 14.15.0'} peerDependencies: fibers: '>= 3.1.0' - node-sass: ^4.0.0 || ^5.0.0 || ^6.0.0 || ^7.0.0 + node-sass: ^4.0.0 || ^5.0.0 || ^6.0.0 || ^7.0.0 || ^8.0.0 || ^9.0.0 sass: ^1.3.0 sass-embedded: '*' webpack: ^5.0.0 @@ -22358,17 +22360,16 @@ packages: sass-embedded: optional: true dependencies: - klona: 2.0.6 neo-async: 2.6.2 - sass: 1.67.0 + sass: 1.69.3 webpack: 5.88.2(webpack-cli@4.10.0) - /sass-loader@12.6.0(webpack@5.88.2): - resolution: {integrity: sha512-oLTaH0YCtX4cfnJZxKSLAyglED0naiYfNG1iXfU5w1LNZ+ukoA5DtyDIN5zmKVZwYNJP4KRc5Y3hkWga+7tYfA==} - engines: {node: '>= 12.13.0'} + /sass-loader@13.3.2(webpack@5.88.2): + resolution: {integrity: sha512-CQbKl57kdEv+KDLquhC+gE3pXt74LEAzm+tzywcA0/aHZuub8wTErbjAoNI57rPUWRYRNC5WUnNl8eGJNbDdwg==} + engines: {node: '>= 14.15.0'} peerDependencies: fibers: '>= 3.1.0' - node-sass: ^4.0.0 || ^5.0.0 || ^6.0.0 || ^7.0.0 + node-sass: ^4.0.0 || ^5.0.0 || ^6.0.0 || ^7.0.0 || ^8.0.0 || ^9.0.0 sass: ^1.3.0 sass-embedded: '*' webpack: ^5.0.0 @@ -22382,12 +22383,11 @@ packages: sass-embedded: optional: true dependencies: - klona: 2.0.6 neo-async: 2.6.2 webpack: 5.88.2(@swc/core@1.3.70)(esbuild@0.18.15) - /sass@1.67.0: - resolution: {integrity: sha512-SVrO9ZeX/QQyEGtuZYCVxoeAL5vGlYjJ9p4i4HFuekWl8y/LtJ7tJc10Z+ck1c8xOuoBm2MYzcLfTAffD0pl/A==} + /sass@1.69.3: + resolution: {integrity: sha512-X99+a2iGdXkdWn1akFPs0ZmelUzyAQfvqYc2P/MPTrJRuIRoTffGzT9W9nFqG00S+c8hXzVmgxhUuHFdrwxkhQ==} engines: {node: '>=14.0.0'} hasBin: true dependencies: diff --git a/tools/scripts-config-react-webpack/CHANGELOG.md b/tools/scripts-config-react-webpack/CHANGELOG.md index b689f274d1..a796a936e2 100644 --- a/tools/scripts-config-react-webpack/CHANGELOG.md +++ b/tools/scripts-config-react-webpack/CHANGELOG.md @@ -1,5 +1,11 @@ # @talend/scripts-config-react-webpack +## 16.1.0 + +### Minor Changes + +- 9d137cb98: feat: upgrade some webpack loader + ## 16.0.0 ### Major Changes diff --git a/tools/scripts-config-react-webpack/package.json b/tools/scripts-config-react-webpack/package.json index d57f0da22a..1afc2f139d 100644 --- a/tools/scripts-config-react-webpack/package.json +++ b/tools/scripts-config-react-webpack/package.json @@ -1,7 +1,7 @@ { "name": "@talend/scripts-config-react-webpack", "description": "Webpack configuration for @talend/scripts-core", - "version": "16.0.0", + "version": "16.1.0", "license": "Apache-2.0", "main": "index.js", "author": "Talend Frontend ", @@ -38,13 +38,13 @@ "html-webpack-plugin": "^5.5.3", "inspectpack": "^4.7.1", "mini-css-extract-plugin": "^2.7.6", - "postcss": "^8.4.29", + "postcss": "^8.4.31", "postcss-loader": "^7.3.3", "postcss-safe-parser": "^6.0.0", "regenerator-runtime": "^0.13.11", "resolve-url-loader": "^5.0.0", - "sass": "^1.67.0", - "sass-loader": "^12.6.0", + "sass": "^1.68.0", + "sass-loader": "^13.3.2", "source-map-loader": "^4.0.1", "style-loader": "^3.3.3", "svg64": "^1.2.0",