Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ jobs:
ENTERPRISE_ID: ${{ secrets.ENTERPRISE_ID }}
BOX_FILE_REQUEST_ID: ${{ secrets.BOX_FILE_REQUEST_ID }}
BOX_EXTERNAL_USER_EMAIL: ${{ secrets.BOX_EXTERNAL_USER_EMAIL }}
WORKFLOW_FOLDER_ID: ${{ secrets.WORKFLOW_FOLDER_ID }}
- name: Coveralls
uses: coverallsapp/github-action@master
with:
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ Now select `Authorization` and submit application to be reviewed by account admi
2. Encode configuration file to Base64, e.g. using command: `base64 -i path_to_json_file`
3. Set environment variable: `JWT_CONFIG_BASE_64` with base64 encoded jwt configuration file
4. Set environment variable: `BOX_FILE_REQUEST_ID` with ID of file request already created in the user account, `BOX_EXTERNAL_USER_EMAIL` with email of free external user which not belongs to any enterprise.
5. Set environment variable: `WORKFLOW_FOLDER_ID` with the ID of the Relay workflow that deletes the file that triggered the workflow. The workflow should have a manual start to be able to start it from the API.

# Questions, Bugs, and Feature Requests?

Expand Down
39 changes: 24 additions & 15 deletions docs/authentication.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,13 +174,16 @@ You can use `CCGAuth` to initialize a client object the same way as for other au

```js
const { BoxClient } = require('box-typescript-sdk-gen/lib/client.generated.js');
const { BoxCcgAuth } = require('box-typescript-sdk-gen/lib/ccgAuth.js');
const {
BoxCcgAuth,
CcgConfig,
} = require('box-typescript-sdk-gen/lib/ccgAuth.js');

const ccgConfig = {
const ccgConfig = new CcgConfig({
userId: 'YOUR_USER_ID',
clientId: 'YOUR_CLIENT_ID',
clientSecret: 'YOUR_CLIENT_SECRET',
};
});
const ccgAuth = new BoxCcgAuth({ config: ccgConfig });
const client = new BoxClient({ auth: ccgAuth });

Expand All @@ -200,13 +203,16 @@ To obtain service account you will have to provide enterprise ID with client id

```js
const { BoxClient } = require('box-typescript-sdk-gen/lib/client.generated.js');
const { BoxCcgAuth } = require('box-typescript-sdk-gen/lib/ccgAuth.js');
const {
BoxCcgAuth,
CcgConfig,
} = require('box-typescript-sdk-gen/lib/ccgAuth.js');

const ccgConfig = {
const ccgConfig = new CcgConfig({
enterpriseId: 'YOUR_ENTERPRISE_ID',
clientId: 'YOUR_CLIENT_ID',
clientSecret: 'YOUR_CLIENT_SECRET',
};
});
const ccgAuth = new BoxCcgAuth({ config: ccgConfig });
const client = new BoxClient({ auth: ccgAuth });
```
Expand All @@ -221,13 +227,16 @@ To obtain user account you will have to provide user ID with client id and secre

```js
const { BoxClient } = require('box-typescript-sdk-gen/lib/client.generated.js');
const { BoxCcgAuth } = require('box-typescript-sdk-gen/lib/ccgAuth.js');
const {
BoxCcgAuth,
CcgConfig,
} = require('box-typescript-sdk-gen/lib/ccgAuth.js');

