1- import { get , DefaultHost } from './common' ;
1+ import { Region } from './common' ;
2+ import { ForgeClient , IAuthOptions } from './common' ;
3+
4+ const ReadTokenScopes = [ 'data:read' ] ;
25
36interface IHub {
47 type : string ;
@@ -44,24 +47,17 @@ interface IVersion {
4447 * Client providing access to Autodesk Forge
4548 * {@link https://forge.autodesk.com/en/docs/bim360/v1|BIM360 APIs}.
4649 */
47- export class BIM360Client {
48- private token : string ;
49- private host : string ;
50-
50+ export class BIM360Client extends ForgeClient {
5151 /**
5252 * Initializes new client with specific authentication method.
53- * @param {string } token Authentication token.
53+ * @param {IAuthOptions } auth Authentication object,
54+ * containing either `client_id` and `client_secret` properties (for 2-legged authentication),
55+ * or a single `token` property (for 2-legged or 3-legged authentication with pre-generated access token).
5456 * @param {string } [host="https://developer.api.autodesk.com"] Forge API host.
57+ * @param {Region } [region="US"] Forge availability region ("US" or "EMEA").
5558 */
56- constructor ( token : string , host = DefaultHost ) {
57- this . token = token ;
58- this . host = host ;
59- }
60-
61- // Helper method for GET requests
62- private async _get ( endpoint : string , headers : { [ name : string ] : string } = { } ) {
63- headers [ 'Authorization' ] = 'Bearer ' + this . token ;
64- return get ( this . host + endpoint , headers ) ;
59+ constructor ( auth : IAuthOptions , host ?: string , region ?: Region ) {
60+ super ( '' , auth , host , region ) ;
6561 }
6662
6763 // Hub APIs
@@ -73,7 +69,7 @@ export class BIM360Client {
7369 * @returns {Promise<IHub[]> } List of hubs.
7470 */
7571 async hubs ( ) : Promise < IHub [ ] > {
76- const response = await this . _get ( `/project/v1/hubs` ) ;
72+ const response = await this . get ( `/project/v1/hubs` , { } , ReadTokenScopes ) ;
7773 return response . data ;
7874 }
7975
@@ -84,7 +80,7 @@ export class BIM360Client {
8480 * @returns {Promise<IHub> } Hub or null if there isn't one.
8581 */
8682 async hub ( id : string ) : Promise < IHub > {
87- const response = await this . _get ( `/project/v1/hubs/${ id } ` ) ;
83+ const response = await this . get ( `/project/v1/hubs/${ id } ` , { } , ReadTokenScopes ) ;
8884 return response . data ;
8985 }
9086
@@ -95,7 +91,7 @@ export class BIM360Client {
9591 * @returns {Promise<IProject[]> } List of projects.
9692 */
9793 async projects ( hub : string ) : Promise < IProject [ ] > {
98- const response = await this . _get ( `/project/v1/hubs/${ hub } /projects` ) ;
94+ const response = await this . get ( `/project/v1/hubs/${ hub } /projects` , { } , ReadTokenScopes ) ;
9995 return response . data ;
10096 }
10197
@@ -107,7 +103,7 @@ export class BIM360Client {
107103 * @returns {Promise<IFolder[]> } List of folder records.
108104 */
109105 async folders ( hub : string , project : string ) : Promise < IFolder [ ] > {
110- const response = await this . _get ( `/project/v1/hubs/${ hub } /projects/${ project } /topFolders` ) ;
106+ const response = await this . get ( `/project/v1/hubs/${ hub } /projects/${ project } /topFolders` , { } , ReadTokenScopes ) ;
111107 return response . data ;
112108 }
113109
@@ -119,7 +115,7 @@ export class BIM360Client {
119115 * @returns {Promise<IItem[]> } List of folder contents.
120116 */
121117 async contents ( project : string , folder : string ) : Promise < IItem [ ] > {
122- const response = await this . _get ( `/data/v1/projects/${ project } /folders/${ folder } /contents` ) ;
118+ const response = await this . get ( `/data/v1/projects/${ project } /folders/${ folder } /contents` , { } , ReadTokenScopes ) ;
123119 return response . data ;
124120 }
125121
@@ -131,7 +127,7 @@ export class BIM360Client {
131127 * @returns {Promise<IVersion[]> } List of item versions.
132128 */
133129 async versions ( project : string , item : string ) : Promise < IVersion [ ] > {
134- const response = await this . _get ( `/data/v1/projects/${ project } /items/${ item } /versions` ) ;
130+ const response = await this . get ( `/data/v1/projects/${ project } /items/${ item } /versions` , { } , ReadTokenScopes ) ;
135131 return response . data ;
136132 }
137133
@@ -143,7 +139,7 @@ export class BIM360Client {
143139 * @returns {Promise<IVersion> } Tip version of the item.
144140 */
145141 async tip ( project : string , item : string ) : Promise < IVersion > {
146- const response = await this . _get ( `/data/v1/projects/${ project } /items/${ item } /tip` ) ;
142+ const response = await this . get ( `/data/v1/projects/${ project } /items/${ item } /tip` , { } , ReadTokenScopes ) ;
147143 return response . data ;
148144 }
149145}
0 commit comments