Skip to content

Commit 7c32eaf

Browse files
feat: add find app item for shared link endpoint (box/box-openapi#514) (#545)
1 parent 2edf7cf commit 7c32eaf

6 files changed

+187
-2
lines changed

.codegen.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{ "engineHash": "41feeaa", "specHash": "6782a0d", "version": "1.13.2" }
1+
{ "engineHash": "41feeaa", "specHash": "3dc6f70", "version": "1.13.2" }

docs/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ the SDK are available by topic:
4949
- [Retention policy assignments](retentionPolicyAssignments.md)
5050
- [Search](search.md)
5151
- [Session termination](sessionTermination.md)
52+
- [Shared links app items](sharedLinksAppItems.md)
5253
- [Shared links files](sharedLinksFiles.md)
5354
- [Shared links folders](sharedLinksFolders.md)
5455
- [Shared links web links](sharedLinksWebLinks.md)

docs/sharedLinksAppItems.md

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# SharedLinksAppItemsManager
2+
3+
- [Find app item for shared link](#find-app-item-for-shared-link)
4+
5+
## Find app item for shared link
6+
7+
Returns the app item represented by a shared link.
8+
9+
The link can originate from the current enterprise or another.
10+
11+
This operation is performed by calling function `getSharedItemAppItems`.
12+
13+
See the endpoint docs at
14+
[API Reference](https://developer.box.com/reference/get-shared-items--app-items/).
15+
16+
_Currently we don't have an example for calling `getSharedItemAppItems` in integration tests_
17+
18+
### Arguments
19+
20+
- headersInput `GetSharedItemAppItemsHeadersInput`
21+
- Headers of getSharedItemAppItems method
22+
- optionalsInput `GetSharedItemAppItemsOptionalsInput`
23+
-
24+
25+
### Returns
26+
27+
This function returns a value of type `AppItem`.
28+
29+
Returns a full app item resource if the shared link is valid and
30+
the user has access to it.

docs/sharedLinksWebLinks.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ await userClient.sharedLinksWebLinks.findWebLinkForSharedLink(
4949

5050
This function returns a value of type `WebLink`.
5151

52-
Returns a full file resource if the shared link is valid and
52+
Returns a full web link resource if the shared link is valid and
5353
the user has access to it.
5454

5555
## Get shared link for web link

src/client.generated.ts

+7
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import { SharedLinksFoldersManager } from './managers/sharedLinksFolders.generat
3636
import { WebLinksManager } from './managers/webLinks.generated.js';
3737
import { TrashedWebLinksManager } from './managers/trashedWebLinks.generated.js';
3838
import { SharedLinksWebLinksManager } from './managers/sharedLinksWebLinks.generated.js';
39+
import { SharedLinksAppItemsManager } from './managers/sharedLinksAppItems.generated.js';
3940
import { UsersManager } from './managers/users.generated.js';
4041
import { SessionTerminationManager } from './managers/sessionTermination.generated.js';
4142
import { AvatarsManager } from './managers/avatars.generated.js';
@@ -130,6 +131,7 @@ export class BoxClient {
130131
readonly webLinks: WebLinksManager;
131132
readonly trashedWebLinks: TrashedWebLinksManager;
132133
readonly sharedLinksWebLinks: SharedLinksWebLinksManager;
134+
readonly sharedLinksAppItems: SharedLinksAppItemsManager;
133135
readonly users: UsersManager;
134136
readonly sessionTermination: SessionTerminationManager;
135137
readonly avatars: AvatarsManager;
@@ -206,6 +208,7 @@ export class BoxClient {
206208
| 'webLinks'
207209
| 'trashedWebLinks'
208210
| 'sharedLinksWebLinks'
211+
| 'sharedLinksAppItems'
209212
| 'users'
210213
| 'sessionTermination'
211214
| 'avatars'
@@ -399,6 +402,10 @@ export class BoxClient {
399402
auth: this.auth,
400403
networkSession: this.networkSession,
401404
});
405+
this.sharedLinksAppItems = new SharedLinksAppItemsManager({
406+
auth: this.auth,
407+
networkSession: this.networkSession,
408+
});
402409
this.users = new UsersManager({
403410
auth: this.auth,
404411
networkSession: this.networkSession,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
import { serializeAppItem } from '../schemas/appItem.generated.js';
2+
import { deserializeAppItem } from '../schemas/appItem.generated.js';
3+
import { serializeClientError } from '../schemas/clientError.generated.js';
4+
import { deserializeClientError } from '../schemas/clientError.generated.js';
5+
import { ResponseFormat } from '../networking/fetchOptions.generated.js';
6+
import { AppItem } from '../schemas/appItem.generated.js';
7+
import { ClientError } from '../schemas/clientError.generated.js';
8+
import { BoxSdkError } from '../box/errors.js';
9+
import { Authentication } from '../networking/auth.generated.js';
10+
import { NetworkSession } from '../networking/network.generated.js';
11+
import { FetchOptions } from '../networking/fetchOptions.generated.js';
12+
import { FetchResponse } from '../networking/fetchResponse.generated.js';
13+
import { prepareParams } from '../internal/utils.js';
14+
import { toString } from '../internal/utils.js';
15+
import { ByteStream } from '../internal/utils.js';
16+
import { CancellationToken } from '../internal/utils.js';
17+
import { sdToJson } from '../serialization/json.js';
18+
import { SerializedData } from '../serialization/json.js';
19+
import { sdIsEmpty } from '../serialization/json.js';
20+
import { sdIsBoolean } from '../serialization/json.js';
21+
import { sdIsNumber } from '../serialization/json.js';
22+
import { sdIsString } from '../serialization/json.js';
23+
import { sdIsList } from '../serialization/json.js';
24+
import { sdIsMap } from '../serialization/json.js';
25+
export class GetSharedItemAppItemsOptionals {
26+
readonly cancellationToken?: CancellationToken = void 0;
27+
constructor(
28+
fields: Omit<GetSharedItemAppItemsOptionals, 'cancellationToken'> &
29+
Partial<Pick<GetSharedItemAppItemsOptionals, 'cancellationToken'>>,
30+
) {
31+
if (fields.cancellationToken !== undefined) {
32+
this.cancellationToken = fields.cancellationToken;
33+
}
34+
}
35+
}
36+
export interface GetSharedItemAppItemsOptionalsInput {
37+
readonly cancellationToken?: undefined | CancellationToken;
38+
}
39+
export class GetSharedItemAppItemsHeaders {
40+
/**
41+
* A header containing the shared link and optional password for the
42+
* shared link.
43+
*
44+
* The format for this header is `shared_link=[link]&shared_link_password=[password]` */
45+
readonly boxapi!: string;
46+
/**
47+
* Extra headers that will be included in the HTTP request. */
48+
readonly extraHeaders?: {
49+
readonly [key: string]: undefined | string;
50+
} = {};
51+
constructor(
52+
fields: Omit<GetSharedItemAppItemsHeaders, 'extraHeaders'> &
53+
Partial<Pick<GetSharedItemAppItemsHeaders, 'extraHeaders'>>,
54+
) {
55+
if (fields.boxapi !== undefined) {
56+
this.boxapi = fields.boxapi;
57+
}
58+
if (fields.extraHeaders !== undefined) {
59+
this.extraHeaders = fields.extraHeaders;
60+
}
61+
}
62+
}
63+
export interface GetSharedItemAppItemsHeadersInput {
64+
/**
65+
* A header containing the shared link and optional password for the
66+
* shared link.
67+
*
68+
* The format for this header is `shared_link=[link]&shared_link_password=[password]` */
69+
readonly boxapi: string;
70+
/**
71+
* Extra headers that will be included in the HTTP request. */
72+
readonly extraHeaders?:
73+
| undefined
74+
| {
75+
readonly [key: string]: undefined | string;
76+
};
77+
}
78+
export class SharedLinksAppItemsManager {
79+
readonly auth?: Authentication;
80+
readonly networkSession: NetworkSession = new NetworkSession({});
81+
constructor(
82+
fields: Omit<
83+
SharedLinksAppItemsManager,
84+
'networkSession' | 'getSharedItemAppItems'
85+
> &
86+
Partial<Pick<SharedLinksAppItemsManager, 'networkSession'>>,
87+
) {
88+
if (fields.auth !== undefined) {
89+
this.auth = fields.auth;
90+
}
91+
if (fields.networkSession !== undefined) {
92+
this.networkSession = fields.networkSession;
93+
}
94+
}
95+
/**
96+
* Returns the app item represented by a shared link.
97+
*
98+
* The link can originate from the current enterprise or another.
99+
* @param {GetSharedItemAppItemsHeadersInput} headersInput Headers of getSharedItemAppItems method
100+
* @param {GetSharedItemAppItemsOptionalsInput} optionalsInput
101+
* @returns {Promise<AppItem>}
102+
*/
103+
async getSharedItemAppItems(
104+
headersInput: GetSharedItemAppItemsHeadersInput,
105+
optionalsInput: GetSharedItemAppItemsOptionalsInput = {},
106+
): Promise<AppItem> {
107+
const headers: GetSharedItemAppItemsHeaders =
108+
new GetSharedItemAppItemsHeaders({
109+
boxapi: headersInput.boxapi,
110+
extraHeaders: headersInput.extraHeaders,
111+
});
112+
const optionals: GetSharedItemAppItemsOptionals =
113+
new GetSharedItemAppItemsOptionals({
114+
cancellationToken: optionalsInput.cancellationToken,
115+
});
116+
const cancellationToken: any = optionals.cancellationToken;
117+
const headersMap: {
118+
readonly [key: string]: string;
119+
} = prepareParams({
120+
...{ ['boxapi']: toString(headers.boxapi) as string },
121+
...headers.extraHeaders,
122+
});
123+
const response: FetchResponse =
124+
await this.networkSession.networkClient.fetch(
125+
new FetchOptions({
126+
url: ''.concat(
127+
this.networkSession.baseUrls.baseUrl,
128+
'/2.0/shared_items#app_items',
129+
) as string,
130+
method: 'GET',
131+
headers: headersMap,
132+
responseFormat: 'json' as ResponseFormat,
133+
auth: this.auth,
134+
networkSession: this.networkSession,
135+
cancellationToken: cancellationToken,
136+
}),
137+
);
138+
return {
139+
...deserializeAppItem(response.data!),
140+
rawData: response.data!,
141+
};
142+
}
143+
}
144+
export interface SharedLinksAppItemsManagerInput {
145+
readonly auth?: Authentication;
146+
readonly networkSession?: NetworkSession;
147+
}

0 commit comments

Comments
 (0)