Comparing version 4.0.0-beta.5 to 4.0.0-beta.6
@@ -13,2 +13,2 @@ /** | ||
exports.isPolyfilled = true; | ||
exports.isPolyfilled = false; |
@@ -1,2 +0,1 @@ | ||
import * as qs from 'qs'; | ||
import { APIError } from './error.js'; | ||
@@ -48,11 +47,2 @@ import type { Readable } from 'openai/_shims/node-readable'; | ||
protected validateHeaders(headers: Headers, customHeaders: Headers): void; | ||
/** | ||
* Override this to add your own qs.stringify options, for example: | ||
* | ||
* { | ||
* ...super.qsOptions(), | ||
* strictNullHandling: true, | ||
* } | ||
*/ | ||
protected qsOptions(): qs.IStringifyOptions | undefined; | ||
protected defaultIdempotencyKey(): string; | ||
@@ -106,2 +96,3 @@ get<Req extends {}, Rsp>(path: string, opts?: RequestOptions<Req>): Promise<Rsp>; | ||
buildURL<Req>(path: string, query: Req | undefined): string; | ||
protected stringifyQuery(query: Record<string, unknown>): string; | ||
fetchWithTimeout( | ||
@@ -108,0 +99,0 @@ url: RequestInfo, |
78
core.js
'use strict'; | ||
var __createBinding = | ||
(this && this.__createBinding) || | ||
(Object.create ? | ||
function (o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ('get' in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { | ||
enumerable: true, | ||
get: function () { | ||
return m[k]; | ||
}, | ||
}; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
} | ||
: function (o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
}); | ||
var __setModuleDefault = | ||
(this && this.__setModuleDefault) || | ||
(Object.create ? | ||
function (o, v) { | ||
Object.defineProperty(o, 'default', { enumerable: true, value: v }); | ||
} | ||
: function (o, v) { | ||
o['default'] = v; | ||
}); | ||
var __importStar = | ||
(this && this.__importStar) || | ||
function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) | ||
for (var k in mod) | ||
if (k !== 'default' && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
var __classPrivateFieldSet = | ||
@@ -92,3 +52,2 @@ (this && this.__classPrivateFieldSet) || | ||
void 0; | ||
const qs = __importStar(require('qs')); | ||
const version_1 = require('./version.js'); | ||
@@ -161,13 +120,2 @@ const streaming_1 = require('./streaming.js'); | ||
validateHeaders(headers, customHeaders) {} | ||
/** | ||
* Override this to add your own qs.stringify options, for example: | ||
* | ||
* { | ||
* ...super.qsOptions(), | ||
* strictNullHandling: true, | ||
* } | ||
*/ | ||
qsOptions() { | ||
return {}; | ||
} | ||
defaultIdempotencyKey() { | ||
@@ -199,5 +147,7 @@ return `stainless-node-retry-${uuid4()}`; | ||
} | ||
const encoder = new TextEncoder(); | ||
const encoded = encoder.encode(body); | ||
return encoded.length.toString(); | ||
if (typeof TextEncoder !== 'undefined') { | ||
const encoder = new TextEncoder(); | ||
const encoded = encoder.encode(body); | ||
return encoded.length.toString(); | ||
} | ||
} | ||
@@ -344,6 +294,22 @@ return null; | ||
if (query) { | ||
url.search = qs.stringify(query, this.qsOptions()); | ||
url.search = this.stringifyQuery(query); | ||
} | ||
return url.toString(); | ||
} | ||
stringifyQuery(query) { | ||
return Object.entries(query) | ||
.filter(([_, value]) => typeof value !== 'undefined') | ||
.map(([key, value]) => { | ||
if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') { | ||
return `${encodeURIComponent(key)}=${encodeURIComponent(value)}`; | ||
} | ||
if (value === null) { | ||
return `${encodeURIComponent(key)}=`; | ||
} | ||
throw new Error( | ||
`Cannot stringify type ${typeof value}; Expected string, number, boolean, or null. If you need to pass nested query parameters, you can manually encode them, e.g. { query: { 'foo[key1]': value1, 'foo[key2]': value2 } }, and please open a GitHub issue requesting better support for your use case.`, | ||
); | ||
}) | ||
.join('&'); | ||
} | ||
async fetchWithTimeout(url, init, ms, controller) { | ||
@@ -350,0 +316,0 @@ const { signal, ...options } = init || {}; |
@@ -1,2 +0,1 @@ | ||
import * as qs from 'qs'; | ||
import * as Core from './core.js'; | ||
@@ -8,3 +7,3 @@ import * as Pagination from './pagination.js'; | ||
import * as Uploads from './uploads.js'; | ||
type Config = { | ||
export interface ClientOptions { | ||
/** | ||
@@ -61,3 +60,3 @@ * Defaults to process.env["OPENAI_API_KEY"]. | ||
defaultQuery?: Core.DefaultQuery; | ||
}; | ||
} | ||
/** Instantiate the API Client. */ | ||
@@ -67,3 +66,3 @@ export declare class OpenAI extends Core.APIClient { | ||
private _options; | ||
constructor(config?: Config); | ||
constructor(opts?: ClientOptions); | ||
completions: API.Completions; | ||
@@ -82,3 +81,2 @@ chat: API.Chat; | ||
protected authHeaders(): Core.Headers; | ||
protected qsOptions(): qs.IStringifyOptions; | ||
static OpenAI: typeof OpenAI; | ||
@@ -85,0 +83,0 @@ static APIError: typeof Errors.APIError; |
@@ -68,3 +68,3 @@ 'use strict'; | ||
class OpenAI extends Core.APIClient { | ||
constructor(config) { | ||
constructor(opts) { | ||
var _b; | ||
@@ -74,3 +74,3 @@ const options = { | ||
baseURL: 'https://api.openai.com/v1', | ||
...config, | ||
...opts, | ||
}; | ||
@@ -114,5 +114,2 @@ if (!options.apiKey && options.apiKey !== null) { | ||
} | ||
qsOptions() { | ||
return { arrayFormat: 'comma' }; | ||
} | ||
} | ||
@@ -119,0 +116,0 @@ exports.OpenAI = OpenAI; |
{ | ||
"name": "openai", | ||
"version": "4.0.0-beta.5", | ||
"version": "4.0.0-beta.6", | ||
"description": "Client library for the OpenAI API", | ||
@@ -51,5 +51,4 @@ "author": "OpenAI <support@openai.com>", | ||
}, | ||
"./*": { | ||
"./*.mjs": { | ||
"types": "./*.d.ts", | ||
"require": "./*.js", | ||
"default": "./*.mjs" | ||
@@ -61,4 +60,5 @@ }, | ||
}, | ||
"./*.mjs": { | ||
"./*": { | ||
"types": "./*.d.ts", | ||
"require": "./*.js", | ||
"default": "./*.mjs" | ||
@@ -77,3 +77,2 @@ } | ||
"@types/node-fetch": "^2.6.4", | ||
"@types/qs": "^6.9.7", | ||
"abort-controller": "^3.0.0", | ||
@@ -84,5 +83,4 @@ "agentkeepalive": "^4.2.1", | ||
"formdata-node": "^4.3.2", | ||
"node-fetch": "^2.6.7", | ||
"qs": "^6.10.3" | ||
"node-fetch": "^2.6.7" | ||
} | ||
} |
@@ -13,2 +13,2 @@ /** | ||
exports.isPolyfilled = true; | ||
exports.isPolyfilled = false; |
@@ -1,2 +0,1 @@ | ||
import * as qs from 'qs'; | ||
import { VERSION } from './version'; | ||
@@ -85,14 +84,2 @@ import { Stream } from './streaming'; | ||
/** | ||
* Override this to add your own qs.stringify options, for example: | ||
* | ||
* { | ||
* ...super.qsOptions(), | ||
* strictNullHandling: true, | ||
* } | ||
*/ | ||
protected qsOptions(): qs.IStringifyOptions | undefined { | ||
return {}; | ||
} | ||
protected defaultIdempotencyKey(): string { | ||
@@ -132,5 +119,7 @@ return `stainless-node-retry-${uuid4()}`; | ||
const encoder = new TextEncoder(); | ||
const encoded = encoder.encode(body); | ||
return encoded.length.toString(); | ||
if (typeof TextEncoder !== 'undefined') { | ||
const encoder = new TextEncoder(); | ||
const encoded = encoder.encode(body); | ||
return encoded.length.toString(); | ||
} | ||
} | ||
@@ -307,3 +296,3 @@ | ||
if (query) { | ||
url.search = qs.stringify(query, this.qsOptions()); | ||
url.search = this.stringifyQuery(query); | ||
} | ||
@@ -314,2 +303,19 @@ | ||
protected stringifyQuery(query: Record<string, unknown>): string { | ||
return Object.entries(query) | ||
.filter(([_, value]) => typeof value !== 'undefined') | ||
.map(([key, value]) => { | ||
if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') { | ||
return `${encodeURIComponent(key)}=${encodeURIComponent(value)}`; | ||
} | ||
if (value === null) { | ||
return `${encodeURIComponent(key)}=`; | ||
} | ||
throw new Error( | ||
`Cannot stringify type ${typeof value}; Expected string, number, boolean, or null. If you need to pass nested query parameters, you can manually encode them, e.g. { query: { 'foo[key1]': value1, 'foo[key2]': value2 } }, and please open a GitHub issue requesting better support for your use case.`, | ||
); | ||
}) | ||
.join('&'); | ||
} | ||
async fetchWithTimeout( | ||
@@ -316,0 +322,0 @@ url: RequestInfo, |
// File generated from our OpenAPI spec by Stainless. | ||
import * as qs from 'qs'; | ||
import * as Core from './core'; | ||
@@ -11,3 +10,3 @@ import * as Pagination from './pagination'; | ||
type Config = { | ||
export interface ClientOptions { | ||
/** | ||
@@ -71,3 +70,3 @@ * Defaults to process.env["OPENAI_API_KEY"]. | ||
defaultQuery?: Core.DefaultQuery; | ||
}; | ||
} | ||
@@ -78,9 +77,9 @@ /** Instantiate the API Client. */ | ||
private _options: Config; | ||
private _options: ClientOptions; | ||
constructor(config?: Config) { | ||
const options: Config = { | ||
constructor(opts?: ClientOptions) { | ||
const options: ClientOptions = { | ||
apiKey: typeof process === 'undefined' ? '' : process.env['OPENAI_API_KEY'] || '', | ||
baseURL: 'https://api.openai.com/v1', | ||
...config, | ||
...opts, | ||
}; | ||
@@ -131,6 +130,2 @@ | ||
protected override qsOptions(): qs.IStringifyOptions { | ||
return { arrayFormat: 'comma' }; | ||
} | ||
static OpenAI = this; | ||
@@ -137,0 +132,0 @@ |
@@ -1,1 +0,1 @@ | ||
export const VERSION = '4.0.0-beta.5'; | ||
export const VERSION = '4.0.0-beta.6'; |
@@ -1,2 +0,2 @@ | ||
export declare const VERSION = '4.0.0-beta.5'; | ||
export declare const VERSION = '4.0.0-beta.6'; | ||
//# sourceMappingURL=version.d.ts.map |
'use strict'; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
exports.VERSION = void 0; | ||
exports.VERSION = '4.0.0-beta.5'; | ||
exports.VERSION = '4.0.0-beta.6'; | ||
//# sourceMappingURL=version.js.map |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
545353
8
10137
- Removed@types/qs@^6.9.7
- Removedqs@^6.10.3
- Removed@types/qs@6.9.17(transitive)
- Removedcall-bind@1.0.7(transitive)
- Removeddefine-data-property@1.1.4(transitive)
- Removedes-define-property@1.0.0(transitive)
- Removedes-errors@1.3.0(transitive)
- Removedfunction-bind@1.1.2(transitive)
- Removedget-intrinsic@1.2.4(transitive)
- Removedgopd@1.0.1(transitive)
- Removedhas-property-descriptors@1.0.2(transitive)
- Removedhas-proto@1.0.3(transitive)
- Removedhas-symbols@1.0.3(transitive)
- Removedhasown@2.0.2(transitive)
- Removedobject-inspect@1.13.3(transitive)
- Removedqs@6.13.0(transitive)
- Removedset-function-length@1.2.2(transitive)
- Removedside-channel@1.0.6(transitive)