MCPcopy Index your code
hub / github.com/coder/coder / ApiMethods

Class ApiMethods

site/src/api/api.ts:515–3134  ·  view source on GitHub ↗

* This is the container for all API methods. It's split off to make it more * clear where API methods should go, but it is eventually merged into the Api * class with a more flat hierarchy * * All public methods should be defined as arrow functions to ensure that they * can be passed around the

Source from the content-addressed store, hash-verified

513 * lexical scope.
514 */
515class ApiMethods {
516 experimental: ExperimentalApiMethods;
517
518 constructor(protected readonly axios: AxiosInstance) {
519 this.experimental = new ExperimentalApiMethods(this.axios);
520 }
521
522 login = async (
523 email: string,
524 password: string,
525 ): Promise<TypesGen.LoginWithPasswordResponse> => {
526 const payload = JSON.stringify({ email, password });
527 const response = await this.axios.post<TypesGen.LoginWithPasswordResponse>(
528 "/api/v2/users/login",
529 payload,
530 { headers: { ...BASE_CONTENT_TYPE_JSON } },
531 );
532
533 return response.data;
534 };
535
536 convertToOAUTH = async (request: TypesGen.ConvertLoginRequest) => {
537 const response = await this.axios.post<TypesGen.OAuthConversionResponse>(
538 "/api/v2/users/me/convert-login",
539 request,
540 );
541
542 return response.data;
543 };
544
545 logout = async (): Promise<void> => {
546 return this.axios.post("/api/v2/users/logout");
547 };
548
549 getAuthenticatedUser = async () => {
550 const response = await this.axios.get<TypesGen.User>("/api/v2/users/me");
551 return response.data;
552 };
553
554 getUser = async (usernameOrId: string) => {
555 const response = await this.axios.get<TypesGen.User>(
556 `/api/v2/users/${encodeURIComponent(usernameOrId)}`,
557 );
558 return response.data;
559 };
560
561 getUserParameters = async (templateID: string) => {
562 const response = await this.axios.get<TypesGen.UserParameter[]>(
563 `/api/v2/users/me/autofill-parameters?template_id=${templateID}`,
564 );
565
566 return response.data;
567 };
568
569 getAuthMethods = async (): Promise<TypesGen.AuthMethods> => {
570 const response = await this.axios.get<TypesGen.AuthMethods>(
571 "/api/v2/users/authmethods",
572 );

Callers

nothing calls this directly

Calls 15

delayFunction · 0.90
isApiErrorFunction · 0.90
getURLWithSearchParamsFunction · 0.85
createWebSocketFunction · 0.85
withDefaultFeaturesFunction · 0.85
getMissingParametersFunction · 0.85
getMethod · 0.80
parseMethod · 0.80
startWorkspaceMethod · 0.80
patchGroupMethod · 0.80
getTemplateMethod · 0.80

Tested by

no test coverage detected