Skip to content

Commit df67fdd

Browse files
feat: api: paginate GET /extensions
1 parent 694525a commit df67fdd

6 files changed

Lines changed: 59 additions & 33 deletions

File tree

.stats.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
configured_endpoints: 117
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/kernel/kernel-e5524e6eeeedc614c05bf19896f1ce6c4f8a113de85c02952d6874d579651f70.yml
3-
openapi_spec_hash: 7815a189a50e6aa9e283213cc78d041c
4-
config_hash: 453b25a35834fd59a55a2315d1d50746
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/kernel/kernel-9a76e7a837ac9ffbe0e9557d618ce9b676e052249e364e516c28ddb33b912019.yml
3+
openapi_spec_hash: c0e5412cc95139f11a8b8635559bb985
4+
config_hash: 098a7f3fd134c8e4cbd3a44750892a18

api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ Types:
296296

297297
Methods:
298298

299-
- <code title="get /extensions">client.extensions.<a href="./src/resources/extensions.ts">list</a>() -> ExtensionListResponse</code>
299+
- <code title="get /extensions">client.extensions.<a href="./src/resources/extensions.ts">list</a>({ ...params }) -> ExtensionListResponsesOffsetPagination</code>
300300
- <code title="delete /extensions/{id_or_name}">client.extensions.<a href="./src/resources/extensions.ts">delete</a>(idOrName) -> void</code>
301301
- <code title="get /extensions/{id_or_name}">client.extensions.<a href="./src/resources/extensions.ts">download</a>(idOrName) -> Response</code>
302302
- <code title="get /extensions/from_chrome_store">client.extensions.<a href="./src/resources/extensions.ts">downloadFromChromeStore</a>({ ...params }) -> Response</code>

