Skip to content

Commit

Permalink
feat: Change asUser and asEnterprise method names (box/box-codege…
Browse files Browse the repository at this point in the history
  • Loading branch information
box-sdk-build committed Mar 28, 2024
1 parent 1c2bab4 commit 22c1907
Show file tree
Hide file tree
Showing 24 changed files with 79 additions and 60 deletions.
2 changes: 1 addition & 1 deletion .codegen.json
@@ -1 +1 @@
{ "engineHash": "0d4bf53", "specHash": "d50ab5f", "version": "0.5.2" }
{ "engineHash": "fa2d002", "specHash": "d50ab5f", "version": "0.5.2" }
10 changes: 5 additions & 5 deletions docs/authentication.md
Expand Up @@ -119,7 +119,7 @@ make calls as that user. See the [API documentation](https://developer.box.com/)
for detailed instructions on how to use app auth.

Clients for making calls as an App User can be created with the same JSON JWT config file generated through the
[Box Developer Console][dev_console]. Calling `jwtAuth.asUser('USER_ID')` method will return a new auth object,
[Box Developer Console][dev_console]. Calling `jwtAuth.withUserSubject('USER_ID')` method will return a new auth object,
which is authenticated as the user with provided id, leaving the original object unchanged.

```js
Expand All @@ -131,7 +131,7 @@ const {

const jwtConfig = JwtConfig.fromConfigFile('/path/to/settings.json');
const jwtAuth = new BoxJwtAuth({ config: jwtConfig });
const userAuth = jwtAuth.asUser('USER_ID');
const userAuth = jwtAuth.withUserSubject('USER_ID');
const userClient = new BoxClient({ auth: userAuth });
```

Expand Down Expand Up @@ -247,14 +247,14 @@ You can easily switch to be authenticated as a Service Account or as a User.
To create a new auth object authenticated as Service Account you can call:

```js
const enterpriseAuth = ccgAuth.asEnterprise('YOUR_ENTERPRISE_ID');
const enterpriseAuth = ccgAuth.withEnterpriseSubject('YOUR_ENTERPRISE_ID');
const enterpriseClient = new BoxClient({ auth: enterpriseAuth });
```

To authenticate as user with provided User ID call:
To authenticate with user subject call:

```js
const userAuth = ccgAuth.asUser('YOUR_USER_ID');
const userAuth = ccgAuth.withUserSubject('YOUR_USER_ID');
const userClient = new BoxClient({ auth: userAuth });
```

Expand Down
8 changes: 4 additions & 4 deletions src/box/ccgAuth.generated.ts
Expand Up @@ -38,8 +38,8 @@ export class BoxCcgAuth implements Authentication {
| 'refreshToken'
| 'retrieveToken'
| 'retrieveAuthorizationHeader'
| 'asUser'
| 'asEnterprise'
| 'withUserSubject'
| 'withEnterpriseSubject'
| 'downscopeToken'
| 'revokeToken'
>
Expand Down Expand Up @@ -86,7 +86,7 @@ export class BoxCcgAuth implements Authentication {
const token: AccessToken = await this.retrieveToken(networkSession);
return ''.concat('Bearer ', token.accessToken!) as string;
}
asUser(
withUserSubject(
userId: string,
tokenStorage: TokenStorage = new InMemoryTokenStorage({})
): BoxCcgAuth {
Expand All @@ -99,7 +99,7 @@ export class BoxCcgAuth implements Authentication {
});
return new BoxCcgAuth({ config: newConfig });
}
asEnterprise(
withEnterpriseSubject(
enterpriseId: string,
tokenStorage: TokenStorage = new InMemoryTokenStorage({})
): BoxCcgAuth {
Expand Down
8 changes: 4 additions & 4 deletions src/box/jwtAuth.generated.ts
Expand Up @@ -114,8 +114,8 @@ export class BoxJwtAuth implements Authentication {
| 'refreshToken'
| 'retrieveToken'
| 'retrieveAuthorizationHeader'
| 'asUser'
| 'asEnterprise'
| 'withUserSubject'
| 'withEnterpriseSubject'
| 'downscopeToken'
| 'revokeToken'
>
Expand Down Expand Up @@ -191,7 +191,7 @@ export class BoxJwtAuth implements Authentication {
const token: AccessToken = await this.retrieveToken(networkSession);
return ''.concat('Bearer ', token.accessToken!) as string;
}
asUser(
withUserSubject(
userId: string,
tokenStorage: TokenStorage = new InMemoryTokenStorage({})
): BoxJwtAuth {
Expand All @@ -208,7 +208,7 @@ export class BoxJwtAuth implements Authentication {
const newAuth: BoxJwtAuth = new BoxJwtAuth({ config: newConfig });
return newAuth;
}
asEnterprise(
withEnterpriseSubject(
userId: string,
tokenStorage: TokenStorage = new InMemoryTokenStorage({})
): BoxJwtAuth {
Expand Down
13 changes: 6 additions & 7 deletions src/test/auth.generated.test.ts
Expand Up @@ -64,9 +64,8 @@ export async function getAccessToken(): Promise<AccessToken> {
userId: userId,
});
const auth: BoxCcgAuth = new BoxCcgAuth({ config: ccgConfig });
auth.asUser(userId);
const token: AccessToken = await auth.retrieveToken();
return token;
const authUser: BoxCcgAuth = auth.withUserSubject(userId);
return await authUser.retrieveToken();
}
test('test_jwt_auth', async function test_jwt_auth(): Promise<any> {
const userId: string = getEnvVar('USER_ID');
Expand All @@ -75,13 +74,13 @@ test('test_jwt_auth', async function test_jwt_auth(): Promise<any> {
decodeBase64(getEnvVar('JWT_CONFIG_BASE_64'))
);
const auth: BoxJwtAuth = new BoxJwtAuth({ config: jwtConfig });
const userAuth: BoxJwtAuth = auth.asUser(userId);
const userAuth: BoxJwtAuth = auth.withUserSubject(userId);
const userClient: BoxClient = new BoxClient({ auth: userAuth });
const currentUser: UserFull = await userClient.users.getUserMe();
if (!(currentUser.id == userId)) {
throw new Error('Assertion failed');
}
const enterpriseAuth: BoxJwtAuth = auth.asEnterprise(enterpriseId);
const enterpriseAuth: BoxJwtAuth = auth.withEnterpriseSubject(enterpriseId);
const enterpriseClient: BoxClient = new BoxClient({ auth: enterpriseAuth });
const newUser: UserFull = await enterpriseClient.users.getUserMe({
fields: ['enterprise' as ''],
Expand Down Expand Up @@ -178,13 +177,13 @@ test('test_ccg_auth', async function test_ccg_auth(): Promise<any> {
userId: userId,
});
const auth: BoxCcgAuth = new BoxCcgAuth({ config: ccgConfig });
const userAuth: BoxCcgAuth = auth.asUser(userId);
const userAuth: BoxCcgAuth = auth.withUserSubject(userId);
const userClient: BoxClient = new BoxClient({ auth: userAuth });
const currentUser: UserFull = await userClient.users.getUserMe();
if (!(currentUser.id == userId)) {
throw new Error('Assertion failed');
}
const enterpriseAuth: BoxCcgAuth = auth.asEnterprise(enterpriseId);
const enterpriseAuth: BoxCcgAuth = auth.withEnterpriseSubject(enterpriseId);
const enterpriseClient: BoxClient = new BoxClient({ auth: enterpriseAuth });
const newUser: UserFull = await enterpriseClient.users.getUserMe({
fields: ['enterprise' as ''],
Expand Down
4 changes: 2 additions & 2 deletions src/test/commons.generated.ts
Expand Up @@ -122,9 +122,9 @@ export function getJwtAuth(): BoxJwtAuth {
const auth: BoxJwtAuth = new BoxJwtAuth({ config: jwtConfig });
return auth;
}
export function getDefaultClientAsUser(userId: string): BoxClient {
export function getDefaultClientWithUserSubject(userId: string): BoxClient {
const auth: BoxJwtAuth = getJwtAuth();
const authUser: BoxJwtAuth = auth.asUser(userId);
const authUser: BoxJwtAuth = auth.withUserSubject(userId);
return new BoxClient({ auth: authUser });
}
export function getDefaultClient(): BoxClient {
Expand Down
4 changes: 2 additions & 2 deletions src/test/fileRequests.generated.test.ts
Expand Up @@ -15,7 +15,7 @@ import { FileRequestCopyRequestFolderField } from '../schemas.generated.js';
import { FileRequestCopyRequestFolderTypeField } from '../schemas.generated.js';
import { FileRequestUpdateRequest } from '../schemas.generated.js';
import { getEnvVar } from '../internal/utils.js';
import { getDefaultClientAsUser } from './commons.generated.js';
import { getDefaultClientWithUserSubject } from './commons.generated.js';
import { toString } from '../internal/utils.js';
import { sdToJson } from '../serialization/json.js';
import { SerializedData } from '../serialization/json.js';
Expand All @@ -28,7 +28,7 @@ import { sdIsMap } from '../serialization/json.js';
test('testGetCopyUpdateDeleteFileRequest', async function testGetCopyUpdateDeleteFileRequest(): Promise<any> {
const fileRequestId: string = getEnvVar('BOX_FILE_REQUEST_ID');
const userId: string = getEnvVar('USER_ID');
const client: BoxClient = getDefaultClientAsUser(userId);
const client: BoxClient = getDefaultClientWithUserSubject(userId);
const fileRequest: FileRequest = await client.fileRequests.getFileRequestById(
fileRequestId
);
Expand Down
4 changes: 2 additions & 2 deletions src/test/integrationMappings.generated.test.ts
Expand Up @@ -30,7 +30,7 @@ import { generateByteStream } from '../internal/utils.js';
import { getUuid } from '../internal/utils.js';
import { getEnvVar } from '../internal/utils.js';
import { getDefaultClient } from './commons.generated.js';
import { getDefaultClientAsUser } from './commons.generated.js';
import { getDefaultClientWithUserSubject } from './commons.generated.js';
import { SerializedData } from '../serialization/json.js';
import { sdIsEmpty } from '../serialization/json.js';
import { sdIsBoolean } from '../serialization/json.js';
Expand All @@ -47,7 +47,7 @@ test('testIntegrationMappings', async function testIntegrationMappings(): Promis
const slackOrgId: string = '1';
const partnerItemId: string = '1';
const userId: string = getEnvVar('USER_ID');
const userClient: BoxClient = getDefaultClientAsUser(userId);
const userClient: BoxClient = getDefaultClientWithUserSubject(userId);
await expect(async () => {
await userClient.integrationMappings.createSlackIntegrationMapping({
partnerItem: {
Expand Down
4 changes: 2 additions & 2 deletions src/test/invites.generated.test.ts
Expand Up @@ -17,7 +17,7 @@ import { CreateInviteRequestBodyEnterpriseField } from '../managers/invites.gene
import { CreateInviteRequestBodyActionableByField } from '../managers/invites.generated.js';
import { getUuid } from '../internal/utils.js';
import { getEnvVar } from '../internal/utils.js';
import { getDefaultClientAsUser } from './commons.generated.js';
import { getDefaultClientWithUserSubject } from './commons.generated.js';
import { toString } from '../internal/utils.js';
import { sdToJson } from '../serialization/json.js';
import { SerializedData } from '../serialization/json.js';
Expand All @@ -29,7 +29,7 @@ import { sdIsList } from '../serialization/json.js';
import { sdIsMap } from '../serialization/json.js';
test('testInvites', async function testInvites(): Promise<any> {
const userId: string = getEnvVar('USER_ID');
const client: BoxClient = getDefaultClientAsUser(userId);
const client: BoxClient = getDefaultClientWithUserSubject(userId);
const currentUser: UserFull = await client.users.getUserMe({
fields: ['enterprise' as ''],
} satisfies GetUserMeQueryParams);
Expand Down
6 changes: 4 additions & 2 deletions src/test/recentItems.generated.test.ts
Expand Up @@ -5,7 +5,7 @@ import { RecentItems } from '../schemas.generated.js';
import { decodeBase64 } from '../internal/utils.js';
import { getEnvVar } from '../internal/utils.js';
import { getUuid } from '../internal/utils.js';
import { getDefaultClientAsUser } from './commons.generated.js';
import { getDefaultClientWithUserSubject } from './commons.generated.js';
import { SerializedData } from '../serialization/json.js';
import { sdIsEmpty } from '../serialization/json.js';
import { sdIsBoolean } from '../serialization/json.js';
Expand All @@ -14,7 +14,9 @@ import { sdIsString } from '../serialization/json.js';
import { sdIsList } from '../serialization/json.js';
import { sdIsMap } from '../serialization/json.js';
test('testRecentItems', async function testRecentItems(): Promise<any> {
const client: BoxClient = getDefaultClientAsUser(getEnvVar('USER_ID'));
const client: BoxClient = getDefaultClientWithUserSubject(
getEnvVar('USER_ID')
);
const recentItems: RecentItems = await client.recentItems.getRecentItems();
if (!(recentItems.entries!.length >= 0)) {
throw new Error('Assertion failed');
Expand Down
6 changes: 4 additions & 2 deletions src/test/sessionTermination.generated.test.ts
Expand Up @@ -20,7 +20,7 @@ import { TerminateGroupsSessionsRequestBody } from '../managers/sessionTerminati
import { getUuid } from '../internal/utils.js';
import { getEnvVar } from '../internal/utils.js';
import { getDefaultClient } from './commons.generated.js';
import { getDefaultClientAsUser } from './commons.generated.js';
import { getDefaultClientWithUserSubject } from './commons.generated.js';
import { SerializedData } from '../serialization/json.js';
import { sdIsEmpty } from '../serialization/json.js';
import { sdIsBoolean } from '../serialization/json.js';
Expand All @@ -30,7 +30,9 @@ import { sdIsList } from '../serialization/json.js';
import { sdIsMap } from '../serialization/json.js';
export const client: BoxClient = getDefaultClient();
test('testSessionTerminationUser', async function testSessionTerminationUser(): Promise<any> {
const adminClient: BoxClient = getDefaultClientAsUser(getEnvVar('USER_ID'));
const adminClient: BoxClient = getDefaultClientWithUserSubject(
getEnvVar('USER_ID')
);
const user: UserFull = await adminClient.users.getUserMe();
const result: SessionTerminationMessage =
await client.sessionTermination.terminateUsersSessions({
Expand Down
4 changes: 2 additions & 2 deletions src/test/sharedLinksFiles.generated.test.ts
Expand Up @@ -39,7 +39,7 @@ import { getUuid } from '../internal/utils.js';
import { generateByteStream } from '../internal/utils.js';
import { getEnvVar } from '../internal/utils.js';
import { getDefaultClient } from './commons.generated.js';
import { getDefaultClientAsUser } from './commons.generated.js';
import { getDefaultClientWithUserSubject } from './commons.generated.js';
import { toString } from '../internal/utils.js';
import { sdToJson } from '../serialization/json.js';
import { SerializedData } from '../serialization/json.js';
Expand Down Expand Up @@ -77,7 +77,7 @@ test('testSharedLinksFiles', async function testSharedLinksFiles(): Promise<any>
throw new Error('Assertion failed');
}
const userId: string = getEnvVar('USER_ID');
const userClient: BoxClient = getDefaultClientAsUser(userId);
const userClient: BoxClient = getDefaultClientWithUserSubject(userId);
const fileFromSharedLinkPassword: FileFull =
await userClient.sharedLinksFiles.findFileForSharedLink(
{} satisfies FindFileForSharedLinkQueryParams,
Expand Down
4 changes: 2 additions & 2 deletions src/test/sharedLinksFolders.generated.test.ts
Expand Up @@ -35,7 +35,7 @@ import { getUuid } from '../internal/utils.js';
import { generateByteStream } from '../internal/utils.js';
import { getEnvVar } from '../internal/utils.js';
import { getDefaultClient } from './commons.generated.js';
import { getDefaultClientAsUser } from './commons.generated.js';
import { getDefaultClientWithUserSubject } from './commons.generated.js';
import { toString } from '../internal/utils.js';
import { sdToJson } from '../serialization/json.js';
import { SerializedData } from '../serialization/json.js';
Expand Down Expand Up @@ -69,7 +69,7 @@ test('testSharedLinksFolders', async function testSharedLinksFolders(): Promise<
throw new Error('Assertion failed');
}
const userId: string = getEnvVar('USER_ID');
const userClient: BoxClient = getDefaultClientAsUser(userId);
const userClient: BoxClient = getDefaultClientWithUserSubject(userId);
const folderFromSharedLinkPassword: FolderFull =
await userClient.sharedLinksFolders.findFolderForSharedLink(
{} satisfies FindFolderForSharedLinkQueryParams,
Expand Down
4 changes: 2 additions & 2 deletions src/test/sharedLinksWebLinks.generated.test.ts
Expand Up @@ -38,7 +38,7 @@ import { getUuid } from '../internal/utils.js';
import { generateByteStream } from '../internal/utils.js';
import { getEnvVar } from '../internal/utils.js';
import { getDefaultClient } from './commons.generated.js';
import { getDefaultClientAsUser } from './commons.generated.js';
import { getDefaultClientWithUserSubject } from './commons.generated.js';
import { toString } from '../internal/utils.js';
import { sdToJson } from '../serialization/json.js';
import { SerializedData } from '../serialization/json.js';
Expand Down Expand Up @@ -76,7 +76,7 @@ test('testSharedLinksWebLinks', async function testSharedLinksWebLinks(): Promis
throw new Error('Assertion failed');
}
const userId: string = getEnvVar('USER_ID');
const userClient: BoxClient = getDefaultClientAsUser(userId);
const userClient: BoxClient = getDefaultClientWithUserSubject(userId);
const webLinkFromSharedLinkPassword: WebLink =
await userClient.sharedLinksWebLinks.findWebLinkForSharedLink(
{} satisfies FindWebLinkForSharedLinkQueryParams,
Expand Down
6 changes: 4 additions & 2 deletions src/test/shieldInformationBarrierReports.generated.test.ts
Expand Up @@ -17,7 +17,7 @@ import { ShieldInformationBarrierReference } from '../schemas.generated.js';
import { ShieldInformationBarrierBase } from '../schemas.generated.js';
import { ShieldInformationBarrierBaseTypeField } from '../schemas.generated.js';
import { getEnvVar } from '../internal/utils.js';
import { getDefaultClientAsUser } from './commons.generated.js';
import { getDefaultClientWithUserSubject } from './commons.generated.js';
import { getOrCreateShieldInformationBarrier } from './commons.generated.js';
import { ShieldInformationBarrier } from '../schemas.generated.js';
import { BoxClient } from '../client.generated.js';
Expand All @@ -31,7 +31,9 @@ import { sdIsString } from '../serialization/json.js';
import { sdIsList } from '../serialization/json.js';
import { sdIsMap } from '../serialization/json.js';
test('shieldInformationBarrierReports', async function shieldInformationBarrierReports(): Promise<any> {
const client: BoxClient = getDefaultClientAsUser(getEnvVar('USER_ID'));
const client: BoxClient = getDefaultClientWithUserSubject(
getEnvVar('USER_ID')
);
const enterpriseId: string = getEnvVar('ENTERPRISE_ID');
const barrier: ShieldInformationBarrier =
await getOrCreateShieldInformationBarrier(client, enterpriseId);
Expand Down
Expand Up @@ -38,7 +38,7 @@ import { ShieldInformationBarrierSegmentMembers } from '../schemas.generated.js'
import { GetShieldInformationBarrierSegmentMembersQueryParams } from '../managers/shieldInformationBarrierSegmentMembers.generated.js';
import { getEnvVar } from '../internal/utils.js';
import { getUuid } from '../internal/utils.js';
import { getDefaultClientAsUser } from './commons.generated.js';
import { getDefaultClientWithUserSubject } from './commons.generated.js';
import { getOrCreateShieldInformationBarrier } from './commons.generated.js';
import { SerializedData } from '../serialization/json.js';
import { sdIsEmpty } from '../serialization/json.js';
Expand All @@ -48,7 +48,9 @@ import { sdIsString } from '../serialization/json.js';
import { sdIsList } from '../serialization/json.js';
import { sdIsMap } from '../serialization/json.js';
test('testShieldInformationBarrierSegmentMembers', async function testShieldInformationBarrierSegmentMembers(): Promise<any> {
const client: BoxClient = getDefaultClientAsUser(getEnvVar('USER_ID'));
const client: BoxClient = getDefaultClientWithUserSubject(
getEnvVar('USER_ID')
);
const enterpriseId: string = getEnvVar('ENTERPRISE_ID');
const barrier: ShieldInformationBarrier =
await getOrCreateShieldInformationBarrier(client, enterpriseId);
Expand Down
Expand Up @@ -41,7 +41,7 @@ import { ShieldInformationBarrierSegmentRestrictions } from '../schemas.generate
import { GetShieldInformationBarrierSegmentRestrictionsQueryParams } from '../managers/shieldInformationBarrierSegmentRestrictions.generated.js';
import { getEnvVar } from '../internal/utils.js';
import { getUuid } from '../internal/utils.js';
import { getDefaultClientAsUser } from './commons.generated.js';
import { getDefaultClientWithUserSubject } from './commons.generated.js';
import { getOrCreateShieldInformationBarrier } from './commons.generated.js';
import { SerializedData } from '../serialization/json.js';
import { sdIsEmpty } from '../serialization/json.js';
Expand All @@ -51,7 +51,9 @@ import { sdIsString } from '../serialization/json.js';
import { sdIsList } from '../serialization/json.js';
import { sdIsMap } from '../serialization/json.js';
test('testShieldInformationBarrierSegmentRestrictions', async function testShieldInformationBarrierSegmentRestrictions(): Promise<any> {
const client: BoxClient = getDefaultClientAsUser(getEnvVar('USER_ID'));
const client: BoxClient = getDefaultClientWithUserSubject(
getEnvVar('USER_ID')
);
const enterpriseId: string = getEnvVar('ENTERPRISE_ID');
const barrier: ShieldInformationBarrier =
await getOrCreateShieldInformationBarrier(client, enterpriseId);
Expand Down
6 changes: 4 additions & 2 deletions src/test/shieldInformationBarrierSegments.generated.test.ts
Expand Up @@ -23,7 +23,7 @@ import { GetShieldInformationBarrierSegmentsQueryParams } from '../managers/shie
import { UpdateShieldInformationBarrierSegmentByIdRequestBody } from '../managers/shieldInformationBarrierSegments.generated.js';
import { getEnvVar } from '../internal/utils.js';
import { getUuid } from '../internal/utils.js';
import { getDefaultClientAsUser } from './commons.generated.js';
import { getDefaultClientWithUserSubject } from './commons.generated.js';
import { getOrCreateShieldInformationBarrier } from './commons.generated.js';
import { toString } from '../internal/utils.js';
import { sdToJson } from '../serialization/json.js';
Expand All @@ -35,7 +35,9 @@ import { sdIsString } from '../serialization/json.js';
import { sdIsList } from '../serialization/json.js';
import { sdIsMap } from '../serialization/json.js';
test('testShieldInformationBarrierSegments', async function testShieldInformationBarrierSegments(): Promise<any> {
const client: BoxClient = getDefaultClientAsUser(getEnvVar('USER_ID'));
const client: BoxClient = getDefaultClientWithUserSubject(
getEnvVar('USER_ID')
);
const enterpriseId: string = getEnvVar('ENTERPRISE_ID');
const barrier: ShieldInformationBarrier =
await getOrCreateShieldInformationBarrier(client, enterpriseId);
Expand Down

0 comments on commit 22c1907

Please sign in to comment.