diff --git a/.github/actions/es-lint/action.yml b/.github/actions/es-lint/action.yml index 97f8c0976..fda93f250 100644 --- a/.github/actions/es-lint/action.yml +++ b/.github/actions/es-lint/action.yml @@ -4,7 +4,7 @@ runs: using: "composite" steps: - name: Install deps - run: npm i -g npm && npm install + run: npm ci shell: bash - name: Run lint run: npm run test:lint diff --git a/.github/actions/functional-tests/action.yml b/.github/actions/functional-tests/action.yml index 7d25fd512..d0e4a25ac 100644 --- a/.github/actions/functional-tests/action.yml +++ b/.github/actions/functional-tests/action.yml @@ -14,7 +14,7 @@ runs: shell: bash - name: Build Kuzzle run: | - npm install + npm ci npm run build shell: bash - name: Run functional tests diff --git a/.github/actions/snippet-tests/action.yml b/.github/actions/snippet-tests/action.yml index e3f41babe..8d67c070b 100644 --- a/.github/actions/snippet-tests/action.yml +++ b/.github/actions/snippet-tests/action.yml @@ -9,7 +9,7 @@ runs: steps: - name: Build the Stack run: | - npm install + npm ci npm run build shell: bash - run: npm run doc-testing diff --git a/.github/actions/unit-tests/action.yml b/.github/actions/unit-tests/action.yml index d531856f9..b7105332f 100644 --- a/.github/actions/unit-tests/action.yml +++ b/.github/actions/unit-tests/action.yml @@ -5,7 +5,7 @@ runs: steps: - name: Run build run: | - npm install + npm ci npm run build shell: bash - name: Run tests diff --git a/.github/workflows/push_branches.workflow.yaml b/.github/workflows/push_branches.workflow.yaml index c7cd96c34..921582f4c 100644 --- a/.github/workflows/push_branches.workflow.yaml +++ b/.github/workflows/push_branches.workflow.yaml @@ -45,11 +45,12 @@ jobs: - name: Checkout uses: actions/checkout@v3 - - uses: convictional/trigger-workflow-and-wait@v1.6.3 + - name: Deploy the documentation + uses: convictional/trigger-workflow-and-wait@v1.6.3 with: owner: kuzzleio repo: documentation github_token: ${{ secrets.ACCESS_TOKEN_CI }} workflow_file_name: child_repo.workflow.yml ref: ${{ github.ref_name == 'master' && 'master' || 'develop' }} - client_payload: '{"repo_name":"sdk-javascript","branch":"${{ github.ref_name }}","version":"1"}' + client_payload: '{"repo_name":"sdk-javascript","branch":"${{ github.ref_name }}","version":"7"}' diff --git a/src/protocols/Http.ts b/src/protocols/Http.ts index bcc86fed6..fcdeadaf4 100644 --- a/src/protocols/Http.ts +++ b/src/protocols/Http.ts @@ -1,9 +1,9 @@ "use strict"; -import staticHttpRoutes from "./routes.json"; -import { KuzzleAbstractProtocol } from "./abstract/Base"; import { HttpRoutes, JSONObject } from "../types"; import { RequestPayload } from "../types/RequestPayload"; +import { KuzzleAbstractProtocol } from "./abstract/Base"; +import staticHttpRoutes from "./routes.json"; /** * Http protocol used to connect to a Kuzzle server. @@ -405,6 +405,11 @@ export default class HttpProtocol extends KuzzleAbstractProtocol { ); } + const contentType = response.headers["content-type"]; + if (!contentType || !contentType.includes("application/json")) { + return response.body; + } + return JSON.parse(response.body); }); } @@ -435,6 +440,11 @@ export default class HttpProtocol extends KuzzleAbstractProtocol { xhr.onload = () => { try { + const contentType = xhr.getResponseHeader("Content-Type"); + if (!contentType || !contentType.includes("application/json")) { + resolve(xhr.responseText); + return; + } const json = JSON.parse(xhr.responseText); resolve(json); } catch (err) { diff --git a/src/types/ProfilePolicy.ts b/src/types/ProfilePolicy.ts index 89ada2e60..45986ff1e 100644 --- a/src/types/ProfilePolicy.ts +++ b/src/types/ProfilePolicy.ts @@ -24,17 +24,19 @@ export type ProfilePolicy = { /** * Optional array of restrictions on which the rights are gonne be applied */ - restrictedTo?: { - /** - * Index name. - * Rights will only be applied on this index. - */ - index: string; + restrictedTo?: [ + { + /** + * Index name. + * Rights will only be applied on this index. + */ + index: string; - /** - * Collection names. - * Rights will only be applied on those collections. - */ - collections?: Array; - }; + /** + * Collection names. + * Rights will only be applied on those collections. + */ + collections?: Array; + } + ]; }; diff --git a/test/protocol/Http.test.js b/test/protocol/Http.test.js index bdad64c42..00ead9347 100644 --- a/test/protocol/Http.test.js +++ b/test/protocol/Http.test.js @@ -677,9 +677,12 @@ describe("HTTP networking module", () => { let httpRequestStub; beforeEach(() => { - httpRequestStub = sinon - .stub() - .resolves({ body: JSON.stringify(mockResponseBody) }); + httpRequestStub = sinon.stub().resolves({ + body: JSON.stringify(mockResponseBody), + headers: { + "content-type": "application/json", + }, + }); const { default: MockHttp } = proxyquire("../../src/protocols/Http", { "min-req-promise": { request: httpRequestStub }, @@ -793,6 +796,7 @@ describe("HTTP networking module", () => { open: sinon.stub(), send: sinon.stub(), setRequestHeader: sinon.stub(), + getResponseHeader: sinon.stub().returns("application/json"), onreadystatechange: sinon.stub(), timeout: 0, };