From 003070f0b69260aa74c98526d4175600ee745a78 Mon Sep 17 00:00:00 2001 From: box-sdk-build Date: Fri, 1 Sep 2023 05:30:17 -0700 Subject: [PATCH] generated with codegen at box/box-codegen@6219bf2 and spec at box/box-openapi@f01a34e --- docs/fileVersions.md | 33 ++++++++-- src/ccgAuth.ts | 16 ++++- src/developerTokenAuth.ts | 10 +++ src/jwtAuth.ts | 8 ++- src/oauth.ts | 5 +- src/test/fileVersions.generated.test.ts | 83 +++++++++++++++++++++++++ 6 files changed, 144 insertions(+), 11 deletions(-) create mode 100644 src/test/fileVersions.generated.test.ts diff --git a/docs/fileVersions.md b/docs/fileVersions.md index f68e7d1a..029ca8be 100644 --- a/docs/fileVersions.md +++ b/docs/fileVersions.md @@ -18,7 +18,11 @@ This operation is performed by calling function `getFileVersions`. See the endpoint docs at [API Reference](https://developer.box.com/reference/get-files-id-versions/). -_Currently we don't have an example for calling `getFileVersions` in integration tests_ + + +```ts +await client.fileVersions.getFileVersions(file.id); +``` ### Arguments @@ -46,7 +50,14 @@ This operation is performed by calling function `getFileVersionById`. See the endpoint docs at [API Reference](https://developer.box.com/reference/get-files-id-versions-id/). -_Currently we don't have an example for calling `getFileVersionById` in integration tests_ + + +```ts +await client.fileVersions.getFileVersionById( + file.id, + fileVersions.entries[0].id +); +``` ### Arguments @@ -111,7 +122,14 @@ This operation is performed by calling function `deleteFileVersionById`. See the endpoint docs at [API Reference](https://developer.box.com/reference/delete-files-id-versions-id/). -_Currently we don't have an example for calling `deleteFileVersionById` in integration tests_ + + +```ts +await client.fileVersions.deleteFileVersionById( + file.id, + fileVersionsRestored.entries[0].id +); +``` ### Arguments @@ -153,7 +171,14 @@ This operation is performed by calling function `promoteFileVersion`. See the endpoint docs at [API Reference](https://developer.box.com/reference/post-files-id-versions-current/). -_Currently we don't have an example for calling `promoteFileVersion` in integration tests_ + + +```ts +await client.fileVersions.promoteFileVersion(file.id, { + id: fileVersions.entries[0].id, + type: 'file_version' as PromoteFileVersionRequestBodyArgTypeField, +} satisfies PromoteFileVersionRequestBodyArg); +``` ### Arguments diff --git a/src/ccgAuth.ts b/src/ccgAuth.ts index c8fcf49f..dfa18f98 100644 --- a/src/ccgAuth.ts +++ b/src/ccgAuth.ts @@ -36,14 +36,26 @@ export class CcgAuth implements Authentication { } } - async retrieveToken(networkSession?: NetworkSession) { + /** + * Get the access token for the app user. If the token is not cached or is expired, a new one will be fetched. + * @param networkSession An object to keep network session state + * @returns {Promise} A promise resolving to the access token. + */ + async retrieveToken(networkSession?: NetworkSession): Promise { if (!this.token) { await this.refreshToken(networkSession); } return this.token!; } - async refreshToken(networkSession?: NetworkSession) { + /** + * Get a new access token for the app user. + * @param networkSession An object to keep network session state + * @returns {Promise} A promise resolving to the access token. + */ + async refreshToken( + networkSession?: NetworkSession + ): Promise { const requestBody = { grant_type: 'client_credentials' as TokenRequestGrantType, client_id: this.config.clientId, diff --git a/src/developerTokenAuth.ts b/src/developerTokenAuth.ts index b156a475..ccfb1c93 100644 --- a/src/developerTokenAuth.ts +++ b/src/developerTokenAuth.ts @@ -9,10 +9,20 @@ export class DeveloperTokenAuth implements Authentication { this.token = { accessToken: token } satisfies AccessToken; } + /** + * Retrieves stored developer token + * @param networkSession An object to keep network session state + * @returns {AccessToken} A stored access token. + */ async retrieveToken(networkSession?: NetworkSession) { return this.token; } + /** + * Developer token cannot be refreshed + * @param networkSession An object to keep network session state + * @returns Always throws an exception + */ async refreshToken(networkSession?: NetworkSession) { throw Error('Developer token has expired. Please provide a new one.'); } diff --git a/src/jwtAuth.ts b/src/jwtAuth.ts index 0e10966b..f7067df0 100644 --- a/src/jwtAuth.ts +++ b/src/jwtAuth.ts @@ -148,8 +148,9 @@ export class JwtAuth implements Authentication { } /** - * Get the access token for the app user. If the token is not cached or is expired, a new one will be fetched. - * @returns {Promise} A promise resolving to the access token. + * Get the access token for the app user. If the token is not cached or is expired, a new one will be fetched. + * @param networkSession An object to keep network session state + * @returns {Promise} A promise resolving to the access token. */ async retrieveToken(networkSession?: NetworkSession): Promise { if (!this.token) { @@ -160,7 +161,8 @@ export class JwtAuth implements Authentication { /** * Get a new access token for the app user. - * @returns {Promise} A promise resolving to the access token. + * @param networkSession An object to keep network session state + * @returns {Promise} A promise resolving to the access token. */ async refreshToken( networkSession?: NetworkSession diff --git a/src/oauth.ts b/src/oauth.ts index c5337212..37d1eecd 100644 --- a/src/oauth.ts +++ b/src/oauth.ts @@ -134,7 +134,7 @@ export class OAuth implements Authentication { /** * Get the access token for the app user. If the token is not cached or is expired, a new one will be fetched. * @param networkSession An object to keep network session state - * @returns {Promise} A promise resolving to the access token. + * @returns {Promise} A promise resolving to the access token. */ async retrieveToken(networkSession?: NetworkSession): Promise { if (!this.token) { @@ -148,7 +148,8 @@ export class OAuth implements Authentication { /** * Get a new access token for the app user. * @param networkSession An object to keep network session state - * @returns {Promise} A promise resolving to the access token. + * @param refreshToken Refresh token, which can be used to obtain a new access token + * @returns {Promise} A promise resolving to the access token. */ async refreshToken( networkSession?: NetworkSession, diff --git a/src/test/fileVersions.generated.test.ts b/src/test/fileVersions.generated.test.ts new file mode 100644 index 00000000..5389c468 --- /dev/null +++ b/src/test/fileVersions.generated.test.ts @@ -0,0 +1,83 @@ +import { serializeFiles } from "../schemas.generated.js"; +import { deserializeFiles } from "../schemas.generated.js"; +import { serializeUploadFileRequestBodyArgAttributesField } from "../managers/uploads.generated.js"; +import { deserializeUploadFileRequestBodyArgAttributesField } from "../managers/uploads.generated.js"; +import { serializeUploadFileRequestBodyArgAttributesFieldParentField } from "../managers/uploads.generated.js"; +import { deserializeUploadFileRequestBodyArgAttributesFieldParentField } from "../managers/uploads.generated.js"; +import { serializeFile } from "../schemas.generated.js"; +import { deserializeFile } from "../schemas.generated.js"; +import { serializeUploadFileVersionRequestBodyArgAttributesField } from "../managers/uploads.generated.js"; +import { deserializeUploadFileVersionRequestBodyArgAttributesField } from "../managers/uploads.generated.js"; +import { serializeFileVersions } from "../schemas.generated.js"; +import { deserializeFileVersions } from "../schemas.generated.js"; +import { serializeFileVersionFull } from "../schemas.generated.js"; +import { deserializeFileVersionFull } from "../schemas.generated.js"; +import { serializePromoteFileVersionRequestBodyArg } from "../managers/fileVersions.generated.js"; +import { deserializePromoteFileVersionRequestBodyArg } from "../managers/fileVersions.generated.js"; +import { serializePromoteFileVersionRequestBodyArgTypeField } from "../managers/fileVersions.generated.js"; +import { deserializePromoteFileVersionRequestBodyArgTypeField } from "../managers/fileVersions.generated.js"; +import { serializeFileFull } from "../schemas.generated.js"; +import { deserializeFileFull } from "../schemas.generated.js"; +import { Files } from "../schemas.generated.js"; +import { UploadFileRequestBodyArg } from "../managers/uploads.generated.js"; +import { UploadFileRequestBodyArgAttributesField } from "../managers/uploads.generated.js"; +import { UploadFileRequestBodyArgAttributesFieldParentField } from "../managers/uploads.generated.js"; +import { File } from "../schemas.generated.js"; +import { UploadFileVersionRequestBodyArg } from "../managers/uploads.generated.js"; +import { UploadFileVersionRequestBodyArgAttributesField } from "../managers/uploads.generated.js"; +import { FileVersions } from "../schemas.generated.js"; +import { FileVersionFull } from "../schemas.generated.js"; +import { PromoteFileVersionRequestBodyArg } from "../managers/fileVersions.generated.js"; +import { PromoteFileVersionRequestBodyArgTypeField } from "../managers/fileVersions.generated.js"; +import { FileFull } from "../schemas.generated.js"; +import { decodeBase64 } from "../utils.js"; +import { getEnvVar } from "../utils.js"; +import { getUuid } from "../utils.js"; +import { generateByteStream } from "../utils.js"; +import { Client } from "../client.generated.js"; +import { JwtAuth } from "../jwtAuth.js"; +import { JwtConfig } from "../jwtAuth.js"; +const jwtConfig: any = JwtConfig.fromConfigJsonString(decodeBase64(getEnvVar("JWT_CONFIG_BASE_64"))); +const auth: any = new JwtAuth({ config: jwtConfig }); +const client: any = new Client({ auth: auth }); +test("testCreateListGetRestoreDeleteFileVersion", async function testCreateListGetRestoreDeleteFileVersion(): Promise { + const oldName: any = getUuid(); + const newName: any = getUuid(); + const files: any = await client.uploads.uploadFile({ attributes: { name: oldName, parent: { id: "0" } satisfies UploadFileRequestBodyArgAttributesFieldParentField } satisfies UploadFileRequestBodyArgAttributesField, file: generateByteStream(10) } satisfies UploadFileRequestBodyArg); + const file: any = files.entries[0]; + if (!(file.name == oldName)) { + throw "Assertion failed"; + } + if (!(file.size == 10)) { + throw "Assertion failed"; + } + const newFiles: any = await client.uploads.uploadFileVersion(file.id, { attributes: { name: newName } satisfies UploadFileVersionRequestBodyArgAttributesField, file: generateByteStream(20) } satisfies UploadFileVersionRequestBodyArg); + const newFile: any = newFiles.entries[0]; + if (!(newFile.name == newName)) { + throw "Assertion failed"; + } + if (!(newFile.size == 20)) { + throw "Assertion failed"; + } + const fileVersions: any = await client.fileVersions.getFileVersions(file.id); + if (!(fileVersions.totalCount == 1)) { + throw "Assertion failed"; + } + const fileVersion: any = await client.fileVersions.getFileVersionById(file.id, fileVersions.entries[0].id); + if (!(fileVersion.id == fileVersions.entries[0].id)) { + throw "Assertion failed"; + } + await client.fileVersions.promoteFileVersion(file.id, { id: fileVersions.entries[0].id, type: "file_version" as PromoteFileVersionRequestBodyArgTypeField } satisfies PromoteFileVersionRequestBodyArg) + const fileRestored: any = await client.files.getFileById(file.id); + if (!(fileRestored.name == oldName)) { + throw "Assertion failed"; + } + if (!(fileRestored.size == 10)) { + throw "Assertion failed"; + } + const fileVersionsRestored: any = await client.fileVersions.getFileVersions(file.id); + await client.fileVersions.deleteFileVersionById(file.id, fileVersionsRestored.entries[0].id) + await client.fileVersions.getFileVersions(file.id) + await client.files.deleteFileById(file.id) +}); +export {};