src/client.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,9 @@ import {
8484
import { KernelApp } from './core/app-framework';
8585
import {
8686
ExtensionDownloadFromChromeStoreParams,
87+
ExtensionListParams,
8788
ExtensionListResponse,
89+
ExtensionListResponsesOffsetPagination,
8890
ExtensionUploadParams,
8991
ExtensionUploadResponse,
9092
Extensions,
@@ -1094,6 +1096,8 @@ export declare namespace Kernel {
10941096
Extensions as Extensions,
10951097
type ExtensionListResponse as ExtensionListResponse,
10961098
type ExtensionUploadResponse as ExtensionUploadResponse,
1099+
type ExtensionListResponsesOffsetPagination as ExtensionListResponsesOffsetPagination,
1100+
type ExtensionListParams as ExtensionListParams,
10971101
type ExtensionDownloadFromChromeStoreParams as ExtensionDownloadFromChromeStoreParams,
10981102
type ExtensionUploadParams as ExtensionUploadParams,
10991103
};

src/resources/extensions.ts

Lines changed: 41 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import { APIResource } from '../core/resource';
44
import { APIPromise } from '../core/api-promise';
5+
import { OffsetPagination, type OffsetPaginationParams, PagePromise } from '../core/pagination';
56
import { type Uploadable } from '../core/uploads';
67
import { buildHeaders } from '../internal/headers';
78
import { RequestOptions } from '../internal/request-options';
@@ -17,11 +18,20 @@ export class Extensions extends APIResource {
1718
*
1819
* @example
1920
* ```ts
20-
* const extensions = await client.extensions.list();
21+
* // Automatically fetches more pages as needed.
22+
* for await (const extensionListResponse of client.extensions.list()) {
23+
* // ...
24+
* }
2125
* ```
2226
*/
23-
list(options?: RequestOptions): APIPromise<ExtensionListResponse> {
24-
return this._client.get('/extensions', options);
27+
list(
28+
query: ExtensionListParams | null | undefined = {},
29+
options?: RequestOptions,
30+
): PagePromise<ExtensionListResponsesOffsetPagination, ExtensionListResponse> {
31+
return this._client.getAPIList('/extensions', OffsetPagination<ExtensionListResponse>, {
32+
query,
33+
...options,
34+
});
2535
}
2636

2737
/**
@@ -103,39 +113,37 @@ export class Extensions extends APIResource {
103113
}
104114
}
105115

106-
export type ExtensionListResponse = Array<ExtensionListResponse.ExtensionListResponseItem>;
116+
export type ExtensionListResponsesOffsetPagination = OffsetPagination<ExtensionListResponse>;
107117

108-
export namespace ExtensionListResponse {
118+
/**
119+
* A browser extension uploaded to Kernel.
120+
*/
121+
export interface ExtensionListResponse {
109122
/**
110-
* A browser extension uploaded to Kernel.
123+
* Unique identifier for the extension
111124
*/
112-
export interface ExtensionListResponseItem {
113-
/**
114-
* Unique identifier for the extension
115-
*/
116-
id: string;
125+
id: string;
117126

118-
/**
119-
* Timestamp when the extension was created
120-
*/
121-
created_at: string;
127+
/**
128+
* Timestamp when the extension was created
129+
*/
130+
created_at: string;
122131

123-
/**
124-
* Size of the extension archive in bytes
125-
*/
126-
size_bytes: number;
132+
/**
133+
* Size of the extension archive in bytes
134+
*/
135+
size_bytes: number;
127136

128-
/**
129-
* Timestamp when the extension was last used
130-
*/
131-
last_used_at?: string | null;
137+
/**
138+
* Timestamp when the extension was last used
139+
*/
140+
last_used_at?: string | null;
132141

133-
/**
134-
* Optional, easier-to-reference name for the extension. Must be unique within the
135-
* project.
136-
*/
137-
name?: string | null;
138-
}
142+
/**
143+
* Optional, easier-to-reference name for the extension. Must be unique within the
144+
* project.
145+
*/
146+
name?: string | null;
139147
}
140148

141149
/**
@@ -169,6 +177,8 @@ export interface ExtensionUploadResponse {
169177
name?: string | null;
170178
}
171179

180+
export interface ExtensionListParams extends OffsetPaginationParams {}
181+
172182
export interface ExtensionDownloadFromChromeStoreParams {
173183
/**
174184
* Chrome Web Store URL for the extension.
@@ -197,6 +207,8 @@ export declare namespace Extensions {
197207
export {
198208
type ExtensionListResponse as ExtensionListResponse,
199209
type ExtensionUploadResponse as ExtensionUploadResponse,
210+
type ExtensionListResponsesOffsetPagination as ExtensionListResponsesOffsetPagination,
211+
type ExtensionListParams as ExtensionListParams,
200212
type ExtensionDownloadFromChromeStoreParams as ExtensionDownloadFromChromeStoreParams,
201213
type ExtensionUploadParams as ExtensionUploadParams,
202214
};

src/resources/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,10 @@ export {
8787
Extensions,
8888
type ExtensionListResponse,
8989
type ExtensionUploadResponse,
90+
type ExtensionListParams,
9091
type ExtensionDownloadFromChromeStoreParams,
9192
type ExtensionUploadParams,
93+
type ExtensionListResponsesOffsetPagination,
9294
} from './extensions';
9395
export {
9496
Invocations,

tests/api-resources/extensions.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@ describe('resource extensions', () => {
2020
expect(dataAndResponse.response).toBe(rawResponse);
2121
});
2222

23+
// Mock server tests are disabled
24+
test.skip('list: request options and params are passed correctly', async () => {
25+
// ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error
26+
await expect(
27+
client.extensions.list({ limit: 1, offset: 0 }, { path: '/_stainless_unknown_path' }),
28+
).rejects.toThrow(Kernel.NotFoundError);
29+
});
30+
2331
// Mock server tests are disabled
2432
test.skip('delete', async () => {
2533
const responsePromise = client.extensions.delete('id_or_name');

0 commit comments

Comments
 (0)