Skip to content

Commit 19bd56b

Browse files
codegen output 5f5d18829899442081b7ce272fc6d363 (#33)
1 parent c92ae50 commit 19bd56b

Some content is hidden

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

41 files changed

+313
-274
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,14 @@ Using `Client` object you can access managers, which allow you to perform some o
5454
The example below demonstrates how to authenticate with Developer Token and print names of all items inside a root folder.
5555

5656
```js
57-
const { Client } = require('box-typescript-sdk-gen/lib/client.generated.js');
57+
const { BoxClient } = require('box-typescript-sdk-gen/lib/client.generated.js');
5858
const {
59-
DeveloperTokenAuth,
60-
} = require('box-typescript-sdk-gen/lib/developerTokenAuth.js');
59+
BoxDeveloperTokenAuth,
60+
} = require('box-typescript-sdk-gen/lib/developerTokenAuth.generated.js');
6161

6262
async function main(token) {
63-
let auth = new DeveloperTokenAuth({ token });
64-
let client = new Client({ auth });
63+
let auth = new BoxDeveloperTokenAuth({ token });
64+
let client = new BoxClient({ auth });
6565
let entries = (await client.folders.getFolderItems('0')).entries;
6666
entries.forEach((entry) => console.log(entry));
6767
}

docs/authentication.md

Lines changed: 54 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,19 @@ and can only be used with your own account. Therefore, they're only useful for
2626
testing an app and aren't suitable for production. You can obtain a developer
2727
token from your application's [developer console][dev_console] page.
2828

29-
To create a `Client` with a developer token, construct an `DeveloperTokenAuth`
29+
To create a `BoxClient` with a developer token, construct an `BoxDeveloperTokenAuth`
3030
object with the `token` set to the developer token and construct the client with that.
3131

3232
<!-- sample x_auth init_with_dev_token -->
3333

3434
```js
35-
const { Client } = require('box-typescript-sdk-gen/lib/client.generated.js');
35+
const { BoxClient } = require('box-typescript-sdk-gen/lib/client.generated.js');
3636
const {
37-
DeveloperTokenAuth,
38-
} = require('box-typescript-sdk-gen/lib/developerTokenAuth.js');
37+
BoxDeveloperTokenAuth,
38+
} = require('box-typescript-sdk-gen/lib/developerTokenAuth.generated.js');
3939

40-
const auth = new DeveloperTokenAuth({ token: 'DEVELOPER_TOKEN_GOES_HERE' });
41-
const client = new Client({ auth });
40+
const auth = new BoxDeveloperTokenAuth({ token: 'DEVELOPER_TOKEN_GOES_HERE' });
41+
const client = new BoxClient({ auth });
4242

4343
const me = await client.users.getUserMe();
4444
console.log(`My user ID is ${me.id}`);
@@ -63,17 +63,20 @@ not accessible in any other account by default, and vice versa.
6363
If you generated your public and private keys automatically through the
6464
[Box Developer Console][dev_console], you can use the JSON file created there
6565
to configure your SDK instance and create a client to make calls as the
66-
Service Account. Call one of static `JwtAuth` method:
66+
Service Account. Call one of static `BoxJwtAuth` method:
6767
`JwtConfig.fromConfigFile(configFilePath)` and pass JSON file local path
6868
or `JwtConfig.fromConfigJsonString(configJsonString)` and pass JSON config file content as string.
6969

7070
```js
71-
const { Client } = require('box-typescript-sdk-gen/lib/client.generated.js');
72-
const { JwtAuth, JwtConfig } = require('box-typescript-sdk-gen/lib/jwtAuth.js');
71+
const { BoxClient } = require('box-typescript-sdk-gen/lib/client.generated.js');
72+
const {
73+
BoxJwtAuth,
74+
JwtConfig,
75+
} = require('box-typescript-sdk-gen/lib/jwtAuth.js');
7376

7477
const jwtConfig = JwtConfig.fromConfigFile('/path/to/settings.json');
75-
const jwtAuth = new JwtAuth({ config: jwtConfig });
76-
const client = new Client({ auth: jwtAuth });
78+
const jwtAuth = new BoxJwtAuth({ config: jwtConfig });
79+
const client = new BoxClient({ auth: jwtAuth });
7780

7881
const me = await client.users.getUserMe();
7982
console.log(`My user ID is ${me.id}`);
@@ -82,8 +85,11 @@ console.log(`My user ID is ${me.id}`);
8285
Otherwise, you'll need to provide the necessary configuration fields directly to the `JwtConfig` constructor:
8386

8487
```js
85-
const { Client } = require('box-typescript-sdk-gen/lib/client.generated.js');
86-
const { JwtAuth, JwtConfig } = require('box-typescript-sdk-gen/lib/jwtAuth.js');
88+
const { BoxClient } = require('box-typescript-sdk-gen/lib/client.generated.js');
89+
const {
90+
BoxJwtAuth,
91+
JwtConfig,
92+
} = require('box-typescript-sdk-gen/lib/jwtAuth.js');
8793

