Skip to content

Commit 65ded8c

Browse files
authored
Merge pull request #453 from contentstack/fix/DR-47
DR - 47 - Fixed all the JSDoc string in the Code
2 parents 9bf6bd3 + 90a0cdd commit 65ded8c

File tree

44 files changed

+872
-555
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+872
-555
lines changed

lib/contentstack.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ import httpClient from './core/contentstackHTTPClient.js'
1818
* const client = contentstack.client()
1919
*
2020
* @param {object} params - Client initialization parameters
21-
* @param {Object=} param.proxy -
21+
* @param {Object=} params.proxy - Proxy configuration object for HTTP requests
22+
* @param {string=} params.region - Region for API endpoint (NA, EU, AU, AZURE_NA, AZURE_EU, GCP_NA, GCP_EU)
23+
* @param {string=} params.feature - Feature identifier for user agent
24+
* @param {string=} params.refreshToken - Refresh token for OAuth authentication
2225
* @prop {string=} params.endpoint - API endpoint that a service will talk to
2326
* @example //Set the `endpoint` to 'https://api.contentstack.io:{port}/{version}'
2427
* import * as contentstack from '@contentstack/management'
@@ -39,7 +42,7 @@ import httpClient from './core/contentstackHTTPClient.js'
3942
* import * as contentstack from '@contentstack/management'
4043
* const client = contentstack.client({ authtoken: 'value' })
4144
*
42-
* @prop {string=} params.early_access - Optional early_access is a token used for early access of new features in CMA requests.
45+
* @prop {Array<string>=} params.early_access - Optional array of early access tokens used for early access of new features in CMA requests.
4346
* @example //Set the `early_access`
4447
* import * as contentstack from '@contentstack/management'
4548
* const client = contentstack.client({ early_access: ['ea1', 'ea2'] })
@@ -158,7 +161,13 @@ import httpClient from './core/contentstackHTTPClient.js'
158161
*
159162
* @prop {string=} params.application - Application name and version e.g myApp/version
160163
* @prop {string=} params.integration - Integration name and version e.g react/version
161-
* @returns Contentstack.Client
164+
* @prop {string=} params.region - API region. Valid values: 'na', 'eu', 'au', 'azure_na', 'azure_eu', 'gcp_na', 'gcp_eu' (default: 'na')
165+
* @example //Set the `region` to 'eu'
166+
* import * as contentstack from '@contentstack/management'
167+
* const client = contentstack.client({ region: 'eu' })
168+
*
169+
* @prop {string=} params.feature - Feature identifier for user agent header
170+
* @returns {ContentstackClient} Instance of ContentstackClient
162171
*/
163172
export function client (params = {}) {
164173
let defaultHostName = getRegionEndpoint('na')

lib/contentstackClient.js

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ export default function contentstackClient ({ http }) {
1919
* @prop {string} parameters.password - password for user to login
2020
* @prop {string} parameters.tfa_token - tfa token for user to login (2FA token)
2121
* @prop {string} parameters.mfaSecret - TOTP secret key for generating 2FA token
22-
* @returns {Promise}
22+
* @param {Object=} params - Optional request parameters
23+
* @returns {Promise<Object>} Promise for login response
2324
* @example
2425
* import * as contentstack from '@contentstack/management'
2526
* const client = contentstack.client()
@@ -59,7 +60,8 @@ export default function contentstackClient ({ http }) {
5960
* The information returned includes details of the stacks owned by and shared with the specified user account.
6061
* @memberof ContentstackClient
6162
* @func getUser
62-
* @returns {Promise}
63+
* @param {Object=} params - Optional request parameters
64+
* @returns {Promise<Object>} Promise for User instance
6365
* @example
6466
* import * as contentstack from '@contentstack/management'
6567
* const client = contentstack.client()
@@ -78,10 +80,11 @@ export default function contentstackClient ({ http }) {
7880
* @description Get Stack instance. A stack is a space that stores the content of a project.
7981
* @memberof ContentstackClient
8082
* @func stack
81-
* @param {String} api_key - Stack API Key
82-
* @param {String} management_token - Management token for Stack.
83-
* @param {String} branch_name - Branch name or alias to access specific branch. Default is master.
84-
* @returns {Stack} Instance of Stack
83+
* @param {Object=} params - Stack initialization parameters
84+
* @prop {String} params.api_key - Stack API Key
85+
* @prop {String} params.management_token - Management token for Stack.
86+
* @prop {String} params.branch_uid - Branch UID or alias to access specific branch. Default is master.
87+
* @returns {Stack} Instance of Stack.
8588
*
8689
* @example
8790
* import * as contentstack from '@contentstack/management'
@@ -121,7 +124,7 @@ export default function contentstackClient ({ http }) {
121124
* @description Organization is the top-level entity in the hierarchy of Contentstack, consisting of stacks and stack resources, and users.
122125
* @memberof ContentstackClient
123126
* @func organization
124-
* @param {String} uid - Organization UID.
127+
* @param {String=} uid - Organization UID. If not provided, returns organization instance for querying all organizations.
125128
* @returns {Organization} Instance of Organization.
126129
*
127130
* @example
@@ -152,7 +155,7 @@ export default function contentstackClient ({ http }) {
152155
* @memberof ContentstackClient
153156
* @param {String} authtoken - Authtoken to logout from.
154157
* @func logout
155-
* @returns {Object} Response object.
158+
* @returns {Promise<Object>} Promise for response object.
156159
*
157160
* @example
158161
* import * as contentstack from '@contentstack/management'
@@ -195,13 +198,13 @@ export default function contentstackClient ({ http }) {
195198
* @memberof ContentstackClient
196199
* @func oauth
197200
* @param {Object} parameters - oauth parameters
198-
* @prop {string} parameters.appId - appId of the application
199-
* @prop {string} parameters.clientId - clientId of the application
200-
* @prop {string} parameters.clientId - clientId of the application
201-
* @prop {string} parameters.responseType - responseType
202-
* @prop {string} parameters.scope - scope
203-
* @prop {string} parameters.clientSecret - clientSecret of the application
204-
* @returns {OAuthHandler} Instance of OAuthHandler
201+
* @prop {string=} parameters.appId - appId of the application (default: '6400aa06db64de001a31c8a9')
202+
* @prop {string=} parameters.clientId - clientId of the application (default: 'Ie0FEfTzlfAHL4xM')
203+
* @prop {string=} parameters.redirectUri - redirect URI for OAuth callback (default: 'http://localhost:8184')
204+
* @prop {string=} parameters.responseType - responseType (default: 'code')
205+
* @prop {string=} parameters.scope - scope
206+
* @prop {string=} parameters.clientSecret - clientSecret of the application
207+
* @returns {OAuthHandler} Instance of OAuthHandler.
205208
* @example
206209
* import * as contentstack from '@contentstack/management'
207210
* const client = contentstack.client()

lib/contentstackCollection.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22
* @namespace ContentstackCollection
33
*/
44
export default class ContentstackCollection {
5+
/**
6+
* Creates a ContentstackCollection instance.
7+
* @param {Object} response - HTTP response object.
8+
* @param {Object} http - HTTP client instance.
9+
* @param {Object=} stackHeaders - Stack headers to include in data.
10+
* @param {Function=} wrapperCollection - Collection wrapper function to transform items.
11+
*/
512
constructor (response, http, stackHeaders = null, wrapperCollection) {
613
const data = response.data || {}
714
if (stackHeaders) {

lib/core/concurrency-queue.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,31 @@ const defaultConfig = {
1818
delayMs: null // Delay in milliseconds before making each request
1919
}
2020

21+
/**
22+
* Creates a concurrency queue manager for Axios requests with retry logic and rate limiting.
23+
* @param {Object} options - Configuration options.
24+
* @param {Object} options.axios - Axios instance to manage.
25+
* @param {Object=} options.config - Queue configuration options.
26+
* @param {number=} options.config.maxRequests - Maximum concurrent requests, defaults to 5.
27+
* @param {number=} options.config.retryLimit - Maximum retry attempts for errors, defaults to 5.
28+
* @param {number=} options.config.retryDelay - Delay between retries in milliseconds, defaults to 300.
29+
* @param {boolean=} options.config.retryOnError - Enable retry on error, defaults to true.
30+
* @param {boolean=} options.config.retryOnNetworkFailure - Enable retry on network failures, defaults to true.
31+
* @param {boolean=} options.config.retryOnDnsFailure - Enable retry on DNS failures, defaults to true.
32+
* @param {boolean=} options.config.retryOnSocketFailure - Enable retry on socket failures, defaults to true.
33+
* @param {boolean=} options.config.retryOnHttpServerError - Enable retry on HTTP 5xx errors, defaults to true.
34+
* @param {number=} options.config.maxNetworkRetries - Maximum network retry attempts, defaults to 3.
35+
* @param {number=} options.config.networkRetryDelay - Base delay for network retries in milliseconds, defaults to 100.
36+
* @param {string=} options.config.networkBackoffStrategy - Backoff strategy ('exponential' or 'fixed'), defaults to 'exponential'.
37+
* @param {number=} options.config.delayMs - Delay before each request in milliseconds.
38+
* @param {Function=} options.config.retryCondition - Custom function to determine if error can be retried.
39+
* @param {Function=} options.config.logHandler - Log handler function.
40+
* @param {Function=} options.config.refreshToken - Token refresh function.
41+
* @param {string=} options.config.authtoken - Auth token.
42+
* @param {string=} options.config.authorization - Authorization token.
43+
* @returns {Object} ConcurrencyQueue instance with request/response interceptors attached to Axios.
44+
* @throws {Error} If axios instance is not provided or configuration is invalid.
45+
*/
2146
export function ConcurrencyQueue ({ axios, config }) {
2247
if (!axios) {
2348
throw Error('Axios instance is not present')

lib/core/contentstackError.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
1-
1+
/**
2+
* Formats and throws an error from an HTTP error response.
3+
* @param {Object} errorResponse - Error response object from HTTP request.
4+
* @param {Object} errorResponse.config - Request configuration object.
5+
* @param {Object} errorResponse.response - HTTP response object.
6+
* @param {number} errorResponse.response.status - HTTP status code.
7+
* @param {string} errorResponse.response.statusText - HTTP status text.
8+
* @param {Object} errorResponse.response.data - Response data containing error details.
9+
* @throws {Error} Formatted error object with request and response details.
10+
*/
211
export default function error (errorResponse) {
312
const config = errorResponse.config
413
const response = errorResponse.response

lib/core/oauthHandler.js

Lines changed: 37 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ import errorFormatter from './contentstackError'
33
/**
44
* @description OAuthHandler class to handle OAuth authorization and token management
55
* @class OAuthHandler
6-
* @param {any} axiosInstance
7-
* @param {any} appId
8-
* @param {any} clientId
9-
* @param {any} redirectUri
10-
* @param {any} responseType='code'
11-
* @param {any} clientSecret
12-
* @param {any} scope=[]
13-
* @returns {OAuthHandler} OAuthHandler instance
6+
* @param {Object} axiosInstance - Axios HTTP client instance.
7+
* @param {string=} appId - Application ID, defaults to '6400aa06db64de001a31c8a9'.
8+
* @param {string=} clientId - Client ID, defaults to 'Ie0FEfTzlfAHL4xM'.
9+
* @param {string=} redirectUri - Redirect URI for OAuth callback, defaults to 'http://localhost:8184'.
10+
* @param {string=} clientSecret - Client secret. If provided, PKCE will be skipped.
11+
* @param {string=} responseType - Response type, defaults to 'code'.
12+
* @param {Array<string>=} scope - OAuth scope array, defaults to [].
13+
* @returns {OAuthHandler} OAuthHandler instance.
1414
* @example
1515
* import * as contentstack from '@contentstack/management'
1616
* const client = contentstack.client();
@@ -80,7 +80,8 @@ export default class OAuthHandler {
8080
* @description Authorize the user by redirecting to the OAuth provider's authorization page
8181
* @memberof OAuthHandler
8282
* @func authorize
83-
* @returns {any} Authorization URL
83+
* @async
84+
* @returns {Promise<string>} Promise that resolves to authorization URL
8485
* @example
8586
* import * as contentstack from '@contentstack/management'
8687
* const client = contentstack.client();
@@ -114,8 +115,9 @@ export default class OAuthHandler {
114115
* @description Exchange the authorization code for an access token
115116
* @memberof OAuthHandler
116117
* @func exchangeCodeForToken
117-
* @param {any} code - Authorization code received from the OAuth provider
118-
* @returns {any} Token data
118+
* @async
119+
* @param {string} code - Authorization code received from the OAuth provider
120+
* @returns {Promise<Object>} Promise that resolves to token data object
119121
* @example
120122
* import * as contentstack from '@contentstack/management'
121123
* const client = contentstack.client();
@@ -155,9 +157,10 @@ export default class OAuthHandler {
155157
* @description Refreshes the access token using the provided refresh token or the one stored in the axios instance.
156158
* @memberof OAuthHandler
157159
* @func refreshAccessToken
160+
* @async
158161
* @param {string|null} [providedRefreshToken=null] - The refresh token to use for refreshing the access token. If not provided, the stored refresh token will be used.
159-
* @returns {Promise<Object>} - A promise that resolves to the response data containing the new access token, refresh token, and expiry time.
160-
* @throws {Error} - Throws an error if no refresh token is available or if the token refresh request fails.
162+
* @returns {Promise<Object>} A promise that resolves to the response data containing the new access token, refresh token, and expiry time.
163+
* @throws {Error} Throws an error if no refresh token is available or if the token refresh request fails.
161164
* @example
162165
* import * as contentstack from '@contentstack/management'
163166
* const client = contentstack.client();
@@ -196,8 +199,9 @@ export default class OAuthHandler {
196199
* @description Logs out the user by revoking the OAuth app authorization
197200
* @memberof OAuthHandler
198201
* @func logout
199-
* @returns {Promise<string>} - A promise that resolves to a success message if the logout was successful.
200-
* @throws {Error} - Throws an error if the logout request fails.
202+
* @async
203+
* @returns {Promise<string>} A promise that resolves to a success message if the logout was successful.
204+
* @throws {Error} Throws an error if the logout request fails.
201205
* @example
202206
* import * as contentstack from '@contentstack/management'
203207
* const client = contentstack.client();
@@ -219,7 +223,7 @@ export default class OAuthHandler {
219223
* @description Get the current access token
220224
* @memberof OAuthHandler
221225
* @func getAccessToken
222-
* @returns {any}
226+
* @returns {string|undefined} Current access token or undefined if not set.
223227
* @example
224228
* import * as contentstack from '@contentstack/management'
225229
* const client = contentstack.client();
@@ -294,7 +298,8 @@ export default class OAuthHandler {
294298
* @description Set the access token in the axios instance
295299
* @memberof OAuthHandler
296300
* @func setAccessToken
297-
* @param {*} token
301+
* @param {string} token - Access token to set.
302+
* @throws {Error} Throws an error if token is not provided.
298303
* @example
299304
* import * as contentstack from '@contentstack/management'
300305
* const client = contentstack.client();
@@ -312,7 +317,8 @@ export default class OAuthHandler {
312317
* @description Set the refresh token in the axios instance
313318
* @memberof OAuthHandler
314319
* @func setRefreshToken
315-
* @param {*} token
320+
* @param {string} token - Refresh token to set.
321+
* @throws {Error} Throws an error if token is not provided.
316322
* @example
317323
* import * as contentstack from '@contentstack/management'
318324
* const client = contentstack.client();
@@ -330,7 +336,8 @@ export default class OAuthHandler {
330336
* @description Set the organization UID in the axios instance
331337
* @memberof OAuthHandler
332338
* @func setOrganizationUID
333-
* @param {*} organizationUID
339+
* @param {string} organizationUID - Organization UID to set.
340+
* @throws {Error} Throws an error if organizationUID is not provided.
334341
* @example
335342
* import * as contentstack from '@contentstack/management'
336343
* const client = contentstack.client();
@@ -348,7 +355,8 @@ export default class OAuthHandler {
348355
* @description Set the user UID in the axios instance
349356
* @memberof OAuthHandler
350357
* @func setUserUID
351-
* @param {*} userUID
358+
* @param {string} userUID - User UID to set.
359+
* @throws {Error} Throws an error if userUID is not provided.
352360
* @example
353361
* import * as contentstack from '@contentstack/management'
354362
* const client = contentstack.client();
@@ -366,7 +374,8 @@ export default class OAuthHandler {
366374
* @description Set the token expiry time in the axios instance
367375
* @memberof OAuthHandler
368376
* @func setTokenExpiryTime
369-
* @param {*} expiryTime
377+
* @param {number} expiryTime - Token expiry time (timestamp in milliseconds).
378+
* @throws {Error} Throws an error if expiryTime is not provided.
370379
* @example
371380
* import * as contentstack from '@contentstack/management'
372381
* const client = contentstack.client();
@@ -386,8 +395,8 @@ export default class OAuthHandler {
386395
* @func handleRedirect
387396
* @async
388397
* @param {string} url - The URL to handle after the OAuth authorization
389-
* @returns {Promise<void>} - A promise that resolves if the redirect URL is successfully handled
390-
* @throws {Error} - Throws an error if the authorization code is not found in the redirect URL
398+
* @returns {Promise<void>} A promise that resolves if the redirect URL is successfully handled
399+
* @throws {Error} Throws an error if the authorization code is not found in the redirect URL
391400
* @example
392401
* import * as contentstack from '@contentstack/management'
393402
* const client = contentstack.client();
@@ -413,7 +422,8 @@ export default class OAuthHandler {
413422
* @description Get the OAuth app authorization for the current user
414423
* @memberof OAuthHandler
415424
* @func getOauthAppAuthorization
416-
* @returns {any}
425+
* @async
426+
* @returns {Promise<string>} Promise that resolves to authorization UID
417427
*/
418428
async getOauthAppAuthorization () {
419429
const headers = {
@@ -448,8 +458,9 @@ export default class OAuthHandler {
448458
* @description Revoke the OAuth app authorization for the current user
449459
* @memberof OAuthHandler
450460
* @func revokeOauthAppAuthorization
451-
* @param {any} authorizationId
452-
* @returns {any}
461+
* @async
462+
* @param {string} authorizationId - Authorization ID to revoke
463+
* @returns {Promise<Object>} Promise that resolves to response data
453464
*/
454465
async revokeOauthAppAuthorization (authorizationId) {
455466
if (authorizationId?.length > 1) {

0 commit comments

Comments
 (0)