Skip to content

Commit db3a2b5

Browse files
box-sdk-buildbox-sdk-build
and
box-sdk-build
authored
feat(ts): add comments to properties and methods (box/box-codegen#537) (#284)
Co-authored-by: box-sdk-build <[email protected]>
1 parent ca77f58 commit db3a2b5

File tree

272 files changed

+12702
-98
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

272 files changed

+12702
-98
lines changed

.codegen.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{ "engineHash": "871ac70", "specHash": "e50af18", "version": "1.3.0" }
1+
{ "engineHash": "525674e", "specHash": "e50af18", "version": "1.3.0" }

package-lock.json

+99-96
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/box/ccgAuth.generated.ts

+70
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,20 @@ import { BoxSdkError } from './errors.js';
1111
import { PostOAuth2Token } from '../schemas/postOAuth2Token.generated.js';
1212
import { PostOAuth2Revoke } from '../schemas/postOAuth2Revoke.generated.js';
1313
export class CcgConfig {
14+
/**
15+
* Box API key used for identifying the application the user is authenticating with */
1416
readonly clientId!: string;
17+
/**
18+
* Box API secret used for making auth requests. */
1519
readonly clientSecret!: string;
20+
/**
21+
* The ID of the Box Developer Edition enterprise. */
1622
readonly enterpriseId?: string;
23+
/**
24+
* The user id to authenticate. This value is not required. But if it is provided, then the user will be auto-authenticated at the time of the first API call. */
1725
readonly userId?: string;
26+
/**
27+
* Object responsible for storing token. If no custom implementation provided,the token will be stored in memory. */
1828
readonly tokenStorage: TokenStorage = new InMemoryTokenStorage({});
1929
constructor(
2030
fields: Omit<CcgConfig, 'tokenStorage'> &
@@ -38,16 +48,34 @@ export class CcgConfig {
3848
}
3949
}
4050
export interface CcgConfigInput {
51+
/**
52+
* Box API key used for identifying the application the user is authenticating with */
4153
readonly clientId: string;
54+
/**
55+
* Box API secret used for making auth requests. */
4256
readonly clientSecret: string;
57+
/**
58+
* The ID of the Box Developer Edition enterprise. */
4359
readonly enterpriseId?: string;
60+
/**
61+
* The user id to authenticate. This value is not required. But if it is provided, then the user will be auto-authenticated at the time of the first API call. */
4462
readonly userId?: string;
63+
/**
64+
* Object responsible for storing token. If no custom implementation provided,the token will be stored in memory. */
4565
readonly tokenStorage?: TokenStorage;
4666
}
4767
export class BoxCcgAuth implements Authentication {
68+
/**
69+
* Configuration object of Client Credentials Grant auth. */
4870
readonly config!: CcgConfig;
71+
/**
72+
* An object responsible for storing token. If no custom implementation provided, the token will be stored in memory. */
4973
readonly tokenStorage: TokenStorage;
74+
/**
75+
* The ID of the user or enterprise to authenticate as. If not provided, defaults to the enterprise ID if set, otherwise defaults to the user ID. */
5076
readonly subjectId?: string;
77+
/**
78+
* The type of the subject ID provided. Must be either 'user' or 'enterprise'. */
5179
readonly subjectType?: PostOAuth2TokenBoxSubjectTypeField;
5280
constructor(
5381
fields: Omit<
@@ -75,6 +103,11 @@ export class BoxCcgAuth implements Authentication {
75103
? ('user' as PostOAuth2TokenBoxSubjectTypeField)
76104
: ('enterprise' as PostOAuth2TokenBoxSubjectTypeField);
77105
}
106+
/**
107+
* Get a new access token using CCG auth
108+
* @param {NetworkSession} networkSession An object to keep network session state
109+
* @returns {Promise<AccessToken>}
110+
*/
78111
async refreshToken(networkSession?: NetworkSession): Promise<AccessToken> {
79112
const authManager: AuthorizationManager = new AuthorizationManager({
80113
networkSession: !(networkSession == void 0)
@@ -91,6 +124,11 @@ export class BoxCcgAuth implements Authentication {
91124
await this.tokenStorage.store(token);
92125
return token;
93126
}
127+
/**
128+
* Return a current token or get a new one when not available.
129+
* @param {NetworkSession} networkSession An object to keep network session state
130+
* @returns {Promise<AccessToken>}
131+
*/
94132
async retrieveToken(networkSession?: NetworkSession): Promise<AccessToken> {
95133
const oldToken: undefined | AccessToken = await this.tokenStorage.get();
96134
if (oldToken == void 0) {
@@ -99,12 +137,25 @@ export class BoxCcgAuth implements Authentication {
99137
}
100138
return oldToken!;
101139
}
140+
/**
141+
* @param {NetworkSession} networkSession
142+
* @returns {Promise<string>}
143+
*/
102144
async retrieveAuthorizationHeader(
103145
networkSession?: NetworkSession
104146
): Promise<string> {
105147
const token: AccessToken = await this.retrieveToken(networkSession);
106148
return ''.concat('Bearer ', token.accessToken!) as string;
107149
}
150+
/**
151+
* Create a new BoxCCGAuth instance that uses the provided user ID as the subject ID.
152+
* May be one of this application's created App User. Depending on the configured User Access Level, may also be any other App User or Managed User in the enterprise.
153+
* <https://developer.box.com/en/guides/applications/>
154+
* <https://developer.box.com/en/guides/authentication/select/>
155+
* @param {string} userId The id of the user to authenticate
156+
* @param {TokenStorage} tokenStorage Object responsible for storing token in newly created BoxCCGAuth. If no custom implementation provided, the token will be stored in memory.
157+
* @returns {BoxCcgAuth}
158+
*/
108159
withUserSubject(
109160
userId: string,
110161
tokenStorage: TokenStorage = new InMemoryTokenStorage({})
@@ -118,6 +169,12 @@ export class BoxCcgAuth implements Authentication {
118169
});
119170
return new BoxCcgAuth({ config: newConfig });
120171
}
172+
/**
173+
* Create a new BoxCCGAuth instance that uses the provided enterprise ID as the subject ID.
174+
* @param {string} enterpriseId The id of the enterprise to authenticate
175+
* @param {TokenStorage} tokenStorage Object responsible for storing token in newly created BoxCCGAuth. If no custom implementation provided, the token will be stored in memory.
176+
* @returns {BoxCcgAuth}
177+
*/
121178
withEnterpriseSubject(
122179
enterpriseId: string,
123180
tokenStorage: TokenStorage = new InMemoryTokenStorage({})
@@ -131,6 +188,14 @@ export class BoxCcgAuth implements Authentication {
131188
});
132189
return new BoxCcgAuth({ config: newConfig });
133190
}
191+
/**
192+
* Downscope access token to the provided scopes. Returning a new access token with the provided scopes, with the original access token unchanged.
193+
* @param {readonly string[]} scopes The scope(s) to apply to the resulting token.
194+
* @param {string} resource The file or folder to get a downscoped token for. If None and shared_link None, the resulting token will not be scoped down to just a single item. The resource should be a full URL to an item, e.g. https://api.box.com/2.0/files/123456.
195+
* @param {string} sharedLink The shared link to get a downscoped token for. If None and item None, the resulting token will not be scoped down to just a single item.
196+
* @param {NetworkSession} networkSession An object to keep network session state
197+
* @returns {Promise<AccessToken>}
198+
*/
134199
async downscopeToken(
135200
scopes: readonly string[],
136201
resource?: string,
@@ -161,6 +226,11 @@ export class BoxCcgAuth implements Authentication {
161226
} satisfies PostOAuth2Token);
162227
return downscopedToken;
163228
}
229+
/**
230+
* Revoke the current access token and remove it from token storage.
231+
* @param {NetworkSession} networkSession An object to keep network session state
232+
* @returns {Promise<undefined>}
233+
*/
164234
async revokeToken(networkSession?: NetworkSession): Promise<undefined> {
165235
const oldToken: undefined | AccessToken = await this.tokenStorage.get();
166236
if (oldToken == void 0) {

src/box/developerTokenAuth.generated.ts

+31
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@ export interface DeveloperTokenConfig {
1515
}
1616
export class BoxDeveloperTokenAuth implements Authentication {
1717
readonly token!: string;
18+
/**
19+
* Configuration object of DeveloperTokenAuth. */
1820
readonly config: DeveloperTokenConfig = {} satisfies DeveloperTokenConfig;
21+
/**
22+
* An object responsible for storing token. If no custom implementation provided, the token will be stored in memory. */
1923
readonly tokenStorage: TokenStorage;
2024
constructor(
2125
fields: Omit<
@@ -40,24 +44,43 @@ export class BoxDeveloperTokenAuth implements Authentication {
4044
token: { accessToken: this.token } satisfies AccessToken,
4145
});
4246
}
47+
/**
48+
* Retrieves stored developer token
49+
* @param {NetworkSession} networkSession An object to keep network session state
50+
* @returns {Promise<AccessToken>}
51+
*/
4352
async retrieveToken(networkSession?: NetworkSession): Promise<AccessToken> {
4453
const token: undefined | AccessToken = await this.tokenStorage.get();
4554
if (token == void 0) {
4655
throw new BoxSdkError({ message: 'No access token is available.' });
4756
}
4857
return token!;
4958
}
59+
/**
60+
* Developer token cannot be refreshed
61+
* @param {NetworkSession} networkSession An object to keep network session state
62+
* @returns {Promise<AccessToken>}
63+
*/
5064
async refreshToken(networkSession?: NetworkSession): Promise<AccessToken> {
5165
throw new BoxSdkError({
5266
message: 'Developer token has expired. Please provide a new one.',
5367
});
5468
}
69+
/**
70+
* @param {NetworkSession} networkSession
71+
* @returns {Promise<string>}
72+
*/
5573
async retrieveAuthorizationHeader(
5674
networkSession?: NetworkSession
5775
): Promise<string> {
5876
const token: AccessToken = await this.retrieveToken(networkSession);
5977
return ''.concat('Bearer ', token.accessToken!) as string;
6078
}
79+
/**
80+
* Revoke an active Access Token, effectively logging a user out that has been previously authenticated.
81+
* @param {NetworkSession} networkSession An object to keep network session state
82+
* @returns {Promise<undefined>}
83+
*/
6184
async revokeToken(networkSession?: NetworkSession): Promise<undefined> {
6285
const token: undefined | AccessToken = await this.tokenStorage.get();
6386
if (token == void 0) {
@@ -76,6 +99,14 @@ export class BoxDeveloperTokenAuth implements Authentication {
7699
await this.tokenStorage.clear();
77100
return void 0;
78101
}
102+
/**
103+
* Downscope access token to the provided scopes. Returning a new access token with the provided scopes, with the original access token unchanged.
104+
* @param {readonly string[]} scopes The scope(s) to apply to the resulting token.
105+
* @param {string} resource The file or folder to get a downscoped token for. If None and shared_link None, the resulting token will not be scoped down to just a single item. The resource should be a full URL to an item, e.g. https://api.box.com/2.0/files/123456.
106+
* @param {string} sharedLink The shared link to get a downscoped token for. If None and item None, the resulting token will not be scoped down to just a single item.
107+
* @param {NetworkSession} networkSession An object to keep network session state
108+
* @returns {Promise<AccessToken>}
109+
*/
79110
async downscopeToken(
80111
scopes: readonly string[],
81112
resource?: string,

0 commit comments

Comments
 (0)