@@ -51,10 +51,9 @@ class Connection {
5151 }
5252
5353 /**
54- * get username.
55- * It's async as in it constructed from access info
56- * @param {* } arrayOfAPICalls
57- * @param {* } progress
54+ * Get username for this connection.
55+ * It's async as it's constructed from access info.
56+ * @returns {Promise<string> } Promise resolving to the username
5857 */
5958 async username ( ) {
6059 const accessInfo = await this . accessInfo ( ) ;
@@ -67,8 +66,9 @@ class Connection {
6766 }
6867
6968 /**
70- * get access info
71- * It's async as it is constructed with get function.
69+ * Get access info for this connection.
70+ * It's async as it is fetched from the API.
71+ * @returns {Promise<AccessInfo> } Promise resolving to the access info
7272 */
7373 async accessInfo ( ) {
7474 return this . get ( 'access-info' , null ) ;
@@ -94,11 +94,12 @@ class Connection {
9494 }
9595
9696 /**
97- * Make one api Api call
98- * @param {string } method - methodId
99- * @param {Object|Array } [params] - the params associated with this methodId
100- * @param {string } [resultKey] - if given, returns the value or throws an error if not present
101- * @throws {Error } if .error is present the response
97+ * Make one API call
98+ * @param {string } method - Method ID (e.g., 'events.get', 'streams.create')
99+ * @param {Object|Array } [params={}] - The params associated with this method
100+ * @param {string } [expectedKey] - If given, returns the value of this key or throws an error if not present
101+ * @returns {Promise<Object> } Promise resolving to the API result or the value of expectedKey
102+ * @throws {Error } If .error is present in the response or expectedKey is missing
102103 */
103104 async apiOne ( method , params = { } , expectedKey ) {
104105 const result = await this . api ( [ { method, params } ] ) ;
@@ -122,9 +123,10 @@ class Connection {
122123
123124 /**
124125 * Revoke : Delete the accessId
125- * - Do not thow error if access is already revoked, just return null;
126- * @param {boolean } [throwOnFail = true] - if set to false do not throw Error on failure
127- * @param {Connection } [usingConnection] - specify which connection issues the revoke, might be necessary when selfRovke
126+ * - Do not throw error if access is already revoked, just return null;
127+ * @param {boolean } [throwOnFail=true] - if set to false do not throw Error on failure
128+ * @param {Connection } [usingConnection] - specify which connection issues the revoke, might be necessary when selfRevoke
129+ * @returns {Promise<Object|null> } Promise resolving to deletion result or null if already revoked/failed
128130 */
129131 async revoke ( throwOnFail = true , usingConnection ) {
130132 usingConnection = usingConnection || this ;
@@ -212,33 +214,38 @@ class Connection {
212214 }
213215
214216 /**
215- * Post to API return results
216- * @param {(Array | Object) } data
217- * @param {string } path
218- * @returns {Promise<Array |Object> } Promise to result.body
217+ * Post to API and return results
218+ * @param {string } path - API path
219+ * @param {(Array | Object) } data - Data to post
220+ * @returns {Promise<Object |Object[] > } Promise to result.body
219221 */
220222 async post ( path , data ) {
221223 const now = getTimestamp ( ) ;
222- const res = await this . postFetch ( path , data ) ;
224+ const res = await this . _postFetch ( path , data ) ;
223225 this . _handleMeta ( res . body , now ) ;
224226 return res . body ;
225227 }
226228
227229 /**
230+ * @private
228231 * Post object as JSON to API
229- * @param {Array | Object } data
230- * @param {string } path
232+ * @param {string } path - API path
233+ * @param {Array | Object } data - Data to post as JSON
234+ * @returns {Promise<{response: Response, body: Object|Object[]}> } Promise to response and body
231235 */
232- async postFetch ( path , data ) {
233- return this . postFetchRaw ( path , JSON . stringify ( data ) , 'application/json' ) ;
236+ async _postFetch ( path , data ) {
237+ return this . _postFetchRaw ( path , JSON . stringify ( data ) , 'application/json' ) ;
234238 }
235239
236240 /**
241+ * @private
237242 * Raw Post to API
238- * @param {Array | Object } data
239- * @param {string } path
243+ * @param {string } path - API path
244+ * @param {any } data - Raw data to post
245+ * @param {string } [contentType] - Content-Type header (optional, allows fetch to set it for FormData)
246+ * @returns {Promise<{response: Response, body: Object|Object[]}> } Promise to response and body
240247 */
241- async postFetchRaw ( path , data , contentType ) {
248+ async _postFetchRaw ( path , data , contentType ) {
242249 const headers = {
243250 Authorization : this . token ,
244251 Accept : 'application/json'
@@ -258,23 +265,26 @@ class Connection {
258265 }
259266
260267 /**
261- * Post to API return results
262- * @param {Object } queryParams
263- * @param {string } path
264- * @returns {Promise<Array |Object> } Promise to result.body
268+ * GET from API and return results
269+ * @param {string } path - API path
270+ * @param {Object } [queryParams] - Query parameters
271+ * @returns {Promise<Object |Object[]> } Promise to result.body
265272 */
266273 async get ( path , queryParams ) {
267274 const now = getTimestamp ( ) ;
268- const res = await this . getFetchRaw ( path , queryParams ) ;
275+ const res = await this . _getFetchRaw ( path , queryParams ) ;
269276 this . _handleMeta ( res . body , now ) ;
270277 return res . body ;
271278 }
272279
273280 /**
274- * @param {Object } queryParams
275- * @param {string } path
281+ * @private
282+ * Raw GET from API
283+ * @param {string } path - API path
284+ * @param {Object } [queryParams={}] - Query parameters
285+ * @returns {Promise<{response: Response, body: Object|Object[]}> } Promise to response and body
276286 */
277- async getFetchRaw ( path , queryParams = { } ) {
287+ async _getFetchRaw ( path , queryParams = { } ) {
278288 path = path || '' ;
279289 let queryStr = '' ;
280290 if ( queryParams && Object . keys ( queryParams ) . length > 0 ) {
@@ -344,7 +354,7 @@ class Connection {
344354 formData . append ( 'file' , fileBlob , fileName ) ;
345355
346356 const now = getTimestamp ( ) ;
347- const { body } = await this . postFetchRaw ( 'events' , formData ) ;
357+ const { body } = await this . _postFetchRaw ( 'events' , formData ) ;
348358 this . _handleMeta ( body , now ) ;
349359 return body ;
350360 }
@@ -375,7 +385,7 @@ class Connection {
375385 */
376386 async createEventWithFormData ( event , formData ) {
377387 formData . append ( 'event' , JSON . stringify ( event ) ) ;
378- const { body } = await this . postFetchRaw ( 'events' , formData ) ;
388+ const { body } = await this . _postFetchRaw ( 'events' , formData ) ;
379389 return body ;
380390 }
381391
@@ -390,9 +400,9 @@ class Connection {
390400 }
391401
392402 /**
393- * API endpoint of this connection
403+ * API endpoint of this connection (includes token if present)
394404 * @readonly
395- * @property {APIEndpoint } deltaTime
405+ * @property {APIEndpoint } apiEndpoint
396406 */
397407 get apiEndpoint ( ) {
398408 return utils . buildAPIEndpoint ( this ) ;
0 commit comments