Skip to content

Commit

Permalink
Add context support to query method
Browse files Browse the repository at this point in the history
  • Loading branch information
kkajla12 authored Mar 31, 2024
1 parent 1a8c75d commit bbcce0d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
22 changes: 17 additions & 5 deletions src/modules/WarrantModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { API_VERSION } from "../constants";
import {
ListResponse,
ListWarrantParams,
QueryParams,
QueryListParams,
QueryResult,
Warrant,
Expand Down Expand Up @@ -49,13 +50,24 @@ export default class WarrantModule {
});
}

public static async query(query: string, listParams: QueryListParams = {}, options: WarrantRequestOptions = {}): Promise<ListResponse<QueryResult>> {
public static async query(query: string | QueryParams, listParams: QueryListParams = {}, options: WarrantRequestOptions = {}): Promise<ListResponse<QueryResult>> {
const params: any = {
...listParams,
};

// preserve backwards compatibility
if (typeof query === "string") {
params.q = query;
} else {
params.q = query.query;
if (query.context) {
params.context = query.context;
}
}

return await WarrantClient.httpClient.get({
url: `/${API_VERSION}/query`,
params: {
q: query,
...listParams,
},
params: params,
options,
});
}
Expand Down
7 changes: 6 additions & 1 deletion src/types/Query.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { Warrant } from "./Warrant";
import { Warrant, PolicyContext } from "./Warrant";
import { ListParams } from "./List";

export interface QueryParams {
query: string;
context?: PolicyContext;
}

export interface QueryResult {
objectType: string;
objectId: string;
Expand Down
1 change: 1 addition & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export {
Subject,
} from "./Warrant";
export {
QueryParams,
QueryResult,
QueryListParams,
} from "./Query";
Expand Down

0 comments on commit bbcce0d

Please sign in to comment.