Skip to content

Commit

Permalink
Fix key construction (#111)
Browse files Browse the repository at this point in the history
Co-authored-by: Automated Version Bump <[email protected]>
  • Loading branch information
motechFR and Automated Version Bump authored Aug 29, 2023
1 parent 55f023b commit c17f48b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@charmverse/core",
"version": "0.3.15",
"version": "0.3.16-rc-fix-get-request.0",
"description": "Core API for Charmverse",
"type": "commonjs",
"types": "./dist/cjs/index.d.ts",
Expand Down
12 changes: 8 additions & 4 deletions src/lib/http/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@ type Params = { [key: string]: any };
export function GET<T = Response>(
_requestUrl: string,
data: Params | null | undefined,
{ headers = {}, credentials = 'include' }: { credentials?: RequestCredentials; headers?: any } = {}
{
headers = {},
credentials = 'include',
addBracketsToArrayValues
}: { credentials?: RequestCredentials; headers?: any; addBracketsToArrayValues?: boolean } = {}
): Promise<T> {
const requestUrl = _appendQuery(_requestUrl, data || {});
const requestUrl = _appendQuery(_requestUrl, data || {}, addBracketsToArrayValues);
return fetch<T>(requestUrl, {
method: 'GET',
headers: new Headers({
Expand Down Expand Up @@ -69,13 +73,13 @@ export function PUT<T>(requestURL: string, data: Params = {}, { headers = {} }:
});
}

function _appendQuery(path: string, data: Params) {
function _appendQuery(path: string, data: Params, addBracketsToArrayValues: boolean = true) {
const queryString = Object.keys(data)
.filter((key) => !!data[key])
.map((key) => {
const value = data[key];
return Array.isArray(value)
? `${value.map((v: string) => `${key}[]=${v}`).join('&')}`
? `${value.map((v: string) => `${key}${addBracketsToArrayValues ? '[]' : ''}=${v}`).join('&')}`
: `${key}=${encodeURIComponent(value)}`;
})
.join('&');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ export class PagePermissionsHttpClient extends AbstractPermissionsApiClient impl
);

const computedResult = await asyncSeries(chunkedPageIds, (chunkedRequest: BulkPagePermissionCompute) =>
GET<BulkPagePermissionFlags>(`${this.prefix}/bulk-compute-page-permissions`, chunkedRequest)
GET<BulkPagePermissionFlags>(`${this.prefix}/bulk-compute-page-permissions`, chunkedRequest, {
addBracketsToArrayValues: false
})
).then((results) => {
const mergedResults: BulkPagePermissionFlags = {};

Expand Down

0 comments on commit c17f48b

Please sign in to comment.