8894
const jwtConfig = new JwtConfig({
8995
clientId: 'YOUR_CLIENT_ID',
@@ -93,8 +99,8 @@ const jwtConfig = new JwtConfig({
9399
privateKeyPassphrase: 'PASSPHRASE',
94100
enterpriseId: 'YOUR_ENTERPRISE_ID',
95101
});
96-
const jwtAuth = new JwtAuth({ config: jwtConfig });
97-
const serviceAccountClient = new Client({ auth: jwtAuth });
102+
const jwtAuth = new BoxJwtAuth({ config: jwtConfig });
103+
const serviceAccountClient = new BoxClient({ auth: jwtAuth });
98104
```
99105

100106
### Authenticate user
@@ -111,22 +117,28 @@ Clients for making calls as an App User can be created with the same JSON JWT co
111117
a user ID you want to authenticate.
112118

113119
```js
114-
const { Client } = require('box-typescript-sdk-gen/lib/client.generated.js');
115-
const { JwtAuth, JwtConfig } = require('box-typescript-sdk-gen/lib/jwtAuth.js');
120+
const { BoxClient } = require('box-typescript-sdk-gen/lib/client.generated.js');
121+
const {
122+
BoxJwtAuth,
123+
JwtConfig,
124+
} = require('box-typescript-sdk-gen/lib/jwtAuth.js');
116125

117126
const jwtConfig = JwtConfig.fromConfigFile('/path/to/settings.json');
118-
const jwtAuth = new JwtAuth({ config: jwtConfig });
127+
const jwtAuth = new BoxJwtAuth({ config: jwtConfig });
119128
jwtAuth.asUser('USER_ID');
120-
const userClient = new Client({ auth: jwtAuth });
129+
const userClient = new BoxClient({ auth: jwtAuth });
121130
```
122131

123132
Alternatively, clients for making calls as an App User can be created with the same `JwtConfig`
124133
constructor as in the above examples, similarly to creating a Service Account client. Simply pass the
125134
`userId` instead of `enterpriseId` when constructing the auth config instance:
126135

127136
```js
128-
const { Client } = require('box-typescript-sdk-gen/lib/client.generated.js');
129-
const { JwtAuth, JwtConfig } = require('box-typescript-sdk-gen/lib/jwtAuth.js');
137+
const { BoxClient } = require('box-typescript-sdk-gen/lib/client.generated.js');
138+
const {
139+
BoxJwtAuth,
140+
JwtConfig,
141+
} = require('box-typescript-sdk-gen/lib/jwtAuth.js');
130142

131143
const jwtConfig = new JwtConfig({
132144
clientId: 'YOUR_CLIENT_ID',
@@ -136,8 +148,8 @@ const jwtConfig = new JwtConfig({
136148
privateKeyPassphrase: 'PASSPHRASE',
137149
userId: 'USER_ID',
138150
});
139-
const jwtAuth = new JwtAuth({ config: jwtConfig });
140-
const userClient = new Client({ auth: jwtAuth });
151+
const jwtAuth = new BoxJwtAuth({ config: jwtConfig });
152+
const userClient = new BoxClient({ auth: jwtAuth });
141153
```
142154

143155
[jwt_guide]: https://developer.box.com/guides/authentication/jwt/jwt-setup/
@@ -155,16 +167,16 @@ and secret with enterprise or user ID, which allows you to work using service or
155167
You can use `CCGAuth` to initialize a client object the same way as for other authentication types:
156168

157169
```js
158-
const { Client } = require('box-typescript-sdk-gen/lib/client.generated.js');
159-
const { CcgAuth } = require('box-typescript-sdk-gen/lib/ccgAuth.js');
170+
const { BoxClient } = require('box-typescript-sdk-gen/lib/client.generated.js');
171+
const { BoxCcgAuth } = require('box-typescript-sdk-gen/lib/ccgAuth.js');
160172

161173
const ccgConfig = {
162174
userId: 'YOUR_USER_ID',
163175
clientId: 'YOUR_CLIENT_ID',
164176
clientSecret: 'YOUR_CLIENT_SECRET',
165177
};
166-
const ccgAuth = new CcgAuth({ config: ccgConfig });
167-
const client = new Client({ auth: ccgAuth });
178+
const ccgAuth = new BoxCcgAuth({ config: ccgConfig });
179+
const client = new BoxClient({ auth: ccgAuth });
168180

169181
const me = await client.users.getUserMe();
170182
console.log(`My user ID is ${me.id}`);
@@ -181,16 +193,16 @@ are not accessible in any other account by default, and vice versa.
181193
To obtain service account you will have to provide enterprise ID with client id and secret:
182194

183195
```js
184-
const { Client } = require('box-typescript-sdk-gen/lib/client.generated.js');
185-
const { CcgAuth } = require('box-typescript-sdk-gen/lib/ccgAuth.js');
196+
const { BoxClient } = require('box-typescript-sdk-gen/lib/client.generated.js');
197+
const { BoxCcgAuth } = require('box-typescript-sdk-gen/lib/ccgAuth.js');
186198

187199
const ccgConfig = {
188200
enterpriseId: 'YOUR_ENTERPRISE_ID',
189201
clientId: 'YOUR_CLIENT_ID',
190202
clientSecret: 'YOUR_CLIENT_SECRET',
191203
};
192-
const ccgAuth = new CcgAuth({ config: ccgConfig });
193-
const client = new Client({ auth: ccgAuth });
204+
const ccgAuth = new BoxCcgAuth({ config: ccgConfig });
205+
const client = new BoxClient({ auth: ccgAuth });
194206
```
195207

196208
### Obtaining User token
@@ -202,16 +214,16 @@ select `Generate user access tokens`. Do not forget to re-authorize application
202214
To obtain user account you will have to provide user ID with client id and secret.
203215

204216
```js
205-
const { Client } = require('box-typescript-sdk-gen/lib/client.generated.js');
206-
const { CcgAuth } = require('box-typescript-sdk-gen/lib/ccgAuth.js');
217+
const { BoxClient } = require('box-typescript-sdk-gen/lib/client.generated.js');
218+
const { BoxCcgAuth } = require('box-typescript-sdk-gen/lib/ccgAuth.js');
207219

208220
const ccgConfig = {
209221
userId: 'YOUR_USER_ID',
210222
clientId: 'YOUR_CLIENT_ID',
211223
clientSecret: 'YOUR_CLIENT_SECRET',
212224
};
213-
const ccgAuth = new CcgAuth({ config: ccgConfig });
214-
const client = new Client({ auth: ccgAuth });
225+
const ccgAuth = new BoxCcgAuth({ config: ccgConfig });
226+
const client = new BoxClient({ auth: ccgAuth });
215227
```
216228

217229
### Switching between Service Account and User
@@ -248,13 +260,16 @@ browser or web view) in order to obtain an auth code.
248260
<!-- sample get_authorize -->
249261

250262
```js
251-
const { OAuth, OAuthConfig } = require('box-typescript-sdk-gen/lib/oauth.js');
263+
const {
264+
BoxOAuth,
265+
OAuthConfig,
266+
} = require('box-typescript-sdk-gen/lib/oauth.js');
252267

253268
const config = {
254269
clientId: 'OAUTH_CLIENT_ID',
255270
clientSecret: 'OAUTH_CLIENT_SECRET',
256271
};
257-
const oauth = new OAuth({ config: config });
272+
const oauth = new BoxOAuth({ config: config });
258273

259274
// the URL to redirect the user to
260275
var authorize_url = oauth.getAuthorizeUrl();
@@ -286,7 +301,7 @@ const config = {
286301
clientId: 'OAUTH_CLIENT_ID',
287302
clientSecret: 'OAUTH_CLIENT_SECRET',
288303
};
289-
const oauth = new OAuth({ config: config });
304+
const oauth = new BoxOAuth({ config: config });
290305
```
291306

292307
## Custom storage
@@ -300,5 +315,5 @@ const config = {
300315
clientSecret: 'OAUTH_CLIENT_SECRET',
301316
tokenStorage: new MyCustomTokenStorage(),
302317
};
303-
const oauth = new OAuth({ config: config });
318+
const oauth = new BoxOAuth({ config: config });
304319
```

docs/memberships.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,10 @@ See the endpoint docs at
8787

8888
```ts
8989
await client.memberships.createGroupMembership({
90-
user: user,
91-
group: group,
90+
user: { id: user.id } satisfies CreateGroupMembershipRequestBodyArgUserField,
91+
group: {
92+
id: group.id,
93+
} satisfies CreateGroupMembershipRequestBodyArgGroupField,
9294
} satisfies CreateGroupMembershipRequestBodyArg);
9395
```
9496

src/auth.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,5 @@ import { AccessToken } from './schemas.generated.js';
33

44
export interface Authentication {
55
retrieveToken: (networkSession?: NetworkSession) => Promise<AccessToken>;
6-
refreshToken: (
7-
networkSession?: NetworkSession
8-
) => Promise<AccessToken | void>;
6+
refreshToken: (networkSession?: NetworkSession) => Promise<AccessToken>;
97
}

src/ccgAuth.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,18 @@ export class CcgConfig {
2121
this.clientSecret = fields.clientSecret;
2222
this.enterpriseId = fields.enterpriseId;
2323
this.userId = fields.userId;
24-
this.tokenStorage = fields.tokenStorage ?? new InMemoryTokenStorage();
24+
this.tokenStorage = fields.tokenStorage ?? new InMemoryTokenStorage({});
2525
}
2626
}
2727

28-
export class CcgAuth implements Authentication {
28+
export class BoxCcgAuth implements Authentication {
2929
config: CcgConfig;
3030
token?: AccessToken;
3131
subjectId: string;
3232
subjectType: string;
3333
tokenStorage: TokenStorage;
3434

35-
constructor({ config }: Pick<CcgAuth, 'config'>) {
35+
constructor({ config }: Pick<BoxCcgAuth, 'config'>) {
3636
if (!config.enterpriseId && !config.userId) {
3737
throw new Error('Enterprise ID or User ID is needed');
3838
}
@@ -64,11 +64,9 @@ export class CcgAuth implements Authentication {
6464
/**
6565
* Get a new access token for the app user.
6666
* @param networkSession An object to keep network session state
67-
* @returns {Promise<AccessToken | undefined>} A promise resolving to the access token.
67+
* @returns {Promise<AccessToken>} A promise resolving to the access token.
6868
*/
69-
async refreshToken(
70-
networkSession?: NetworkSession
71-
): Promise<AccessToken | undefined> {
69+
async refreshToken(networkSession?: NetworkSession): Promise<AccessToken> {
7270
const requestBody = {
7371
grant_type: 'client_credentials' as TokenRequestGrantType,
7472
client_id: this.config.clientId,

src/client.generated.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ import { SignTemplatesManager } from './managers/signTemplates.generated.js';
6868
import { IntegrationMappingsManager } from './managers/integrationMappings.generated.js';
6969
import { Authentication } from './auth.js';
7070
import { NetworkSession } from './network.js';
71-
export class Client {
71+
export class BoxClient {
7272
readonly auth!: Authentication;
7373
readonly networkSession?: NetworkSession = {} satisfies NetworkSession;
7474
readonly authorization: AuthorizationManager;
@@ -141,7 +141,7 @@ export class Client {
141141
readonly integrationMappings: IntegrationMappingsManager;
142142
constructor(
143143
fields: Omit<
144-
Client,
144+
BoxClient,
145145
| 'authorization'
146146
| 'files'
147147
| 'trashedFiles'
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { AccessToken } from './schemas.generated.js';
2+
import { Authentication } from './auth.js';
3+
import { NetworkSession } from './network.js';
4+
export class BoxDeveloperTokenAuth implements Authentication {
5+
readonly token!: string;
6+
constructor(
7+
fields: Omit<BoxDeveloperTokenAuth, 'retrieveToken' | 'refreshToken'>
8+
) {
9+
Object.assign(this, fields);
10+
}
11+
async retrieveToken(networkSession?: NetworkSession): Promise<AccessToken> {
12+
return { accessToken: this.token } satisfies AccessToken;
13+
}
14+
async refreshToken(networkSession?: NetworkSession): Promise<AccessToken> {
15+
throw 'Developer token has expired. Please provide a new one.';
16+
}
17+
}

src/developerTokenAuth.ts

Lines changed: 0 additions & 29 deletions
This file was deleted.

0 commit comments

Comments
 (0)