Skip to content

Commit 025572d

Browse files
stainless-app[bot]meorphis
authored andcommitted
feat(api): api update (#2124)
1 parent 9911931 commit 025572d

File tree

6 files changed

+111
-6
lines changed

6 files changed

+111
-6
lines changed

.stats.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
configured_endpoints: 1416
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/cloudflare%2Fcloudflare-3f87896b62cce36e33c03f416ad98add2717ccd78f1743925c160a6c6a67ff15.yml
1+
configured_endpoints: 1417
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/cloudflare%2Fcloudflare-4396f2b615f2349cc28c23e9df6cf66c1c0fd8257d18df0ce54d7e74c839bf9f.yml

api.md

+8
Original file line numberDiff line numberDiff line change
@@ -2003,6 +2003,14 @@ Methods:
20032003

20042004
#### Upload
20052005

2006+
Types:
2007+
2008+
- <code><a href="./src/resources/workers/scripts/assets/upload.ts">UploadCreateResponse</a></code>
2009+
2010+
Methods:
2011+
2012+
- <code title="post /accounts/{account_id}/workers/scripts/{script_name}/assets-upload-session">client.workers.scripts.assets.upload.<a href="./src/resources/workers/scripts/assets/upload.ts">create</a>(scriptName, { ...params }) -> UploadCreateResponse</code>
2013+
20062014
### Subdomain
20072015

20082016
Types:

src/resources/workers/scripts/assets/assets.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import { APIResource } from '../../../../resource';
44
import * as UploadAPI from './upload';
5-
import { Upload } from './upload';
5+
import { Upload, UploadCreateParams, UploadCreateResponse } from './upload';
66

77
export class Assets extends APIResource {
88
upload: UploadAPI.Upload = new UploadAPI.Upload(this._client);
@@ -11,5 +11,9 @@ export class Assets extends APIResource {
1111
Assets.Upload = Upload;
1212

1313
export declare namespace Assets {
14-
export { Upload as Upload };
14+
export {
15+
Upload as Upload,
16+
type UploadCreateResponse as UploadCreateResponse,
17+
type UploadCreateParams as UploadCreateParams,
18+
};
1519
}
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
22

33
export { Assets } from './assets';
4-
export { Upload } from './upload';
4+
export { Upload, type UploadCreateResponse, type UploadCreateParams } from './upload';
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,66 @@
11
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
22

33
import { APIResource } from '../../../../resource';
4+
import * as Core from '../../../../core';
45

5-
export class Upload extends APIResource {}
6+
export class Upload extends APIResource {
7+
/**
8+
* Start uploading a collection of assets for use in a Worker version.
9+
*/
10+
create(
11+
scriptName: string,
12+
params: UploadCreateParams,
13+
options?: Core.RequestOptions,
14+
): Core.APIPromise<UploadCreateResponse> {
15+
const { account_id, ...body } = params;
16+
return (
17+
this._client.post(`/accounts/${account_id}/workers/scripts/${scriptName}/assets-upload-session`, {
18+
body,
19+
...options,
20+
}) as Core.APIPromise<{ result: UploadCreateResponse }>
21+
)._thenUnwrap((obj) => obj.result);
22+
}
23+
}
24+
25+
export interface UploadCreateResponse {
26+
/**
27+
* The requests to make to upload assets.
28+
*/
29+
buckets?: Array<Array<string>>;
30+
31+
/**
32+
* A JWT to use as authentication for uploading assets.
33+
*/
34+
jwt?: string;
35+
}
36+
37+
export interface UploadCreateParams {
38+
/**
39+
* Path param: Identifier
40+
*/
41+
account_id: string;
42+
43+
/**
44+
* Body param: A manifest ([path]: {hash, size}) map of files to upload. As an
45+
* example, `/blog/hello-world.html` would be a valid path key.
46+
*/
47+
manifest?: Record<string, UploadCreateParams.Manifest>;
48+
}
49+
50+
export namespace UploadCreateParams {
51+
export interface Manifest {
52+
/**
53+
* The hash of the file.
54+
*/
55+
hash?: string;
56+
57+
/**
58+
* The size of the file in bytes.
59+
*/
60+
size?: number;
61+
}
62+
}
63+
64+
export declare namespace Upload {
65+
export { type UploadCreateResponse as UploadCreateResponse, type UploadCreateParams as UploadCreateParams };
66+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2+
3+
import Cloudflare from 'cloudflare';
4+
import { Response } from 'node-fetch';
5+
6+
const client = new Cloudflare({
7+
apiKey: '144c9defac04969c7bfad8efaa8ea194',
8+
apiEmail: '[email protected]',
9+
baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',
10+
});
11+
12+
describe('resource upload', () => {
13+
test('create: only required params', async () => {
14+
const responsePromise = client.workers.scripts.assets.upload.create('this-is_my_script-01', {
15+
account_id: '023e105f4ecef8ad9ca31a8372d0c353',
16+
});
17+
const rawResponse = await responsePromise.asResponse();
18+
expect(rawResponse).toBeInstanceOf(Response);
19+
const response = await responsePromise;
20+
expect(response).not.toBeInstanceOf(Response);
21+
const dataAndResponse = await responsePromise.withResponse();
22+
expect(dataAndResponse.data).toBe(response);
23+
expect(dataAndResponse.response).toBe(rawResponse);
24+
});
25+
26+
test('create: required and optional params', async () => {
27+
const response = await client.workers.scripts.assets.upload.create('this-is_my_script-01', {
28+
account_id: '023e105f4ecef8ad9ca31a8372d0c353',
29+
manifest: { foo: { hash: 'hash', size: 0 } },
30+
});
31+
});
32+
});

0 commit comments

Comments
 (0)