Skip to content

Commit 16903e4

Browse files
authored
Merge pull request #734 from kuzzleio/7-dev
fix: (ProfilePolicy.ts) restrictedTo was mistyped (#733)
2 parents e4bdf50 + 0938207 commit 16903e4

File tree

8 files changed

+40
-23
lines changed

8 files changed

+40
-23
lines changed

.github/actions/es-lint/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ runs:
44
using: "composite"
55
steps:
66
- name: Install deps
7-
run: npm i -g npm && npm install
7+
run: npm ci
88
shell: bash
99
- name: Run lint
1010
run: npm run test:lint

.github/actions/functional-tests/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ runs:
1414
shell: bash
1515
- name: Build Kuzzle
1616
run: |
17-
npm install
17+
npm ci
1818
npm run build
1919
shell: bash
2020
- name: Run functional tests

.github/actions/snippet-tests/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ runs:
99
steps:
1010
- name: Build the Stack
1111
run: |
12-
npm install
12+
npm ci
1313
npm run build
1414
shell: bash
1515
- run: npm run doc-testing

.github/actions/unit-tests/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ runs:
55
steps:
66
- name: Run build
77
run: |
8-
npm install
8+
npm ci
99
npm run build
1010
shell: bash
1111
- name: Run tests

.github/workflows/push_branches.workflow.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,12 @@ jobs:
4545
- name: Checkout
4646
uses: actions/checkout@v3
4747

48-
- uses: convictional/[email protected]
48+
- name: Deploy the documentation
49+
uses: convictional/[email protected]
4950
with:
5051
owner: kuzzleio
5152
repo: documentation
5253
github_token: ${{ secrets.ACCESS_TOKEN_CI }}
5354
workflow_file_name: child_repo.workflow.yml
5455
ref: ${{ github.ref_name == 'master' && 'master' || 'develop' }}
55-
client_payload: '{"repo_name":"sdk-javascript","branch":"${{ github.ref_name }}","version":"1"}'
56+
client_payload: '{"repo_name":"sdk-javascript","branch":"${{ github.ref_name }}","version":"7"}'

src/protocols/Http.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
"use strict";
22

3-
import staticHttpRoutes from "./routes.json";
4-
import { KuzzleAbstractProtocol } from "./abstract/Base";
53
import { HttpRoutes, JSONObject } from "../types";
64
import { RequestPayload } from "../types/RequestPayload";
5+
import { KuzzleAbstractProtocol } from "./abstract/Base";
6+
import staticHttpRoutes from "./routes.json";
77

88
/**
99
* Http protocol used to connect to a Kuzzle server.
@@ -405,6 +405,11 @@ export default class HttpProtocol extends KuzzleAbstractProtocol {
405405
);
406406
}
407407

408+
const contentType = response.headers["content-type"];
409+
if (!contentType || !contentType.includes("application/json")) {
410+
return response.body;
411+
}
412+
408413
return JSON.parse(response.body);
409414
});
410415
}
@@ -435,6 +440,11 @@ export default class HttpProtocol extends KuzzleAbstractProtocol {
435440

436441
xhr.onload = () => {
437442
try {
443+
const contentType = xhr.getResponseHeader("Content-Type");
444+
if (!contentType || !contentType.includes("application/json")) {
445+
resolve(xhr.responseText);
446+
return;
447+
}
438448
const json = JSON.parse(xhr.responseText);
439449
resolve(json);
440450
} catch (err) {

src/types/ProfilePolicy.ts

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,19 @@ export type ProfilePolicy = {
2424
/**
2525
* Optional array of restrictions on which the rights are gonne be applied
2626
*/
27-
restrictedTo?: {
28-
/**
29-
* Index name.
30-
* Rights will only be applied on this index.
31-
*/
32-
index: string;
27+
restrictedTo?: [
28+
{
29+
/**
30+
* Index name.
31+
* Rights will only be applied on this index.
32+
*/
33+
index: string;
3334

34-
/**
35-
* Collection names.
36-
* Rights will only be applied on those collections.
37-
*/
38-
collections?: Array<string>;
39-
};
35+
/**
36+
* Collection names.
37+
* Rights will only be applied on those collections.
38+
*/
39+
collections?: Array<string>;
40+
}
41+
];
4042
};

test/protocol/Http.test.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -677,9 +677,12 @@ describe("HTTP networking module", () => {
677677
let httpRequestStub;
678678

679679
beforeEach(() => {
680-
httpRequestStub = sinon
681-
.stub()
682-
.resolves({ body: JSON.stringify(mockResponseBody) });
680+
httpRequestStub = sinon.stub().resolves({
681+
body: JSON.stringify(mockResponseBody),
682+
headers: {
683+
"content-type": "application/json",
684+
},
685+
});
683686

684687
const { default: MockHttp } = proxyquire("../../src/protocols/Http", {
685688
"min-req-promise": { request: httpRequestStub },
@@ -793,6 +796,7 @@ describe("HTTP networking module", () => {
793796
open: sinon.stub(),
794797
send: sinon.stub(),
795798
setRequestHeader: sinon.stub(),
799+
getResponseHeader: sinon.stub().returns("application/json"),
796800
onreadystatechange: sinon.stub(),
797801
timeout: 0,
798802
};

0 commit comments

Comments
 (0)