Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: getToken for oauth correctly encodes params #8

Merged
merged 3 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .fernignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ src/core/fetcher/Fetcher.ts
tests/integration
src/wrapper
src/index.ts
src/api/resources/auth/client/Client.ts
src/core/fetcher/getRequestBody.ts
18 changes: 11 additions & 7 deletions src/api/resources/auth/client/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
* This file was auto-generated by Fern from our API Definition.
*/

import * as environments from "../../../../environments";
import * as core from "../../../../core";
import * as Vectara from "../../../index";
import * as serializers from "../../../../serialization/index";
import urlJoin from "url-join";
import * as core from "../../../../core";
import * as environments from "../../../../environments";
import * as errors from "../../../../errors/index";
import * as serializers from "../../../../serialization/index";
import * as Vectara from "../../../index";

export declare namespace Auth {
interface Options {
Expand Down Expand Up @@ -55,7 +55,7 @@ export class Auth {
url: urlJoin(
((await core.Supplier.get(this._options.environment)) ?? environments.VectaraEnvironment.Production)
.auth,
"oauth/token"
"oauth2/token"
),
method: "POST",
headers: {
Expand All @@ -72,12 +72,16 @@ export class Auth {
"X-Fern-Runtime-Version": core.RUNTIME.version,
...requestOptions?.headers,
},
contentType: "application/json",
requestType: "json",
contentType: "application/x-www-form-urlencoded",
requestType: "urlencoded",
body: {
...serializers.AuthGetTokenRequest.jsonOrThrow(request, { unrecognizedObjectKeys: "strip" }),
grant_type: "client_credentials",
},
// queryParameters: {
// ...serializers.AuthGetTokenRequest.jsonOrThrow(request, { unrecognizedObjectKeys: "strip" }),
// grant_type: "client_credentials",
// },
timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000,
maxRetries: requestOptions?.maxRetries,
abortSignal: requestOptions?.abortSignal,
Expand Down
2 changes: 1 addition & 1 deletion src/core/fetcher/Fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export async function fetcherImpl<R = unknown>(args: Fetcher.Args): Promise<APIR
const url = createRequestUrl(args.url, args.queryParameters);
let requestBody: BodyInit | undefined = await getRequestBody({
body: args.body,
type: args.requestType === "json" ? "json" : "other",
type: args.requestType === "json" ? "json" : args.requestType === "urlencoded" ? "urlencoded" : "other",
});
const fetchFn = await getFetchFn();

Expand Down
10 changes: 9 additions & 1 deletion src/core/fetcher/getRequestBody.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
export declare namespace GetRequestBody {
interface Args {
body: unknown;
type: "json" | "file" | "bytes" | "other";
type: "json" | "file" | "bytes" | "urlencoded" | "other";
}
}

export async function getRequestBody({ body, type }: GetRequestBody.Args): Promise<BodyInit | undefined> {
if (type.includes("json")) {
return JSON.stringify(body);
} else if (type === "urlencoded") {
const params = new URLSearchParams();
if (typeof body === "object" && body !== null) {
Object.entries(body).forEach(([key, value]) => {
params.append(key, String(value));
});
}
return params.toString();
} else {
return body as BodyInit;
}
Expand Down
6 changes: 3 additions & 3 deletions src/wrapper/client.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { VectaraClient as FernClient } from "../client";
import * as core from "../core";
import {
ChatFullResponse,
ChatFullResponse,
ChatParameters,
ChatStreamedResponse,
GenerationParameters,
SearchCorporaParameters
} from "../api";
import { VectaraClient as FernClient } from "../Client";
import * as core from "../core";
import RequestOptions = FernClient.RequestOptions;


Expand Down
Loading