cwmsjs
Version:
CWMS Data API Library for JavaScript/TypeScript created with OpenAPI generator for use with browser webapps
191 lines (156 loc) • 6.79 kB
text/typescript
/* tslint:disable */
/* eslint-disable */
/**
* CWMS Data API
* CWMS REST API for Data Retrieval
*
* The version of the OpenAPI document: 2.3.2-2025.03.19
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
import * as runtime from '../runtime';
import type {
ApiKey,
CdaError,
} from '../models/index';
import {
ApiKeyFromJSON,
ApiKeyToJSON,
CdaErrorFromJSON,
CdaErrorToJSON,
} from '../models/index';
export interface DeleteAuthKeysWithKeyNameRequest {
keyName: string;
}
export interface GetAuthKeysWithKeyNameRequest {
keyName: string;
}
export interface PostAuthKeysRequest {
apiKey?: ApiKey;
}
/**
*
*/
export class AuthorizationApi extends runtime.BaseAPI {
/**
* Delete API key for a user
* Delete cwmsData auth keys with keyName
*/
async deleteAuthKeysWithKeyNameRaw(requestParameters: DeleteAuthKeysWithKeyNameRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<ApiKey>> {
if (requestParameters['keyName'] == null) {
throw new runtime.RequiredError(
'keyName',
'Required parameter "keyName" was null or undefined when calling deleteAuthKeysWithKeyName().'
);
}
const queryParameters: any = {};
const headerParameters: runtime.HTTPHeaders = {};
if (this.configuration && this.configuration.apiKey) {
headerParameters["Authorization"] = await this.configuration.apiKey("Authorization"); // ApiKey authentication
}
const response = await this.request({
path: `/auth/keys/{key-name}`.replace(`{${"key-name"}}`, encodeURIComponent(String(requestParameters['keyName']))),
method: 'DELETE',
headers: headerParameters,
query: queryParameters,
}, initOverrides);
return new runtime.JSONApiResponse(response, (jsonValue) => ApiKeyFromJSON(jsonValue));
}
/**
* Delete API key for a user
* Delete cwmsData auth keys with keyName
*/
async deleteAuthKeysWithKeyName(requestParameters: DeleteAuthKeysWithKeyNameRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<ApiKey> {
const response = await this.deleteAuthKeysWithKeyNameRaw(requestParameters, initOverrides);
return await response.value();
}
/**
* View all keys for the current user
* Get cwmsData auth keys
*/
async getAuthKeysRaw(initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<Array<ApiKey>>> {
const queryParameters: any = {};
const headerParameters: runtime.HTTPHeaders = {};
if (this.configuration && this.configuration.apiKey) {
headerParameters["Authorization"] = await this.configuration.apiKey("Authorization"); // ApiKey authentication
}
const response = await this.request({
path: `/auth/keys`,
method: 'GET',
headers: headerParameters,
query: queryParameters,
}, initOverrides);
return new runtime.JSONApiResponse(response, (jsonValue) => jsonValue.map(ApiKeyFromJSON));
}
/**
* View all keys for the current user
* Get cwmsData auth keys
*/
async getAuthKeys(initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<Array<ApiKey>> {
const response = await this.getAuthKeysRaw(initOverrides);
return await response.value();
}
/**
* View specific key
* Get cwmsData auth keys with keyName
*/
async getAuthKeysWithKeyNameRaw(requestParameters: GetAuthKeysWithKeyNameRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<ApiKey>> {
if (requestParameters['keyName'] == null) {
throw new runtime.RequiredError(
'keyName',
'Required parameter "keyName" was null or undefined when calling getAuthKeysWithKeyName().'
);
}
const queryParameters: any = {};
const headerParameters: runtime.HTTPHeaders = {};
if (this.configuration && this.configuration.apiKey) {
headerParameters["Authorization"] = await this.configuration.apiKey("Authorization"); // ApiKey authentication
}
const response = await this.request({
path: `/auth/keys/{key-name}`.replace(`{${"key-name"}}`, encodeURIComponent(String(requestParameters['keyName']))),
method: 'GET',
headers: headerParameters,
query: queryParameters,
}, initOverrides);
return new runtime.JSONApiResponse(response, (jsonValue) => ApiKeyFromJSON(jsonValue));
}
/**
* View specific key
* Get cwmsData auth keys with keyName
*/
async getAuthKeysWithKeyName(requestParameters: GetAuthKeysWithKeyNameRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<ApiKey> {
const response = await this.getAuthKeysWithKeyNameRaw(requestParameters, initOverrides);
return await response.value();
}
/**
* Create a new API Key for user. The randomly generated key is returned to the caller. A provided key will be ignored.
* Post cwmsData auth keys
*/
async postAuthKeysRaw(requestParameters: PostAuthKeysRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<ApiKey>> {
const queryParameters: any = {};
const headerParameters: runtime.HTTPHeaders = {};
headerParameters['Content-Type'] = 'application/json';
if (this.configuration && this.configuration.apiKey) {
headerParameters["Authorization"] = await this.configuration.apiKey("Authorization"); // ApiKey authentication
}
const response = await this.request({
path: `/auth/keys`,
method: 'POST',
headers: headerParameters,
query: queryParameters,
body: ApiKeyToJSON(requestParameters['apiKey']),
}, initOverrides);
return new runtime.JSONApiResponse(response, (jsonValue) => ApiKeyFromJSON(jsonValue));
}
/**
* Create a new API Key for user. The randomly generated key is returned to the caller. A provided key will be ignored.
* Post cwmsData auth keys
*/
async postAuthKeys(requestParameters: PostAuthKeysRequest = {}, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<ApiKey> {
const response = await this.postAuthKeysRaw(requestParameters, initOverrides);
return await response.value();
}
}