Skip to content

Commit f0edc96

Browse files
feat(api): manual updates
1 parent f50f5ad commit f0edc96

File tree

7 files changed

+255
-2
lines changed

7 files changed

+255
-2
lines changed

.stats.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
configured_endpoints: 115
1+
configured_endpoints: 116
22
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/gitpod%2Fgitpod-d854bc81e0a99171716893e6790a87ba350bb6fc778f8e3244abdd47d5c252c3.yml
33
openapi_spec_hash: 5189220e4712a7b0cdd35beba2ebb47d
4-
config_hash: 981e43e8b1e3ddabd435d350aeeed417
4+
config_hash: 60929489bdc1eaf979e7ef74fdd17b94

api.md

+10
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,16 @@ Methods:
484484
- <code title="post /gitpod.v1.SecretService/GetSecretValue">client.secrets.<a href="./src/resources/secrets.ts">getValue</a>({ ...params }) -> SecretGetValueResponse</code>
485485
- <code title="post /gitpod.v1.SecretService/UpdateSecretValue">client.secrets.<a href="./src/resources/secrets.ts">updateValue</a>({ ...params }) -> unknown</code>
486486

487+
# Usage
488+
489+
Types:
490+
491+
- <code><a href="./src/resources/usage.ts">EnvironmentSession</a></code>
492+
493+
Methods:
494+
495+
- <code title="post /gitpod.v1.UsageService/ListEnvironmentSessions">client.usage.<a href="./src/resources/usage.ts">listEnvironmentSessions</a>({ ...params }) -> EnvironmentSessionsSessionsPage</code>
496+
487497
# Users
488498

489499
Types:

src/client.ts

