diff --git a/.stats.yml b/.stats.yml index 254000e633..f6163818d6 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,2 +1,2 @@ configured_endpoints: 1343 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/cloudflare%2Fcloudflare-6545c93a16062d2763cd304367d8babf5aaef09046036361dbb077b75536e858.yml +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/cloudflare%2Fcloudflare-f1ab7e5d073ef27b0e08bd9fd83e406c15c1c69017c29b17dadceec459febd7b.yml diff --git a/src/core.ts b/src/core.ts index 5f985a0a71..2a6ff76440 100644 --- a/src/core.ts +++ b/src/core.ts @@ -18,7 +18,7 @@ import { type HeadersInit, } from './_shims/index'; export { type Response }; -import { isMultipartBody } from './uploads'; +import { BlobLike, isBlobLike, isMultipartBody } from './uploads'; export { maybeMultipartFormRequestOptions, multipartFormRequestOptions, @@ -235,7 +235,17 @@ export abstract class APIClient { path: string, opts?: PromiseOrValue>, ): APIPromise { - return this.request(Promise.resolve(opts).then((opts) => ({ method, path, ...opts }))); + return this.request( + Promise.resolve(opts).then(async (opts) => { + const body = + opts && isBlobLike(opts?.body) ? new DataView(await opts.body.arrayBuffer()) + : opts?.body instanceof DataView ? opts.body + : opts?.body instanceof ArrayBuffer ? new DataView(opts.body) + : opts && ArrayBuffer.isView(opts?.body) ? new DataView(opts.body.buffer) + : opts?.body; + return { method, path, ...opts, body }; + }), + ); } getAPIList = AbstractPage>( @@ -257,6 +267,8 @@ export abstract class APIClient { const encoded = encoder.encode(body); return encoded.length.toString(); } + } else if (ArrayBuffer.isView(body)) { + return body.byteLength.toString(); } return null; @@ -266,7 +278,9 @@ export abstract class APIClient { const { method, path, query, headers: headers = {} } = options; const body = - isMultipartBody(options.body) ? options.body.body + ArrayBuffer.isView(options.body) || (options.__binaryRequest && typeof options.body === 'string') ? + options.body + : isMultipartBody(options.body) ? options.body.body : options.body ? JSON.stringify(options.body, null, 2) : null; const contentLength = this.calculateContentLength(body); @@ -721,7 +735,9 @@ export type Headers = Record; export type DefaultQuery = Record; export type KeysEnum = { [P in keyof Required]: true }; -export type RequestOptions | Readable> = { +export type RequestOptions< + Req = unknown | Record | Readable | BlobLike | ArrayBufferView | ArrayBuffer, +> = { method?: HTTPMethod; path?: string; query?: Req | undefined; @@ -735,6 +751,7 @@ export type RequestOptions | Readable> = signal?: AbortSignal | undefined | null; idempotencyKey?: string; + __binaryRequest?: boolean | undefined; __binaryResponse?: boolean | undefined; }; @@ -755,6 +772,7 @@ const requestOptionsKeys: KeysEnum = { signal: true, idempotencyKey: true, + __binaryRequest: true, __binaryResponse: true, }; @@ -767,10 +785,11 @@ export const isRequestOptions = (obj: unknown): obj is RequestOptions => { ); }; -export type FinalRequestOptions | Readable> = RequestOptions & { - method: HTTPMethod; - path: string; -}; +export type FinalRequestOptions | Readable | DataView> = + RequestOptions & { + method: HTTPMethod; + path: string; + }; declare const Deno: any; declare const EdgeRuntime: any; diff --git a/src/resources/vectorize/indexes.ts b/src/resources/vectorize/indexes.ts index 011c123f3a..5280edd431 100644 --- a/src/resources/vectorize/indexes.ts +++ b/src/resources/vectorize/indexes.ts @@ -133,6 +133,8 @@ export class Indexes extends APIResource { this._client.post(`/accounts/${account_id}/vectorize/indexes/${indexName}/insert`, { body: body, ...options, + headers: { 'Content-Type': 'application/x-ndjson', ...options?.headers }, + __binaryRequest: true, }) as Core.APIPromise<{ result: IndexInsert | null }> )._thenUnwrap((obj) => obj.result); } @@ -168,6 +170,8 @@ export class Indexes extends APIResource { this._client.post(`/accounts/${account_id}/vectorize/indexes/${indexName}/upsert`, { body: body, ...options, + headers: { 'Content-Type': 'application/x-ndjson', ...options?.headers }, + __binaryRequest: true, }) as Core.APIPromise<{ result: IndexUpsert | null }> )._thenUnwrap((obj) => obj.result); } diff --git a/src/resources/workers-for-platforms/dispatch/namespaces/scripts/scripts.ts b/src/resources/workers-for-platforms/dispatch/namespaces/scripts/scripts.ts index ce5a325abf..f05cadf5f8 100644 --- a/src/resources/workers-for-platforms/dispatch/namespaces/scripts/scripts.ts +++ b/src/resources/workers-for-platforms/dispatch/namespaces/scripts/scripts.ts @@ -35,7 +35,11 @@ export class Scripts extends APIResource { return ( this._client.put( `/accounts/${account_id}/workers/dispatch/namespaces/${dispatchNamespace}/scripts/${scriptName}`, - maybeMultipartFormRequestOptions({ body, ...options }), + maybeMultipartFormRequestOptions({ + body, + ...options, + headers: { 'Content-Type': 'application/javascript', ...options?.headers }, + }), ) as Core.APIPromise<{ result: ScriptsAPI.Script }> )._thenUnwrap((obj) => obj.result); } diff --git a/src/resources/workers/scripts/scripts.ts b/src/resources/workers/scripts/scripts.ts index 90558b0639..96c0a9d180 100644 --- a/src/resources/workers/scripts/scripts.ts +++ b/src/resources/workers/scripts/scripts.ts @@ -34,7 +34,12 @@ export class Scripts extends APIResource { return ( this._client.put( `/accounts/${account_id}/workers/scripts/${scriptName}`, - maybeMultipartFormRequestOptions({ query: { rollback_to }, body, ...options }), + maybeMultipartFormRequestOptions({ + query: { rollback_to }, + body, + ...options, + headers: { 'Content-Type': 'application/javascript', ...options?.headers }, + }), ) as Core.APIPromise<{ result: Script }> )._thenUnwrap((obj) => obj.result); } diff --git a/src/resources/zero-trust/dlp/datasets/upload.ts b/src/resources/zero-trust/dlp/datasets/upload.ts index 2391176d95..f631048af2 100644 --- a/src/resources/zero-trust/dlp/datasets/upload.ts +++ b/src/resources/zero-trust/dlp/datasets/upload.ts @@ -37,6 +37,8 @@ export class Upload extends APIResource { this._client.post(`/accounts/${account_id}/dlp/datasets/${datasetId}/upload/${version}`, { body: body, ...options, + headers: { 'Content-Type': 'application/octet-stream', ...options?.headers }, + __binaryRequest: true, }) as Core.APIPromise<{ result: DatasetsAPI.Dataset }> )._thenUnwrap((obj) => obj.result); } @@ -63,7 +65,7 @@ export interface UploadEditParams { /** * Body param: */ - body: unknown; + body: string; } export namespace Upload { diff --git a/tests/api-resources/zero-trust/dlp/datasets/upload.test.ts b/tests/api-resources/zero-trust/dlp/datasets/upload.test.ts index 83bb67cbc8..286907836d 100644 --- a/tests/api-resources/zero-trust/dlp/datasets/upload.test.ts +++ b/tests/api-resources/zero-trust/dlp/datasets/upload.test.ts @@ -36,7 +36,7 @@ describe('resource upload', () => { const responsePromise = cloudflare.zeroTrust.dlp.datasets.upload.edit( '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', 0, - { account_id: 'string', body: {} }, + { account_id: 'string', body: 'string' }, ); const rawResponse = await responsePromise.asResponse(); expect(rawResponse).toBeInstanceOf(Response); @@ -52,7 +52,7 @@ describe('resource upload', () => { const response = await cloudflare.zeroTrust.dlp.datasets.upload.edit( '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', 0, - { account_id: 'string', body: {} }, + { account_id: 'string', body: 'string' }, ); }); });