const ccgConfig = {
const ccgConfig = new CcgConfig({
userId: 'YOUR_USER_ID',
clientId: 'YOUR_CLIENT_ID',
clientSecret: 'YOUR_CLIENT_SECRET',
};
});
const ccgAuth = new BoxCcgAuth({ config: ccgConfig });
const client = new BoxClient({ auth: ccgAuth });
```
Expand Down Expand Up @@ -276,10 +285,10 @@ const {
OAuthConfig,
} = require('box-typescript-sdk-gen/lib/oauth.js');

const config = {
const config = new OAuthConfig({
clientId: 'OAUTH_CLIENT_ID',
clientSecret: 'OAUTH_CLIENT_SECRET',
};
});
const oauth = new BoxOAuth({ config: config });

// the URL to redirect the user to
Expand Down Expand Up @@ -350,10 +359,10 @@ To use in-memory token storage, you don't need to do anything more than
create an Auth class using AuthConfig, for example, for OAuth:

```js
const config = {
const config = new OAuthConfig({
clientId: 'OAUTH_CLIENT_ID',
clientSecret: 'OAUTH_CLIENT_SECRET',
};
});
const oauth = new BoxOAuth({ config: config });
```

Expand All @@ -363,10 +372,10 @@ You can also provide a custom token storage class. All you need to do is create
interface and pass an instance of your class to the AuthConfig constructor.

```js
const config = {
const config = new OAuthConfig({
clientId: 'OAUTH_CLIENT_ID',
clientSecret: 'OAUTH_CLIENT_SECRET',
tokenStorage: new MyCustomTokenStorage(),
};
});
const oauth = new BoxOAuth({ config: config });
```
46 changes: 45 additions & 1 deletion docs/client.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ divided across resource managers.
- [As-User header](#as-user-header)
- [Suppress notifications](#suppress-notifications)
- [Custom headers](#custom-headers)
- [Custom Base URLs](#custom-base-urls)
- [Interceptors](#interceptors)

<!-- END doctoc generated TOC please keep comment here to allow auto update -->

Expand Down Expand Up @@ -62,7 +64,7 @@ Calling the `client.withExtraHeaders()` method creates a new client, leaving the
const newClient = client.withExtraHeaders({ ['customHeader']: 'customValue' });
```

## Custom Base URLs
# Custom Base URLs

You can also specify the custom base URLs, which will be used for API calls made by client.
Calling the `client.withCustomBaseUrls()` method creates a new client, leaving the original client unmodified.
Expand All @@ -74,3 +76,45 @@ const newClient = client.withCustomBaseUrls({
oauth2Url: 'https://account.box.com/api/oauth2',
});
```

# Interceptors

You can specify custom interceptors - methods that will be called just before making a request and right after
receiving a response from the server. Using these function allows you to modify the request payload and response.
Interceptor interface accepts two methods with the following signatures:

```js
beforeRequest(options: FetchOptions): FetchOptions;
afterRequest(response: FetchResponse): FetchResponse;
```

You can apply more than one interceptor to the client by passing a list of interceptors to apply.
Calling the `client.withInterceptors()` method creates a new client, leaving the original client unmodified.

```js
function beforeRequest(options: FetchOptions): FetchOptions {
return {
method: options.method,
headers: options.headers,
params: { ...options.params, ...{ ['fields']: 'role' } },
data: options.data,
fileStream: options.fileStream,
multipartData: options.multipartData,
contentType: options.contentType,
responseFormat: options.responseFormat,
auth: options.auth,
networkSession: options.networkSession,
cancellationToken: options.cancellationToken,
};
}
function emptyAfterRequest(response: FetchResponse): FetchResponse {
return response;
}