+20
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ import {
4949
SecretsPageResponse,
5050
type ServicesPageParams,
5151
ServicesPageResponse,
52+
type SessionsPageParams,
53+
SessionsPageResponse,
5254
type TaskExecutionsPageParams,
5355
TaskExecutionsPageResponse,
5456
type TasksPageParams,
@@ -123,6 +125,12 @@ import {
123125
Secrets,
124126
SecretsSecretsPage,
125127
} from './resources/secrets';
128+
import {
129+
EnvironmentSession,
130+
EnvironmentSessionsSessionsPage,
131+
Usage,
132+
UsageListEnvironmentSessionsParams,
133+
} from './resources/usage';
126134
import { readEnv } from './internal/utils/env';
127135
import { formatRequestDetails, loggerFor } from './internal/utils/log';
128136
import { isEmptyObj } from './internal/utils/values';
@@ -917,6 +925,7 @@ export class Gitpod {
917925
projects: API.Projects = new API.Projects(this);
918926
runners: API.Runners = new API.Runners(this);
919927
secrets: API.Secrets = new API.Secrets(this);
928+
usage: API.Usage = new API.Usage(this);
920929
users: API.Users = new API.Users(this);
921930
}
922931
Gitpod.Accounts = Accounts;
@@ -929,6 +938,7 @@ Gitpod.Organizations = Organizations;
929938
Gitpod.Projects = Projects;
930939
Gitpod.Runners = Runners;
931940
Gitpod.Secrets = Secrets;
941+
Gitpod.Usage = Usage;
932942
Gitpod.Users = Users;
933943
export declare namespace Gitpod {
934944
export type RequestOptions = Opts.RequestOptions;
@@ -996,6 +1006,9 @@ export declare namespace Gitpod {
9961006
export import ServicesPage = Pagination.ServicesPage;
9971007
export { type ServicesPageParams as ServicesPageParams, type ServicesPageResponse as ServicesPageResponse };
9981008

1009+
export import SessionsPage = Pagination.SessionsPage;
1010+
export { type SessionsPageParams as SessionsPageParams, type SessionsPageResponse as SessionsPageResponse };
1011+
9991012
export import SSOConfigurationsPage = Pagination.SSOConfigurationsPage;
10001013
export {
10011014
type SSOConfigurationsPageParams as SSOConfigurationsPageParams,
@@ -1194,6 +1207,13 @@ export declare namespace Gitpod {
11941207
type SecretUpdateValueParams as SecretUpdateValueParams,
11951208
};
11961209

1210+
export {
1211+
Usage as Usage,
1212+
type EnvironmentSession as EnvironmentSession,
1213+
type EnvironmentSessionsSessionsPage as EnvironmentSessionsSessionsPage,
1214+
type UsageListEnvironmentSessionsParams as UsageListEnvironmentSessionsParams,
1215+
};
1216+
11971217
export {
11981218
Users as Users,
11991219
type User as User,

src/core/pagination.ts

+55
Original file line numberDiff line numberDiff line change
@@ -941,6 +941,61 @@ export class ServicesPage<Item> extends AbstractPage<Item> implements ServicesPa
941941
}
942942
}
943943

944+
export interface SessionsPageResponse<Item> {
945+
pagination: SessionsPageResponse.Pagination;
946+
947+
sessions: Array<Item>;
948+
}
949+
950+
export namespace SessionsPageResponse {
951+
export interface Pagination {
952+
nextToken?: string;
953+
}
954+
}
955+
956+
export interface SessionsPageParams {
957+
pageSize?: number;
958+
959+
token?: string;
960+
}
961+
962+
export class SessionsPage<Item> extends AbstractPage<Item> implements SessionsPageResponse<Item> {
963+
pagination: SessionsPageResponse.Pagination;
964+
965+
sessions: Array<Item>;
966+
967+
constructor(
968+
client: Gitpod,
969+
response: Response,
970+
body: SessionsPageResponse<Item>,
971+
options: FinalRequestOptions,
972+
) {
973+
super(client, response, body, options);
974+
975+
this.pagination = body.pagination || {};
976+
this.sessions = body.sessions || [];
977+
}
978+
979+
getPaginatedItems(): Item[] {
980+
return this.sessions ?? [];
981+
}
982+
983+
nextPageRequestOptions(): PageRequestOptions | null {
984+
const cursor = this.pagination?.nextToken;
985+
if (!cursor) {
986+
return null;
987+
}
988+
989+
return {
990+
...this.options,
991+
query: {
992+
...maybeObj(this.options.query),
993+
token: cursor,
994+
},
995+
};
996+
}
997+
}
998+
944999
export interface SSOConfigurationsPageResponse<Item> {
9451000
pagination: SSOConfigurationsPageResponse.Pagination;
9461001

src/resources/index.ts

+6
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,12 @@ export {
166166
type SecretUpdateValueParams,
167167
type SecretsSecretsPage,
168168
} from './secrets';
169+
export {
170+
Usage,
171+
type EnvironmentSession,
172+
type UsageListEnvironmentSessionsParams,
173+
type EnvironmentSessionsSessionsPage,
174+
} from './usage';
169175
export {
170176
Users,
171177
type User,

src/resources/usage.ts

+140
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2+
3+
import { APIResource } from '../core/resource';
4+
import { PagePromise, SessionsPage, type SessionsPageParams } from '../core/pagination';
5+
import { RequestOptions } from '../internal/request-options';
6+
7+
export class Usage extends APIResource {
8+
/**
9+
* Lists environment sessions within a specified date range.
10+
*
11+
* Returns a list of environment sessions that were active within the specified
12+
* date range.
13+
*/
14+
listEnvironmentSessions(
15+
params: UsageListEnvironmentSessionsParams,
16+
options?: RequestOptions,
17+
): PagePromise<EnvironmentSessionsSessionsPage, EnvironmentSession> {
18+
const { token, pageSize, ...body } = params;
19+
return this._client.getAPIList(
20+
'/gitpod.v1.UsageService/ListEnvironmentSessions',
21+
SessionsPage<EnvironmentSession>,
22+
{ query: { token, pageSize }, body, method: 'post', ...options },
23+
);
24+
}
25+
}
26+
27+
export type EnvironmentSessionsSessionsPage = SessionsPage<EnvironmentSession>;
28+
29+
export interface EnvironmentSession {
30+
/**
31+
* Environment session ID.
32+
*/
33+
id?: string;
34+
35+
/**
36+
* Time when the session was created.
37+
*/
38+
createdAt?: string;
39+
40+
/**
41+
* Environment class ID associated with the session.
42+
*/
43+
environmentClassId?: string;
44+
45+
/**
46+
* Environment ID associated with the session.
47+
*/
48+
environmentId?: string;
49+
50+
/**
51+
* Project ID associated with the session.
52+
*/
53+
projectId?: string;
54+
55+
/**
56+
* Runner ID associated with the session.
57+
*/
58+
runnerId?: string;
59+
60+
/**
61+
* Time when the session was stopped.
62+
*/
63+
stoppedAt?: string;
64+
65+
/**
66+
* User ID who created the session.
67+
*/
68+
userId?: string;
69+
}
70+
71+
export interface UsageListEnvironmentSessionsParams extends SessionsPageParams {
72+
/**
73+
* Body param: Filter options.
74+
*/
75+
filter?: UsageListEnvironmentSessionsParams.Filter;
76+
77+
/**
78+
* Body param: Pagination options.
79+
*/
80+
pagination?: UsageListEnvironmentSessionsParams.Pagination;
81+
}
82+
83+
export namespace UsageListEnvironmentSessionsParams {
84+
/**
85+
* Filter options.
86+
*/
87+
export interface Filter {
88+
/**
89+
* Date range to query sessions within.
90+
*/
91+
dateRange: Filter.DateRange;
92+
93+
/**
94+
* Optional project ID to filter sessions by.
95+
*/
96+
projectId?: string;
97+
}
98+
99+
export namespace Filter {
100+
/**
101+
* Date range to query sessions within.
102+
*/
103+
export interface DateRange {
104+
/**
105+
* End time of the date range (exclusive).
106+
*/
107+
endTime: string;
108+
109+
/**
110+
* Start time of the date range (inclusive).
111+
*/
112+
startTime: string;
113+
}
114+
}
115+
116+
/**
117+
* Pagination options.
118+
*/
119+
export interface Pagination {
120+
/**
121+
* Token for the next set of results that was returned as next_token of a
122+
* PaginationResponse
123+
*/
124+
token?: string;
125+
126+
/**
127+
* Page size is the maximum number of results to retrieve per page. Defaults to 25.
128+
* Maximum 100.
129+
*/
130+
pageSize?: number;
131+
}
132+
}
133+
134+
export declare namespace Usage {
135+
export {
136+
type EnvironmentSession as EnvironmentSession,
137+
type EnvironmentSessionsSessionsPage as EnvironmentSessionsSessionsPage,
138+
type UsageListEnvironmentSessionsParams as UsageListEnvironmentSessionsParams,
139+
};
140+
}

tests/api-resources/usage.test.ts

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2+
3+
import Gitpod from '@gitpod/sdk';
4+
5+
const client = new Gitpod({
6+
bearerToken: 'My Bearer Token',
7+
baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',
8+
});
9+
10+
describe('resource usage', () => {
11+
// skipped: tests are disabled for the time being
12+
test.skip('listEnvironmentSessions', async () => {
13+
const responsePromise = client.usage.listEnvironmentSessions({});
14+
const rawResponse = await responsePromise.asResponse();
15+
expect(rawResponse).toBeInstanceOf(Response);
16+
const response = await responsePromise;
17+
expect(response).not.toBeInstanceOf(Response);
18+
const dataAndResponse = await responsePromise.withResponse();
19+
expect(dataAndResponse.data).toBe(response);
20+
expect(dataAndResponse.response).toBe(rawResponse);
21+
});
22+
});

0 commit comments

Comments
 (0)