Skip to content

Commit 26e6aef

Browse files
kworathurgreptile-apps[bot]aakashg00
authored
Implement client for new API key endpoints: create, list, and delete by ID (#74)
* feat: implement create, list, delete api key client library * feat: add openAPI generated classes for new SDK API key functions * styles: remove 'Request' from SDK function names * fix: incorrect casing in module import * fix: incomplete types, undetailed errors, incorrect auth code * models: add updated response model * fix: remove redundant delete api key by id method * feat: updata client sdk with delete api key by id method * feat: add pagination links to get all api keys response * fix: openAPI schema validation errors * add pnpm lockfile * fix: remove conflicting getAllApiKeysResponse.ts * fix: add GetAllApiKeysResponse with correct casing * Update src/lib/validators.ts Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com> * fix: lint errors * fix: merge conflicts * add key validation and fix credentials auth for deleteapikey method --------- Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com> Co-authored-by: aakashg00 <aakashbb@gmail.com>
1 parent 3db0573 commit 26e6aef

10 files changed

Lines changed: 9316 additions & 62 deletions

File tree

‎pnpm-lock.yaml‎

Lines changed: 8761 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/internal/apis/AuthApi.ts‎

Lines changed: 109 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
import * as runtime from '../runtime';
1616
import type {
17+
GetAllApiKeysResponse,
1718
IssueApiKeyRequest,
1819
IssueApiKeyResponse,
1920
IssueJWTResponse,
@@ -22,6 +23,8 @@ import type {
2223
RequestNewAccountModel,
2324
} from '../models/index';
2425
import {
26+
GetAllApiKeysResponseFromJSON,
27+
GetAllApiKeysResponseToJSON,
2528
IssueApiKeyRequestFromJSON,
2629
IssueApiKeyRequestToJSON,
2730
IssueApiKeyResponseFromJSON,
@@ -41,9 +44,9 @@ export interface AuthControllerCreateAccountRequestRequest {
4144
}
4245

4346
export interface AuthControllerCreateApiKeyRequest {
44-
xUserPassword: string;
45-
xUserEmail: string;
4647
issueApiKeyRequest: IssueApiKeyRequest;
48+
xUserPassword?: string;
49+
xUserEmail?: string;
4750
}
4851

4952
export interface AuthControllerDeleteAccountRequestRequest {
@@ -52,15 +55,25 @@ export interface AuthControllerDeleteAccountRequestRequest {
5255
xUserEmail: string;
5356
}
5457

55-
export interface AuthControllerDeleteApiKeyRequest {
56-
authorization: string;
58+
export interface AuthControllerDeleteApiKeyByIdRequest {
59+
id: string;
60+
xUserJwt?: string;
61+
xUserPassword?: string;
62+
xUserEmail?: string;
5763
}
5864

5965
export interface AuthControllerGetAllAccountRequestsRequest {
6066
xUserPassword: string;
6167
xUserEmail: string;
6268
}
6369

70+
export interface AuthControllerGetAllApiKeysRequest {
71+
offset?: number;
72+
limit?: number;
73+
xUserPassword?: string;
74+
xUserEmail?: string;
75+
}
76+
6477
export interface AuthControllerGetApiKeyJWTRequest {
6578
authorization: string;
6679
}
@@ -139,20 +152,6 @@ export class AuthApi extends runtime.BaseAPI {
139152
requestParameters: AuthControllerCreateApiKeyRequest,
140153
initOverrides?: RequestInit | runtime.InitOverrideFunction
141154
): Promise<runtime.ApiResponse<IssueApiKeyResponse>> {
142-
if (requestParameters['xUserPassword'] == null) {
143-
throw new runtime.RequiredError(
144-
'xUserPassword',
145-
'Required parameter "xUserPassword" was null or undefined when calling authControllerCreateApiKey().'
146-
);
147-
}
148-
149-
if (requestParameters['xUserEmail'] == null) {
150-
throw new runtime.RequiredError(
151-
'xUserEmail',
152-
'Required parameter "xUserEmail" was null or undefined when calling authControllerCreateApiKey().'
153-
);
154-
}
155-
156155
if (requestParameters['issueApiKeyRequest'] == null) {
157156
throw new runtime.RequiredError(
158157
'issueApiKeyRequest',
@@ -295,26 +294,36 @@ export class AuthApi extends runtime.BaseAPI {
295294
}
296295

297296
/**
298-
* Deletes an API key, detaching it from its project.
297+
* Revokes an API key, detaching it from its project.
299298
*/
300-
async authControllerDeleteApiKeyRaw(
301-
requestParameters: AuthControllerDeleteApiKeyRequest,
299+
async authControllerDeleteApiKeyByIdRaw(
300+
requestParameters: AuthControllerDeleteApiKeyByIdRequest,
302301
initOverrides?: RequestInit | runtime.InitOverrideFunction
303302
): Promise<runtime.ApiResponse<void>> {
304-
if (requestParameters['authorization'] == null) {
303+
if (requestParameters['id'] == null) {
305304
throw new runtime.RequiredError(
306-
'authorization',
307-
'Required parameter "authorization" was null or undefined when calling authControllerDeleteApiKey().'
305+
'id',
306+
'Required parameter "id" was null or undefined when calling authControllerDeleteApiKeyById().'
308307
);
309308
}
310309

311310
const queryParameters: any = {};
312311

313312
const headerParameters: runtime.HTTPHeaders = {};
314313

315-
if (requestParameters['authorization'] != null) {
316-
headerParameters['Authorization'] = String(
317-
requestParameters['authorization']
314+
if (requestParameters['xUserJwt'] != null) {
315+
headerParameters['x-user-jwt'] = String(requestParameters['xUserJwt']);
316+
}
317+
318+
if (requestParameters['xUserPassword'] != null) {
319+
headerParameters['X-User-Password'] = String(
320+
requestParameters['xUserPassword']
321+
);
322+
}
323+
324+
if (requestParameters['xUserEmail'] != null) {
325+
headerParameters['X-User-Email'] = String(
326+
requestParameters['xUserEmail']
318327
);
319328
}
320329

@@ -328,7 +337,10 @@ export class AuthApi extends runtime.BaseAPI {
328337
}
329338
const response = await this.request(
330339
{
331-
path: `/auth/key`,
340+
path: `/auth/key/{id}`.replace(
341+
`{${'id'}}`,
342+
encodeURIComponent(String(requestParameters['id']))
343+
),
332344
method: 'DELETE',
333345
headers: headerParameters,
334346
query: queryParameters,
@@ -340,13 +352,16 @@ export class AuthApi extends runtime.BaseAPI {
340352
}
341353

342354
/**
343-
* Deletes an API key, detaching it from its project.
355+
* Revokes an API key, detaching it from its project.
344356
*/
345-
async authControllerDeleteApiKey(
346-
requestParameters: AuthControllerDeleteApiKeyRequest,
357+
async authControllerDeleteApiKeyById(
358+
requestParameters: AuthControllerDeleteApiKeyByIdRequest,
347359
initOverrides?: RequestInit | runtime.InitOverrideFunction
348360
): Promise<void> {
349-
await this.authControllerDeleteApiKeyRaw(requestParameters, initOverrides);
361+
await this.authControllerDeleteApiKeyByIdRaw(
362+
requestParameters,
363+
initOverrides
364+
);
350365
}
351366

352367
/**
@@ -425,6 +440,66 @@ export class AuthApi extends runtime.BaseAPI {
425440
return await response.value();
426441
}
427442

443+
/**
444+
* Lists all API keys
445+
*/
446+
async authControllerGetAllApiKeysRaw(
447+
requestParameters: AuthControllerGetAllApiKeysRequest,
448+
initOverrides?: RequestInit | runtime.InitOverrideFunction
449+
): Promise<runtime.ApiResponse<GetAllApiKeysResponse>> {
450+
const queryParameters: any = {};
451+
452+
if (requestParameters['offset'] != null) {
453+
queryParameters['offset'] = requestParameters['offset'];
454+
}
455+
456+
if (requestParameters['limit'] != null) {
457+
queryParameters['limit'] = requestParameters['limit'];
458+
}
459+
460+
const headerParameters: runtime.HTTPHeaders = {};
461+
462+
if (requestParameters['xUserPassword'] != null) {
463+
headerParameters['X-User-Password'] = String(
464+
requestParameters['xUserPassword']
465+
);
466+
}
467+
468+
if (requestParameters['xUserEmail'] != null) {
469+
headerParameters['X-User-Email'] = String(
470+
requestParameters['xUserEmail']
471+
);
472+
}
473+
474+
const response = await this.request(
475+
{
476+
path: `/auth/key/all`,
477+
method: 'GET',
478+
headers: headerParameters,
479+
query: queryParameters,
480+
},
481+
initOverrides
482+
);
483+
484+
return new runtime.JSONApiResponse(response, (jsonValue) =>
485+
GetAllApiKeysResponseFromJSON(jsonValue)
486+
);
487+
}
488+
489+
/**
490+
* Lists all API keys
491+
*/
492+
async authControllerGetAllApiKeys(
493+
requestParameters: AuthControllerGetAllApiKeysRequest = {},
494+
initOverrides?: RequestInit | runtime.InitOverrideFunction
495+
): Promise<GetAllApiKeysResponse> {
496+
const response = await this.authControllerGetAllApiKeysRaw(
497+
requestParameters,
498+
initOverrides
499+
);
500+
return await response.value();
501+
}
502+
428503
/**
429504
* JSON Web Tokens are used for the vast majority of API-gateway calls. The Juno SDK provides the means of automatically authenticating through this route given a valid API key.
430505
* Generates a temporary JWT for the project tied to a specified API key.
@@ -489,7 +564,7 @@ export class AuthApi extends runtime.BaseAPI {
489564
}
490565

491566
/**
492-
* JSON Web Tokens are used for the vast majority of API-gateway calls. The Juno SDK provides the means of automatically authenticating through this route given valid user credentials.
567+
* Generates a user identity token that can be used to authenticate admin and management endpoints in place of email/password credentials.
493568
* Generates a temporary JWT tied to a specified user.
494569
*/
495570
async authControllerGetUserJWTRaw(
@@ -550,7 +625,7 @@ export class AuthApi extends runtime.BaseAPI {
550625
}
551626

552627
/**
553-
* JSON Web Tokens are used for the vast majority of API-gateway calls. The Juno SDK provides the means of automatically authenticating through this route given valid user credentials.
628+
* Generates a user identity token that can be used to authenticate admin and management endpoints in place of email/password credentials.
554629
* Generates a temporary JWT tied to a specified user.
555630
*/
556631
async authControllerGetUserJWT(

‎src/internal/apis/index.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ export * from './FileDownloadApi';
1111
export * from './FileProviderApi';
1212
export * from './FileUploadApi';
1313
export * from './ProjectApi';
14+
1415
export * from './UserApi';

‎src/internal/models/ApiKey.ts‎

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
/* tslint:disable */
2+
/* eslint-disable */
3+
/**
4+
* Juno
5+
* Juno Public API Docs
6+
*
7+
* The version of the OpenAPI document: 1.0
8+
*
9+
*
10+
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
11+
* https://openapi-generator.tech
12+
* Do not edit the class manually.
13+
*/
14+
15+
import { mapValues } from '../runtime';
16+
/**
17+
*
18+
* @export
19+
* @interface ApiKey
20+
*/
21+
export interface ApiKey {
22+
/**
23+
* The API key's ID in the databse
24+
* @type {string}
25+
* @memberof ApiKey
26+
*/
27+
id: string;
28+
/**
29+
* The generated API key value (store immediately, not retrievable again)
30+
* @type {string}
31+
* @memberof ApiKey
32+
*/
33+
hash: string;
34+
/**
35+
* Description provided at creation
36+
* @type {string}
37+
* @memberof ApiKey
38+
*/
39+
description: string;
40+
/**
41+
* Scopes tied to this API key
42+
* @type {Array<string>}
43+
* @memberof ApiKey
44+
*/
45+
scopes: Array<string>;
46+
/**
47+
* project identifier for the API key
48+
* @type {string}
49+
* @memberof ApiKey
50+
*/
51+
project: string;
52+
/**
53+
* Environment this key was issued for
54+
* @type {string}
55+
* @memberof ApiKey
56+
*/
57+
environment: string;
58+
/**
59+
* ISO timestamp of key creation
60+
* @type {string}
61+
* @memberof ApiKey
62+
*/
63+
createdAt: string;
64+
}
65+
66+
/**
67+
* Check if a given object implements the ApiKey interface.
68+
*/
69+
export function instanceOfApiKey(value: object): value is ApiKey {
70+
if (!('id' in value) || value['id'] === undefined) return false;
71+
if (!('hash' in value) || value['hash'] === undefined) return false;
72+
if (!('description' in value) || value['description'] === undefined)
73+
return false;
74+
if (!('scopes' in value) || value['scopes'] === undefined) return false;
75+
if (!('project' in value) || value['project'] === undefined) return false;
76+
if (!('environment' in value) || value['environment'] === undefined)
77+
return false;
78+
if (!('createdAt' in value) || value['createdAt'] === undefined) return false;
79+
return true;
80+
}
81+
82+
export function ApiKeyFromJSON(json: any): ApiKey {
83+
return ApiKeyFromJSONTyped(json, false);
84+
}
85+
86+
export function ApiKeyFromJSONTyped(
87+
json: any,
88+
ignoreDiscriminator: boolean
89+
): ApiKey {
90+
if (json == null) {
91+
return json;
92+
}
93+
return {
94+
id: json['id'],
95+
hash: json['hash'],
96+
description: json['description'],
97+
scopes: json['scopes'],
98+
project: json['project'],
99+
environment: json['environment'],
100+
createdAt: json['createdAt'],
101+
};
102+
}
103+
104+
export function ApiKeyToJSON(value?: ApiKey | null): any {
105+
if (value == null) {
106+
return value;
107+
}
108+
return {
109+
id: value['id'],
110+
hash: value['hash'],
111+
description: value['description'],
112+
scopes: value['scopes'],
113+
project: value['project'],
114+
environment: value['environment'],
115+
createdAt: value['createdAt'],
116+
};
117+
}

0 commit comments

Comments
 (0)