Skip to content

Commit 4768a95

Browse files
generated with codegen at box/box-codegen@6219bf2 and spec at box/box-openapi@f01a34e (#30)
1 parent 0f2cef8 commit 4768a95

File tree

6 files changed

+144
-11
lines changed

6 files changed

+144
-11
lines changed

docs/fileVersions.md

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ This operation is performed by calling function `getFileVersions`.
1818
See the endpoint docs at
1919
[API Reference](https://developer.box.com/reference/get-files-id-versions/).
2020

21-
_Currently we don't have an example for calling `getFileVersions` in integration tests_
21+
<!-- sample get_files_id_versions -->
22+
23+
```ts
24+
await client.fileVersions.getFileVersions(file.id);
25+
```
2226

2327
### Arguments
2428

@@ -46,7 +50,14 @@ This operation is performed by calling function `getFileVersionById`.
4650
See the endpoint docs at
4751
[API Reference](https://developer.box.com/reference/get-files-id-versions-id/).
4852

49-
_Currently we don't have an example for calling `getFileVersionById` in integration tests_
53+
<!-- sample get_files_id_versions_id -->
54+
55+
```ts
56+
await client.fileVersions.getFileVersionById(
57+
file.id,
58+
fileVersions.entries[0].id
59+
);
60+
```
5061

5162
### Arguments
5263

@@ -111,7 +122,14 @@ This operation is performed by calling function `deleteFileVersionById`.
111122
See the endpoint docs at
112123
[API Reference](https://developer.box.com/reference/delete-files-id-versions-id/).
113124

114-
_Currently we don't have an example for calling `deleteFileVersionById` in integration tests_
125+
<!-- sample delete_files_id_versions_id -->
126+
127+
```ts
128+
await client.fileVersions.deleteFileVersionById(
129+
file.id,
130+
fileVersionsRestored.entries[0].id
131+
);
132+
```
115133

116134
### Arguments
117135

@@ -153,7 +171,14 @@ This operation is performed by calling function `promoteFileVersion`.
153171
See the endpoint docs at
154172
[API Reference](https://developer.box.com/reference/post-files-id-versions-current/).
155173

156-
_Currently we don't have an example for calling `promoteFileVersion` in integration tests_
174+
<!-- sample post_files_id_versions_current -->
175+
176+
```ts
177+
await client.fileVersions.promoteFileVersion(file.id, {
178+
id: fileVersions.entries[0].id,
179+
type: 'file_version' as PromoteFileVersionRequestBodyArgTypeField,
180+
} satisfies PromoteFileVersionRequestBodyArg);
181+
```
157182

158183
### Arguments
159184

src/ccgAuth.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,26 @@ export class CcgAuth implements Authentication {
3636
}
3737
}
3838

39-
async retrieveToken(networkSession?: NetworkSession) {
39+
/**
40+
* Get the access token for the app user. If the token is not cached or is expired, a new one will be fetched.
41+
* @param networkSession An object to keep network session state
42+
* @returns {Promise<AccessToken>} A promise resolving to the access token.
43+
*/
44+
async retrieveToken(networkSession?: NetworkSession): Promise<AccessToken> {
4045
if (!this.token) {
4146
await this.refreshToken(networkSession);
4247
}
4348
return this.token!;
4449
}
4550

46-
async refreshToken(networkSession?: NetworkSession) {
51+
/**
52+
* Get a new access token for the app user.
53+
* @param networkSession An object to keep network session state
54+
* @returns {Promise<AccessToken | undefined>} A promise resolving to the access token.
55+
*/
56+
async refreshToken(
57+
networkSession?: NetworkSession
58+
): Promise<AccessToken | undefined> {
4759
const requestBody = {
4860
grant_type: 'client_credentials' as TokenRequestGrantType,
4961
client_id: this.config.clientId,

src/developerTokenAuth.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,20 @@ export class DeveloperTokenAuth implements Authentication {
99
this.token = { accessToken: token } satisfies AccessToken;
1010
}
1111

12+
/**
13+
* Retrieves stored developer token
14+
* @param networkSession An object to keep network session state
15+
* @returns {AccessToken} A stored access token.
16+
*/
1217
async retrieveToken(networkSession?: NetworkSession) {
1318
return this.token;
1419
}
1520

21+
/**
22+
* Developer token cannot be refreshed
23+
* @param networkSession An object to keep network session state
24+
* @returns Always throws an exception
25+
*/
1626
async refreshToken(networkSession?: NetworkSession) {
1727
throw Error('Developer token has expired. Please provide a new one.');
1828
}

src/jwtAuth.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,9 @@ export class JwtAuth implements Authentication {
148148
}
149149

150150
/**
151-
* Get the access token for the app user. If the token is not cached or is expired, a new one will be fetched.
152-
* @returns {Promise<string>} A promise resolving to the access token.
151+
* Get the access token for the app user. If the token is not cached or is expired, a new one will be fetched.
152+
* @param networkSession An object to keep network session state
153+
* @returns {Promise<AccessToken>} A promise resolving to the access token.
153154
*/
154155
async retrieveToken(networkSession?: NetworkSession): Promise<AccessToken> {
155156
if (!this.token) {
@@ -160,7 +161,8 @@ export class JwtAuth implements Authentication {
160161

161162
/**
162163
* Get a new access token for the app user.
163-
* @returns {Promise<string>} A promise resolving to the access token.
164+
* @param networkSession An object to keep network session state
165+
* @returns {Promise<AccessToken | undefined>} A promise resolving to the access token.
164166
*/
165167
async refreshToken(
166168
networkSession?: NetworkSession

src/oauth.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ export class OAuth implements Authentication {
134134
/**
135135
* Get the access token for the app user. If the token is not cached or is expired, a new one will be fetched.
136136
* @param networkSession An object to keep network session state
137-
* @returns {Promise<string>} A promise resolving to the access token.
137+
* @returns {Promise<AccessToken>} A promise resolving to the access token.
138138
*/
139139
async retrieveToken(networkSession?: NetworkSession): Promise<AccessToken> {
140140
if (!this.token) {
@@ -148,7 +148,8 @@ export class OAuth implements Authentication {
148148
/**
149149
* Get a new access token for the app user.
150150
* @param networkSession An object to keep network session state
151-
* @returns {Promise<string>} A promise resolving to the access token.
151+
* @param refreshToken Refresh token, which can be used to obtain a new access token
152+
* @returns {Promise<AccessToken | undefined>} A promise resolving to the access token.
152153
*/
153154
async refreshToken(
154155
networkSession?: NetworkSession,
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
import { serializeFiles } from "../schemas.generated.js";
2+
import { deserializeFiles } from "../schemas.generated.js";
3+
import { serializeUploadFileRequestBodyArgAttributesField } from "../managers/uploads.generated.js";
4+
import { deserializeUploadFileRequestBodyArgAttributesField } from "../managers/uploads.generated.js";
5+
import { serializeUploadFileRequestBodyArgAttributesFieldParentField } from "../managers/uploads.generated.js";
6+
import { deserializeUploadFileRequestBodyArgAttributesFieldParentField } from "../managers/uploads.generated.js";
7+
import { serializeFile } from "../schemas.generated.js";
8+
import { deserializeFile } from "../schemas.generated.js";
9+
import { serializeUploadFileVersionRequestBodyArgAttributesField } from "../managers/uploads.generated.js";
10+
import { deserializeUploadFileVersionRequestBodyArgAttributesField } from "../managers/uploads.generated.js";
11+
import { serializeFileVersions } from "../schemas.generated.js";
12+
import { deserializeFileVersions } from "../schemas.generated.js";
13+
import { serializeFileVersionFull } from "../schemas.generated.js";
14+
import { deserializeFileVersionFull } from "../schemas.generated.js";
15+
import { serializePromoteFileVersionRequestBodyArg } from "../managers/fileVersions.generated.js";
16+
import { deserializePromoteFileVersionRequestBodyArg } from "../managers/fileVersions.generated.js";
17+
import { serializePromoteFileVersionRequestBodyArgTypeField } from "../managers/fileVersions.generated.js";
18+
import { deserializePromoteFileVersionRequestBodyArgTypeField } from "../managers/fileVersions.generated.js";
19+
import { serializeFileFull } from "../schemas.generated.js";
20+
import { deserializeFileFull } from "../schemas.generated.js";
21+
import { Files } from "../schemas.generated.js";
22+
import { UploadFileRequestBodyArg } from "../managers/uploads.generated.js";
23+
import { UploadFileRequestBodyArgAttributesField } from "../managers/uploads.generated.js";
24+
import { UploadFileRequestBodyArgAttributesFieldParentField } from "../managers/uploads.generated.js";
25+
import { File } from "../schemas.generated.js";
26+
import { UploadFileVersionRequestBodyArg } from "../managers/uploads.generated.js";
27+
import { UploadFileVersionRequestBodyArgAttributesField } from "../managers/uploads.generated.js";
28+
import { FileVersions } from "../schemas.generated.js";
29+
import { FileVersionFull } from "../schemas.generated.js";
30+
import { PromoteFileVersionRequestBodyArg } from "../managers/fileVersions.generated.js";
31+
import { PromoteFileVersionRequestBodyArgTypeField } from "../managers/fileVersions.generated.js";
32+
import { FileFull } from "../schemas.generated.js";
33+
import { decodeBase64 } from "../utils.js";
34+
import { getEnvVar } from "../utils.js";
35+
import { getUuid } from "../utils.js";
36+
import { generateByteStream } from "../utils.js";
37+
import { Client } from "../client.generated.js";
38+
import { JwtAuth } from "../jwtAuth.js";
39+
import { JwtConfig } from "../jwtAuth.js";
40+
const jwtConfig: any = JwtConfig.fromConfigJsonString(decodeBase64(getEnvVar("JWT_CONFIG_BASE_64")));
41+
const auth: any = new JwtAuth({ config: jwtConfig });
42+
const client: any = new Client({ auth: auth });
43+
test("testCreateListGetRestoreDeleteFileVersion", async function testCreateListGetRestoreDeleteFileVersion(): Promise<any> {
44+
const oldName: any = getUuid();
45+
const newName: any = getUuid();
46+
const files: any = await client.uploads.uploadFile({ attributes: { name: oldName, parent: { id: "0" } satisfies UploadFileRequestBodyArgAttributesFieldParentField } satisfies UploadFileRequestBodyArgAttributesField, file: generateByteStream(10) } satisfies UploadFileRequestBodyArg);
47+
const file: any = files.entries[0];
48+
if (!(file.name == oldName)) {
49+
throw "Assertion failed";
50+
}
51+
if (!(file.size == 10)) {
52+
throw "Assertion failed";
53+
}
54+
const newFiles: any = await client.uploads.uploadFileVersion(file.id, { attributes: { name: newName } satisfies UploadFileVersionRequestBodyArgAttributesField, file: generateByteStream(20) } satisfies UploadFileVersionRequestBodyArg);
55+
const newFile: any = newFiles.entries[0];
56+
if (!(newFile.name == newName)) {
57+
throw "Assertion failed";
58+
}
59+
if (!(newFile.size == 20)) {
60+
throw "Assertion failed";
61+
}
62+
const fileVersions: any = await client.fileVersions.getFileVersions(file.id);
63+
if (!(fileVersions.totalCount == 1)) {
64+
throw "Assertion failed";
65+
}
66+
const fileVersion: any = await client.fileVersions.getFileVersionById(file.id, fileVersions.entries[0].id);
67+
if (!(fileVersion.id == fileVersions.entries[0].id)) {
68+
throw "Assertion failed";
69+
}
70+
await client.fileVersions.promoteFileVersion(file.id, { id: fileVersions.entries[0].id, type: "file_version" as PromoteFileVersionRequestBodyArgTypeField } satisfies PromoteFileVersionRequestBodyArg)
71+
const fileRestored: any = await client.files.getFileById(file.id);
72+
if (!(fileRestored.name == oldName)) {
73+
throw "Assertion failed";
74+
}
75+
if (!(fileRestored.size == 10)) {
76+
throw "Assertion failed";
77+
}
78+
const fileVersionsRestored: any = await client.fileVersions.getFileVersions(file.id);
79+
await client.fileVersions.deleteFileVersionById(file.id, fileVersionsRestored.entries[0].id)
80+
await client.fileVersions.getFileVersions(file.id)
81+
await client.files.deleteFileById(file.id)
82+
});
83+
export {};

0 commit comments

Comments
 (0)