|
| 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