keycloak-scim/js/libs/keycloak-admin-client/src/resources/resource.ts
Jon Koops 8cb202eb29
Add JavaScript admin client to repository (#16697)
* Add JavaScript admin client to repository

* Apply review feedback

Co-authored-by: Stian Thorgersen <stian@redhat.com>

---------

Co-authored-by: Stian Thorgersen <stian@redhat.com>
2023-02-03 10:45:11 +00:00

42 lines
1 KiB
TypeScript

import type { KeycloakAdminClient } from "../client.js";
import { Agent, RequestArgs } from "./agent.js";
export default class Resource<ParamType = {}> {
private agent: Agent;
constructor(
client: KeycloakAdminClient,
settings: {
path?: string;
getUrlParams?: () => Record<string, any>;
getBaseUrl?: () => string;
} = {}
) {
this.agent = new Agent({
client,
...settings,
});
}
public makeRequest = <PayloadType = any, ResponseType = any>(
args: RequestArgs
): ((
payload?: PayloadType & ParamType,
options?: Pick<RequestArgs, "catchNotFound">
) => Promise<ResponseType>) => {
return this.agent.request(args);
};
// update request will take three types: query, payload and response
public makeUpdateRequest = <
QueryType = any,
PayloadType = any,
ResponseType = any
>(
args: RequestArgs
): ((
query: QueryType & ParamType,
payload: PayloadType
) => Promise<ResponseType>) => {
return this.agent.updateRequest(args);
};
}