Skip to content

Commit 1cb7ddb

Browse files
box-sdk-buildbox-sdk-build
andauthored
feat: Add support for replacing the network client implementation (box/box-codegen#629) (#454)
Co-authored-by: box-sdk-build <box-sdk-build@box.com>
1 parent f5683b7 commit 1cb7ddb

File tree

80 files changed

+5334
-5065
lines changed

Some content is hidden

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

80 files changed

+5334
-5065
lines changed

.codegen.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{ "engineHash": "264bdc9", "specHash": "6886603", "version": "1.9.0" }
1+
{ "engineHash": "ce7ab17", "specHash": "6886603", "version": "1.9.0" }

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,15 @@ Embrace the new generation of Box SDKs and unlock the full potential of the Box
2828
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
2929
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
3030

31+
- [Box TypeScript SDK GENERATED](#box-typescript-sdk-generated)
32+
- [Table of contents](#table-of-contents)
3133
- [Installing](#installing)
3234
- [Getting Started](#getting-started)
3335
- [Documentation](#documentation)
3436
- [Upgrades](#upgrades)
3537
- [Integration Tests](#integration-tests)
3638
- [Running integration tests locally](#running-integration-tests-locally)
37-
- [Create Custom Application](#create-custom-application)
39+
- [Create Platform Application](#create-platform-application)
3840
- [Export configuration](#export-configuration)
3941
- [Questions, Bugs, and Feature Requests?](#questions-bugs-and-feature-requests)
4042
- [Copyright and License](#copyright-and-license)
@@ -107,7 +109,7 @@ Upgrading from our legacy SDKs to the new generation SDKs is a straightforward p
107109

108110
## Running integration tests locally
109111

110-
### Create Custom Application
112+
### Create Platform Application
111113

112114
To run integration tests locally you will need a `Custom App` created in the [Box Developer
113115
Console](https://app.box.com/developers/console) with `Server Authentication (with JWT)` selected as authentication method.

docs/authentication.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
44
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
55

6+
- [Authentication](#authentication)
67
- [Authentication methods](#authentication-methods)
78
- [Developer Token](#developer-token)
89
- [JWT Auth](#jwt-auth)
@@ -54,7 +55,7 @@ console.log(`My user ID is ${me.id}`);
5455

5556
## JWT Auth
5657

57-
Before using JWT Auth make sure you set up correctly your Box App.
58+
Before using JWT Auth make sure you set up correctly your Box platform app.
5859
The guide with all required steps can be found here: [Setup with JWT][jwt_guide]
5960

6061
### Authenticate Enterprise
@@ -164,7 +165,7 @@ const userClient = new BoxClient({ auth: jwtAuth });
164165

165166
## Client Credentials Grant
166167

167-
Before using Client Credentials Grant Auth make sure you set up correctly your Box App.
168+
Before using Client Credentials Grant Auth make sure you set up correctly your Box platform app.
168169
The guide with all required steps can be found here: [Setup with Client Credentials Grant][ccg_guide]
169170

170171
Client Credentials Grant Auth method allows you to obtain an access token by having client credentials

package-lock.json

Lines changed: 94 additions & 91 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/box/oauth.generated.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ export class BoxOAuth implements Authentication {
144144
return token!;
145145
}
146146
/**
147-
* Get a new access token for the app user.
147+
* Get a new access token for the platform app user.
148148
* @param {NetworkSession} networkSession An object to keep network session state
149149
* @returns {Promise<AccessToken>}
150150
*/

src/client.generated.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,13 @@ import { IntegrationMappingsManager } from './managers/integrationMappings.gener
7474
import { AiManager } from './managers/ai.generated.js';
7575
import { Authentication } from './networking/auth.generated.js';
7676
import { NetworkSession } from './networking/network.generated.js';
77+
import { BoxSdkError } from './box/errors.js';
78+
import { FetchOptions } from './networking/fetchOptions.generated.js';
79+
import { FetchResponse } from './networking/fetchResponse.generated.js';
7780
import { BaseUrls } from './networking/baseUrls.generated.js';
7881
import { ProxyConfig } from './networking/proxyConfig.generated.js';
7982
import { AgentOptions } from './internal/utils.js';
8083
import { Interceptor } from './networking/interceptors.generated.js';
81-
import { FetchOptions } from './networking/fetchOptions.generated.js';
82-
import { FetchResponse } from './networking/fetchResponse.generated.js';
83-
import { fetch } from './networking/fetch.js';
8484
import { SerializedData } from './serialization/json.js';
8585
import { sdIsEmpty } from './serialization/json.js';
8686
import { sdIsBoolean } from './serialization/json.js';
@@ -584,7 +584,7 @@ export class BoxClient {
584584
responseFormat: fetchOptions.responseFormat,
585585
followRedirects: fetchOptions.followRedirects,
586586
});
587-
return (await fetch(enrichedFetchOptions)) as FetchResponse;
587+
return await networkSession.networkClient.fetch(enrichedFetchOptions);
588588
}
589589
/**
590590
* Create a new client to impersonate user with the provided ID. All calls made with the new client will be made in context of the impersonated user, leaving the original client unmodified.

src/managers/ai.generated.ts

Lines changed: 87 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,21 @@ import { ResponseFormat } from '../networking/fetchOptions.generated.js';
2020
import { AiResponseFull } from '../schemas/aiResponseFull.generated.js';
2121
import { ClientError } from '../schemas/clientError.generated.js';
2222
import { AiAsk } from '../schemas/aiAsk.generated.js';
23-
import { BoxSdkError } from '../box/errors.js';
2423
import { AiResponse } from '../schemas/aiResponse.generated.js';
2524
import { AiTextGen } from '../schemas/aiTextGen.generated.js';
2625
import { AiAgentAskOrAiAgentExtractOrAiAgentExtractStructuredOrAiAgentTextGen } from '../schemas/aiAgentAskOrAiAgentExtractOrAiAgentExtractStructuredOrAiAgentTextGen.generated.js';
2726
import { AiExtract } from '../schemas/aiExtract.generated.js';
2827
import { AiExtractResponse } from '../schemas/aiExtractResponse.generated.js';
2928
import { AiExtractStructured } from '../schemas/aiExtractStructured.generated.js';
29+
import { BoxSdkError } from '../box/errors.js';
3030
import { Authentication } from '../networking/auth.generated.js';
3131
import { NetworkSession } from '../networking/network.generated.js';
32+
import { FetchOptions } from '../networking/fetchOptions.generated.js';
33+
import { FetchResponse } from '../networking/fetchResponse.generated.js';
3234
import { prepareParams } from '../internal/utils.js';
3335
import { toString } from '../internal/utils.js';
3436
import { ByteStream } from '../internal/utils.js';
3537
import { CancellationToken } from '../internal/utils.js';
36-
import { FetchOptions } from '../networking/fetchOptions.generated.js';
37-
import { FetchResponse } from '../networking/fetchResponse.generated.js';
38-
import { fetch } from '../networking/fetch.js';
3938
import { SerializedData } from '../serialization/json.js';
4039
import { sdToJson } from '../serialization/json.js';
4140
import { sdIsEmpty } from '../serialization/json.js';
@@ -332,22 +331,23 @@ export class AiManager {
332331
const headersMap: {
333332
readonly [key: string]: string;
334333
} = prepareParams({ ...{}, ...headers.extraHeaders });
335-
const response: FetchResponse = (await fetch(
336-
new FetchOptions({
337-
url: ''.concat(
338-
this.networkSession.baseUrls.baseUrl,
339-
'/2.0/ai/ask',
340-
) as string,
341-
method: 'POST',
342-
headers: headersMap,
343-
data: serializeAiAsk(requestBody),
344-
contentType: 'application/json',
345-
responseFormat: 'json' as ResponseFormat,
346-
auth: this.auth,
347-
networkSession: this.networkSession,
348-
cancellationToken: cancellationToken,
349-
}),
350-
)) as FetchResponse;
334+
const response: FetchResponse =
335+
await this.networkSession.networkClient.fetch(
336+
new FetchOptions({
337+
url: ''.concat(
338+
this.networkSession.baseUrls.baseUrl,
339+
'/2.0/ai/ask',
340+
) as string,
341+
method: 'POST',
342+
headers: headersMap,
343+
data: serializeAiAsk(requestBody),
344+
contentType: 'application/json',
345+
responseFormat: 'json' as ResponseFormat,
346+
auth: this.auth,
347+
networkSession: this.networkSession,
348+
cancellationToken: cancellationToken,
349+
}),
350+
);
351351
return {
352352
...deserializeAiResponseFull(response.data!),
353353
rawData: response.data!,
@@ -372,22 +372,23 @@ export class AiManager {
372372
const headersMap: {
373373
readonly [key: string]: string;
374374
} = prepareParams({ ...{}, ...headers.extraHeaders });
375-
const response: FetchResponse = (await fetch(
376-
new FetchOptions({
377-
url: ''.concat(
378-
this.networkSession.baseUrls.baseUrl,
379-
'/2.0/ai/text_gen',
380-
) as string,
381-
method: 'POST',
382-
headers: headersMap,
383-
data: serializeAiTextGen(requestBody),
384-
contentType: 'application/json',
385-
responseFormat: 'json' as ResponseFormat,
386-
auth: this.auth,
387-
networkSession: this.networkSession,
388-
cancellationToken: cancellationToken,
389-
}),
390-
)) as FetchResponse;
375+
const response: FetchResponse =
376+
await this.networkSession.networkClient.fetch(
377+
new FetchOptions({
378+
url: ''.concat(
379+
this.networkSession.baseUrls.baseUrl,
380+
'/2.0/ai/text_gen',
381+
) as string,
382+
method: 'POST',
383+
headers: headersMap,
384+
data: serializeAiTextGen(requestBody),
385+
contentType: 'application/json',
386+
responseFormat: 'json' as ResponseFormat,
387+
auth: this.auth,
388+
networkSession: this.networkSession,
389+
cancellationToken: cancellationToken,
390+
}),
391+
);
391392
return {
392393
...deserializeAiResponse(response.data!),
393394
rawData: response.data!,
@@ -420,21 +421,22 @@ export class AiManager {
420421
const headersMap: {
421422
readonly [key: string]: string;
422423
} = prepareParams({ ...{}, ...headers.extraHeaders });
423-
const response: FetchResponse = (await fetch(
424-
new FetchOptions({
425-
url: ''.concat(
426-
this.networkSession.baseUrls.baseUrl,
427-
'/2.0/ai_agent_default',
428-
) as string,
429-
method: 'GET',
430-
params: queryParamsMap,
431-
headers: headersMap,
432-
responseFormat: 'json' as ResponseFormat,
433-
auth: this.auth,
434-
networkSession: this.networkSession,
435-
cancellationToken: cancellationToken,
436-
}),
437-
)) as FetchResponse;
424+
const response: FetchResponse =
425+
await this.networkSession.networkClient.fetch(
426+
new FetchOptions({
427+
url: ''.concat(
428+
this.networkSession.baseUrls.baseUrl,
429+
'/2.0/ai_agent_default',
430+
) as string,
431+
method: 'GET',
432+
params: queryParamsMap,
433+
headers: headersMap,
434+
responseFormat: 'json' as ResponseFormat,
435+
auth: this.auth,
436+
networkSession: this.networkSession,
437+
cancellationToken: cancellationToken,
438+
}),
439+
);
438440
return {
439441
...deserializeAiAgentAskOrAiAgentExtractOrAiAgentExtractStructuredOrAiAgentTextGen(
440442
response.data!,
@@ -463,22 +465,23 @@ export class AiManager {
463465
const headersMap: {
464466
readonly [key: string]: string;
465467
} = prepareParams({ ...{}, ...headers.extraHeaders });
466-
const response: FetchResponse = (await fetch(
467-
new FetchOptions({
468-
url: ''.concat(
469-
this.networkSession.baseUrls.baseUrl,
470-
'/2.0/ai/extract',
471-
) as string,
472-
method: 'POST',
473-
headers: headersMap,
474-
data: serializeAiExtract(requestBody),
475-
contentType: 'application/json',
476-
responseFormat: 'json' as ResponseFormat,
477-
auth: this.auth,
478-
networkSession: this.networkSession,
479-
cancellationToken: cancellationToken,
480-
}),
481-
)) as FetchResponse;
468+
const response: FetchResponse =
469+
await this.networkSession.networkClient.fetch(
470+
new FetchOptions({
471+
url: ''.concat(
472+
this.networkSession.baseUrls.baseUrl,
473+
'/2.0/ai/extract',
474+
) as string,
475+
method: 'POST',
476+
headers: headersMap,
477+
data: serializeAiExtract(requestBody),
478+
contentType: 'application/json',
479+
responseFormat: 'json' as ResponseFormat,
480+
auth: this.auth,
481+
networkSession: this.networkSession,
482+
cancellationToken: cancellationToken,
483+
}),
484+
);
482485
return {
483486
...deserializeAiResponse(response.data!),
484487
rawData: response.data!,
@@ -508,22 +511,23 @@ export class AiManager {
508511
const headersMap: {
509512
readonly [key: string]: string;
510513
} = prepareParams({ ...{}, ...headers.extraHeaders });
511-
const response: FetchResponse = (await fetch(
512-
new FetchOptions({
513-
url: ''.concat(
514-
this.networkSession.baseUrls.baseUrl,
515-
'/2.0/ai/extract_structured',
516-
) as string,
517-
method: 'POST',
518-
headers: headersMap,
519-
data: serializeAiExtractStructured(requestBody),
520-
contentType: 'application/json',
521-
responseFormat: 'json' as ResponseFormat,
522-
auth: this.auth,
523-
networkSession: this.networkSession,
524-
cancellationToken: cancellationToken,
525-
}),
526-
)) as FetchResponse;
514+
const response: FetchResponse =
515+
await this.networkSession.networkClient.fetch(
516+
new FetchOptions({
517+
url: ''.concat(
518+
this.networkSession.baseUrls.baseUrl,
519+
'/2.0/ai/extract_structured',
520+
) as string,
521+
method: 'POST',
522+
headers: headersMap,
523+
data: serializeAiExtractStructured(requestBody),
524+
contentType: 'application/json',
525+
responseFormat: 'json' as ResponseFormat,
526+
auth: this.auth,
527+
networkSession: this.networkSession,
528+
cancellationToken: cancellationToken,
529+
}),
530+
);
527531
return {
528532
...deserializeAiExtractResponse(response.data!),
529533
rawData: response.data!,

0 commit comments

Comments
 (0)