const clientWithInterceptor: BoxClient = client.withInterceptors([
{
beforeRequest: beforeRequest,
afterRequest: emptyAfterRequest,
},
]);
```
2 changes: 1 addition & 1 deletion docs/tasks.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ await client.tasks.createTask({
id: file.id,
} satisfies CreateTaskRequestBodyItemField,
message: 'test message',
dueAt: '2035-01-01T00:00:00Z',
dueAt: date,
action: 'review' as CreateTaskRequestBodyActionField,
completionRule: 'all_assignees' as CreateTaskRequestBodyCompletionRuleField,
} satisfies CreateTaskRequestBody);
Expand Down
36 changes: 33 additions & 3 deletions docs/termsOfServiceUserStatuses.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,14 @@ This operation is performed by calling function `getTermsOfServiceUserStatuses`.
See the endpoint docs at
[API Reference](https://developer.box.com/reference/get-terms-of-service-user-statuses/).

_Currently we don't have an example for calling `getTermsOfServiceUserStatuses` in integration tests_
<!-- sample get_terms_of_service_user_statuses -->

```ts
await client.termsOfServiceUserStatuses.getTermsOfServiceUserStatuses({
tosId: tos.id,
userId: user.id,
} satisfies GetTermsOfServiceUserStatusesQueryParams);
```

### Arguments

Expand All @@ -41,7 +48,21 @@ This operation is performed by calling function `createTermsOfServiceStatusForUs
See the endpoint docs at
[API Reference](https://developer.box.com/reference/post-terms-of-service-user-statuses/).

_Currently we don't have an example for calling `createTermsOfServiceStatusForUser` in integration tests_
<!-- sample post_terms_of_service_user_statuses -->

```ts
await client.termsOfServiceUserStatuses.createTermsOfServiceStatusForUser({
tos: {
type: 'terms_of_service' as CreateTermsOfServiceStatusForUserRequestBodyTosTypeField,
id: tos.id,
} satisfies CreateTermsOfServiceStatusForUserRequestBodyTosField,
user: {
type: 'user' as CreateTermsOfServiceStatusForUserRequestBodyUserTypeField,
id: user.id,
} satisfies CreateTermsOfServiceStatusForUserRequestBodyUserField,
isAccepted: false,
} satisfies CreateTermsOfServiceStatusForUserRequestBody);
```

### Arguments

Expand All @@ -67,7 +88,16 @@ This operation is performed by calling function `updateTermsOfServiceStatusForUs
See the endpoint docs at
[API Reference](https://developer.box.com/reference/put-terms-of-service-user-statuses-id/).

_Currently we don't have an example for calling `updateTermsOfServiceStatusForUserById` in integration tests_
<!-- sample put_terms_of_service_user_statuses_id -->

```ts
await client.termsOfServiceUserStatuses.updateTermsOfServiceStatusForUserById(
createdTosUserStatus.id,
{
isAccepted: true,
} satisfies UpdateTermsOfServiceStatusForUserByIdRequestBody
);
```

### Arguments

Expand Down
2 changes: 1 addition & 1 deletion docs/termsOfServices.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ See the endpoint docs at

```ts
await client.termsOfServices.createTermsOfService({
status: 'enabled' as CreateTermsOfServiceRequestBodyStatusField,
status: 'disabled' as CreateTermsOfServiceRequestBodyStatusField,
tosType: 'managed' as CreateTermsOfServiceRequestBodyTosTypeField,
text: 'Test TOS',
} satisfies CreateTermsOfServiceRequestBody);
Expand Down
30 changes: 28 additions & 2 deletions docs/workflows.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,13 @@ This operation is performed by calling function `getWorkflows`.
See the endpoint docs at
[API Reference](https://developer.box.com/reference/get-workflows/).

_Currently we don't have an example for calling `getWorkflows` in integration tests_
<!-- sample get_workflows -->

```ts
await adminClient.workflows.getWorkflows({
folderId: workflowFolderId,
} satisfies GetWorkflowsQueryParams);
```

### Arguments

Expand Down Expand Up @@ -45,7 +51,27 @@ This operation is performed by calling function `startWorkflow`.
See the endpoint docs at
[API Reference](https://developer.box.com/reference/post-workflows-id-start/).

_Currently we don't have an example for calling `startWorkflow` in integration tests_
<!-- sample post_workflows_id_start -->

```ts
await adminClient.workflows.startWorkflow(workflowToRun.id!, {
type: 'workflow_parameters' as StartWorkflowRequestBodyTypeField,
flow: {
type: 'flow',
id: workflowToRun.flows![0].id!,
} satisfies StartWorkflowRequestBodyFlowField,
files: [
{
type: 'file' as StartWorkflowRequestBodyFilesTypeField,
id: workflowFileId,
} satisfies StartWorkflowRequestBodyFilesField,
],
folder: {
type: 'folder' as StartWorkflowRequestBodyFolderTypeField,
id: workflowFolderId,
} satisfies StartWorkflowRequestBodyFolderField,
} satisfies StartWorkflowRequestBody);
```

### Arguments

Expand Down
4 changes: 2 additions & 2 deletions src/auth.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { NetworkSession } from './network';
import { AccessToken } from './schemas.generated.js';
import { NetworkSession } from './network.generated';
import { AccessToken } from './schemas.generated';

export interface Authentication {
retrieveToken: (networkSession?: NetworkSession) => Promise<AccessToken>;
Expand Down
8 changes: 6 additions & 2 deletions src/ccgAuth.generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { PostOAuth2Revoke } from './schemas.generated.js';
import { AccessToken } from './schemas.generated.js';
import { PostOAuth2TokenBoxSubjectTypeField } from './schemas.generated.js';
import { Authentication } from './auth.js';
import { NetworkSession } from './network.js';
import { NetworkSession } from './network.generated.js';
import { TokenStorage } from './tokenStorage.generated.js';
import { InMemoryTokenStorage } from './tokenStorage.generated.js';
import { AuthorizationManager } from './managers/authorization.generated.js';
Expand Down Expand Up @@ -105,7 +105,11 @@ export class BoxCcgAuth implements Authentication {
): Promise<AccessToken> {
const token: undefined | AccessToken = await this.tokenStorage.get();
if (token == void 0) {
throw 'No access token is available. Make an API call to retrieve a token before calling this method.';
throw new Error(
String(
'No access token is available. Make an API call to retrieve a token before calling this method.'
)
);
}
const authManager: AuthorizationManager = !(networkSession == void 0)
? new AuthorizationManager({ networkSession: networkSession })
Expand Down
10 changes: 9 additions & 1 deletion src/client.generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,9 @@ import { WorkflowsManager } from './managers/workflows.generated.js';
import { SignTemplatesManager } from './managers/signTemplates.generated.js';
import { IntegrationMappingsManager } from './managers/integrationMappings.generated.js';
import { Authentication } from './auth.js';
import { NetworkSession } from './network.js';
import { NetworkSession } from './network.generated.js';
import { BaseUrls } from './baseUrls.generated.js';
import { Interceptor } from './interceptors.generated.js';
import { SerializedData } from './json.js';
import { sdIsEmpty } from './json.js';
import { sdIsBoolean } from './json.js';
Expand Down Expand Up @@ -228,6 +229,7 @@ export class BoxClient {
| 'withSuppressedNotifications'
| 'withExtraHeaders'
| 'withCustomBaseUrls'
| 'withInterceptors'
>
| Partial<Pick<BoxClient, 'networkSession'>>
) {
Expand Down Expand Up @@ -543,4 +545,10 @@ export class BoxClient {
networkSession: this.networkSession.withCustomBaseUrls(baseUrls),
});
}
withInterceptors(interceptors: readonly Interceptor[]): BoxClient {
return new BoxClient({
auth: this.auth,
networkSession: this.networkSession.withInterceptors(interceptors),
});
}
}
6 changes: 4 additions & 2 deletions src/developerTokenAuth.generated.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AccessToken } from './schemas.generated.js';
import { Authentication } from './auth.js';
import { NetworkSession } from './network.js';
import { NetworkSession } from './network.generated.js';
export class BoxDeveloperTokenAuth implements Authentication {
readonly token!: string;
constructor(
Expand All @@ -12,6 +12,8 @@ export class BoxDeveloperTokenAuth implements Authentication {
return { accessToken: this.token } satisfies AccessToken;
}
async refreshToken(networkSession?: NetworkSession): Promise<AccessToken> {
throw 'Developer token has expired. Please provide a new one.';
throw new Error(
String('Developer token has expired. Please provide a new one.')
);
}
}
Loading