Skip to content

Commit

Permalink
Fix JS WrappedTokenResponse type (#1997)
Browse files Browse the repository at this point in the history
* Fix JS WrappedTokenResponse type

* Fix JS WrappedTokenResponse type

* Remove ts-ignore
  • Loading branch information
NolanTrem authored Feb 22, 2025
1 parent 777cc31 commit d010711
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 12 deletions.
2 changes: 1 addition & 1 deletion js/sdk/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion js/sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "r2r-js",
"version": "0.4.27",
"version": "0.4.28",
"description": "",
"main": "dist/index.js",
"browser": "dist/index.browser.js",
Expand Down
7 changes: 2 additions & 5 deletions js/sdk/src/r2rClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,9 @@ export class r2rClient extends BaseClient {

// Attempt refresh
try {
//@ts-ignore
const refreshResponse = await this.users.refreshAccessToken();
//@ts-ignore
const newAccessToken = refreshResponse.results.accessToken?.token;
//@ts-ignore
const newRefreshToken = refreshResponse.results.refreshToken?.token;
const newAccessToken = refreshResponse.results.accessToken.token;
const newRefreshToken = refreshResponse.results.refreshToken.token;

// set new tokens
this.setTokens(newAccessToken, newRefreshToken);
Expand Down
13 changes: 10 additions & 3 deletions js/sdk/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,9 +278,16 @@ export interface SettingsResponse {

// User types

export type TokenType = "access" | "refresh";

export interface Token {
accessToken: string;
refreshToken: string;
token: string;
tokenType: TokenType;
}

export interface TokenResponse {
accessToken: Token;
refreshToken: Token;
}

export interface User {
Expand Down Expand Up @@ -424,7 +431,7 @@ export type WrappedSettingsResponse = ResultsWrapper<SettingsResponse>;
export type WrappedServerStatsResponse = ResultsWrapper<ServerStats>;

// User Responses
export type WrappedTokenResponse = ResultsWrapper<Token>;
export type WrappedTokenResponse = ResultsWrapper<TokenResponse>;
export type WrappedUserResponse = ResultsWrapper<User>;
export type WrappedUsersResponse = PaginatedResultsWrapper<User[]>;
export type WrappedLimitsResponse = ResultsWrapper<LimitsResponse>;
Expand Down
9 changes: 7 additions & 2 deletions js/sdk/src/v3/clients/collections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -328,11 +328,16 @@ export class CollectionsClient {
* @param name The name of the collection to retrieve.
* @returns A promise that resolves with the collection details.
*/
async retrieveByName(options: { name: string; ownerId?: string }): Promise<WrappedCollectionResponse> {
async retrieveByName(options: {
name: string;
ownerId?: string;
}): Promise<WrappedCollectionResponse> {
const queryParams: Record<string, any> = {};
if (options.ownerId) {
queryParams.owner_id = options.ownerId;
}
return this.client.makeRequest("GET", `collections/name/${options.name}`, { params: queryParams });
return this.client.makeRequest("GET", `collections/name/${options.name}`, {
params: queryParams,
});
}
}

0 comments on commit d010711

Please sign in to comment.