Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
dsinghvi committed Jan 14, 2025
1 parent 65c6c42 commit ce7fc22
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
1 change: 1 addition & 0 deletions .fernignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ tests/integration
src/wrapper
src/index.ts
src/api/resources/auth/client/Client.ts
src/core/fetcher/getRequestBody.ts
9 changes: 6 additions & 3 deletions src/api/resources/auth/client/Client.ts
Original file line number Diff line number Diff line change
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 @@ -74,11 +74,14 @@ export class Auth {
},
contentType: "application/x-www-form-urlencoded",
requestType: "urlencoded",
body: undefined,
queryParameters: {
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

0 comments on commit ce7fc22

Please sign in to comment.