Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
### Version: 4.10.4
#### Date: Dec-08-2025
Feat: Improved error messages

### Version: 4.10.3
#### Date: Nov-12-2025
fix: reverts the endpoints helper method integration

### Version: 4.10.2
#### Date: Nov-12-2025
Enhancement: Added logHandler interceptors for request and response logging
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@contentstack/delivery-sdk",
"version": "4.10.2",
"version": "4.10.4",
"type": "module",
"license": "MIT",
"main": "./dist/legacy/index.cjs",
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ export type { ImageTransform } from './lib/image-transform';
export type { AssetQuery } from './lib/asset-query';
export type { TaxonomyQuery } from './lib/taxonomy-query';
export type { ContentTypeQuery } from './lib/contenttype-query';
export { ErrorMessages, ErrorCode } from './lib/error-messages';

export default contentstack;
12 changes: 6 additions & 6 deletions src/lib/asset-query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,14 @@ export class AssetQuery extends BaseQuery {

/**
* @method includeMetadata
* @memberof Entries
* @description Include the metadata for getting metadata content for the entry.
* @returns {Entries}
* @memberof AssetQuery
* @description Include the metadata for getting metadata content for the asset.
* @returns {AssetQuery}
* @example
* import contentstack from '@contentstack/delivery-sdk'
*
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const result = await stack.asset().includeMetadata().fetch();
* const result = await stack.asset().includeMetadata().find();
*/
includeMetadata(): AssetQuery {
this._queryParams.include_metadata = 'true';
Expand Down Expand Up @@ -128,14 +128,14 @@ export class AssetQuery extends BaseQuery {
}
/**
* @method query
* @memberof Query
* @memberof AssetQuery
* @description Fetches the asset data on the basis of the query
* @returns {Query}
* @example
* import contentstack from '@contentstack/delivery-sdk'
*
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const result = await stack.asset().query().where('fieldUid', queryOperators, 'value').find();
* const result = await stack.asset().query().where('fieldUid', QueryOperation.EQUALS, 'value').find();
*/
query() {
return new Query(this._client, this._parameters, this._queryParams);
Expand Down
10 changes: 5 additions & 5 deletions src/lib/asset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ export class Asset {

/**
* @method includeMetadata
* @memberof Entries
* @description Include the metadata for getting metadata content for the entry.
* @returns {Entries}
* @memberof Asset
* @description Include the metadata for getting metadata content for the asset.
* @returns {Asset}
* @example
* import contentstack from '@contentstack/delivery-sdk'
*
Expand Down Expand Up @@ -115,7 +115,7 @@ export class Asset {
/**
* @method locale
* @memberof Asset
* @description The assets published in the locale will be fetched
* @description The asset published in the locale will be fetched
* @returns {Asset}
* @example
* import contentstack from '@contentstack/delivery-sdk'
Expand All @@ -133,7 +133,7 @@ export class Asset {
* @method fetch
* @memberof Asset
* @description Fetches the asset data on the basis of the asset uid
* @returns {Asset}
* @returns {Promise<T>} Promise that resolves to the asset data
* @example
* import contentstack from '@contentstack/delivery-sdk'
*
Expand Down
17 changes: 9 additions & 8 deletions src/lib/base-query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export class BaseQuery extends Pagination {
* const query = stack.contentType("contentTypeUid").entry().query();
* const result = await query.orderByAscending("field_uid").find()
* // OR
* const asset = await stack.asset().orderByAscending().find()
* const asset = await stack.asset().orderByAscending("field_uid").find()
*
* @returns {Query}
*/
Expand All @@ -72,7 +72,7 @@ export class BaseQuery extends Pagination {
* const query = stack.contentType("contentTypeUid").entry().query();
* const result = await query.orderByDescending("field_uid").find()
* // OR
* const asset = await stack.asset().orderByDescending().find()
* const asset = await stack.asset().orderByDescending("field_uid").find()
*
* @returns {Query}
*/
Expand All @@ -91,7 +91,7 @@ export class BaseQuery extends Pagination {
*
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const query = stack.contentType("contentTypeUid").entry().query();
* const result = await query.limit("limit_value").find()
* const result = await query.limit(10).find()
* // OR
* const asset = await stack.asset().limit(5).find()
*
Expand All @@ -112,7 +112,7 @@ export class BaseQuery extends Pagination {
*
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const query = stack.contentType("contentTypeUid").entry().query();
* const result = await query.skip("skip_value").find()
* const result = await query.skip(10).find()
* // OR
* const asset = await stack.asset().skip(5).find()
*
Expand Down Expand Up @@ -191,9 +191,10 @@ export class BaseQuery extends Pagination {

/**
* @method find
* @memberof AssetQuery
* @description The assets of the stack will be fetched
* @returns {Collection}
* @memberof BaseQuery
* @description Fetches the data based on the query parameters
* @param {boolean} encode - Whether to encode query parameters
* @returns {Promise<FindResponse<T>>} Promise that resolves to the find response
* @example
* import contentstack from '@contentstack/delivery-sdk'
*
Expand All @@ -208,7 +209,7 @@ export class BaseQuery extends Pagination {
* import contentstack from '@contentstack/delivery-sdk'
*
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const result = await stack.asset(asset_uid).fetch();
* const result = await stack.contentType("contentTypeUid").entry().query().find();
*/

async find<T>(encode: boolean = false): Promise<FindResponse<T>> {
Expand Down
10 changes: 10 additions & 0 deletions src/lib/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,16 @@ function generateEnhancedCacheKey(originalKey: string, contentTypeUid?: string,
return cacheKey;
}

/**
* Handles cache requests based on the cache policy
* @param {CacheOptions} cacheOptions - Cache configuration options
* @param {string} apiKey - API key for cache key generation
* @param {Function} defaultAdapter - Default axios adapter function
* @param {Function} resolve - Promise resolve function
* @param {Function} reject - Promise reject function
* @param {object} config - Request configuration object
* @returns {Promise} Resolves or rejects based on cache policy and API response
*/
export async function handleRequest(
cacheOptions: CacheOptions,
apiKey: string,
Expand Down
9 changes: 6 additions & 3 deletions src/lib/content-type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,16 @@ export class ContentType {
/**
* @method entry
* @memberof ContentType
* @description Creates entry object of the passed entry uid.
* @returns {Entry}
* @description Creates entry object of the passed entry uid, or entries query object if no uid is provided.
* @param {string} [uid] - Optional entry UID. If provided, returns a single Entry instance. If omitted, returns Entries query object.
* @returns {Entry | Entries} Entry instance if uid is provided, otherwise Entries query object
* @example
* import contentstack from '@contentstack/delivery-sdk'
*
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const entry = stack.contentType("contentTypeUid").entry("entryUid");
* // OR
* const entries = stack.contentType("contentTypeUid").entry();
*/
entry(uid: string): Entry;
entry(): Entries;
Expand All @@ -41,7 +44,7 @@ export class ContentType {
* @method fetch
* @memberof ContentType
* @description Fetches the contentType data on the basis of the contentType uid
* @returns {ContentType}
* @returns {Promise<T>} Promise that resolves to the content type data
* @example
* import contentstack from '@contentstack/delivery-sdk'
*
Expand Down
4 changes: 2 additions & 2 deletions src/lib/contentstack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ let version = '{{VERSION}}';
* @memberof Contentstack
* @description Creates a stack instance
* @param {StackConfig} config - config object for stack with apiKey, deliveryToken and environment as required fields
*
* @returns {StackClass} Stack instance
* @example
* import contentstack from '@contentstack/delivery-sdk'
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
Expand All @@ -30,7 +30,7 @@ let version = '{{VERSION}}';
* policy: Policy.CACHE_THEN_NETWORK,
* storeType: 'localStorage'
* }
* }
* });
*/
// eslint-disable-next-line @typescript-eslint/naming-convention
export function stack(config: StackConfig): StackClass {
Expand Down
4 changes: 2 additions & 2 deletions src/lib/contenttype-query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export class ContentTypeQuery {
/**
* @method includeGlobalFieldSchema
* @memberof ContentTypeQuery
* @description The assets published in the locale will be fetched
* @description Includes the global field schema in the content type response
* @returns {ContentTypeQuery}
* @example
* import contentstack from '@contentstack/delivery-sdk'
Expand All @@ -31,7 +31,7 @@ export class ContentTypeQuery {
* @method find
* @memberof ContentTypeQuery
* @description Fetches all contentTypes of the stack
* @returns {ContentTypeQuery}
* @returns {Promise<FindResponse<T>>} Promise that resolves to the find response containing content types
* @example
* import contentstack from '@contentstack/delivery-sdk'
*
Expand Down
52 changes: 30 additions & 22 deletions src/lib/entries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Query } from './query';
import { BaseQuery } from './base-query';
import { FindResponse } from './types';
import { encodeQueryParams } from './utils';
import { ErrorMessages } from './error-messages';

export class Entries extends BaseQuery {
private _contentTypeUid: string;
Expand Down Expand Up @@ -62,13 +63,13 @@ export class Entries extends BaseQuery {
/**
* @method includeContentType
* @memberof Entries
* @description IInclude the details of the content type along with the entries details
* @description Include the details of the content type along with the entries details
* @returns {Entries}
* @example
* import contentstack from '@contentstack/delivery-sdk'
*
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const result = await stack.contentType(contentType_uid).entry().includeContentType().fetch();
* const result = await stack.contentType(contentType_uid).entry().includeContentType().find();
*/
includeContentType(): Entries {
this._queryParams.include_content_type = 'true';
Expand All @@ -85,7 +86,7 @@ export class Entries extends BaseQuery {
* import contentstack from '@contentstack/delivery-sdk'
*
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const result = await stack.contentType(contentType_uid).entry().includeEmbeddedItems().fetch();
* const result = await stack.contentType(contentType_uid).entry().includeEmbeddedItems().find();
*/
includeEmbeddedItems(): Entries {
this._queryParams['include_embedded_items[]'] = 'BASE';
Expand Down Expand Up @@ -134,9 +135,11 @@ export class Entries extends BaseQuery {
* you need to use the include[] parameter and specify the UID of the reference field as value.
* This function sets the include parameter to a reference field UID in the API request.
* @example
* const stack = contentstack.stack("apiKey", "deliveryKey", "environment");
* const query = stack.contentType("contentTypeUid").entry().includeReference("brand")
* const res = await query.find()
* import contentstack from '@contentstack/delivery-sdk'
*
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const entries = stack.contentType("contentTypeUid").entry().includeReference("brand")
* const result = await entries.find()
*
* @param {string} referenceFieldUid - UID of the reference field to include.
* @returns {Entries} - Returns the Entries instance for chaining.
Expand All @@ -150,7 +153,7 @@ export class Entries extends BaseQuery {
(this._queryParams['include[]'] as string[]).push(...(Array.isArray(value) ? value : [value]));
});
} else {
console.error("Argument should be a String or an Array.");
console.error(ErrorMessages.INVALID_ARGUMENT_STRING_OR_ARRAY);
}
return this;
}
Expand All @@ -160,9 +163,11 @@ export class Entries extends BaseQuery {
* @memberof Entries
* @description This method also includes the content type UIDs of the referenced entries returned in the response.
* @example
* const stack = contentstack.stack("apiKey", "deliveryKey", "environment");
* const query = stack.contentType("contentTypeUid").entry().includeReferenceContentTypeUID()
* const res = await query.find()
* import contentstack from '@contentstack/delivery-sdk'
*
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const entries = stack.contentType("contentTypeUid").entry().includeReferenceContentTypeUID()
* const result = await entries.find()
*
* @returns {Entries} - Returns the Entries instance for chaining.
*/
Expand All @@ -175,11 +180,13 @@ export class Entries extends BaseQuery {
/**
* @method includeSchema
* @memberof Entries
* @description This method also includes the content type UIDs of the referenced entries returned in the response.
* @description Includes the schema of the content type along with the entries details.
* @example
* const stack = contentstack.stack("apiKey", "deliveryKey", "environment");
* const query = stack.contentType("contentTypeUid").entry().includeSchema()
* const res = await query.find()
* import contentstack from '@contentstack/delivery-sdk'
*
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const entries = stack.contentType("contentTypeUid").entry().includeSchema()
* const result = await entries.find()
*
* @returns {Entries} - Returns the Entries instance for chaining.
*/
Expand All @@ -191,9 +198,9 @@ export class Entries extends BaseQuery {

/**
* @method locale
* @memberof Entry
* @description The assets published in the locale will be fetched
* @returns {Entry}
* @memberof Entries
* @description The entries published in the locale will be fetched
* @returns {Entries}
* @example
* import contentstack from '@contentstack/delivery-sdk'
*
Expand Down Expand Up @@ -235,13 +242,14 @@ export class Entries extends BaseQuery {
/**
* @method query
* @memberof Entries
* @description Fetches the Entry data on the basis of the asset uid
* @returns {Collection}
* @description Creates a query object for filtering entries
* @param {object} queryObj - Optional query object to initialize the query
* @returns {Query} Query instance for chaining query methods
* @example
* import contentstack from '@contentstack/delivery-sdk'
*
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const result = await stack.contentType("contentTypeUid").entry().query();
* const query = stack.contentType("contentTypeUid").entry().query();
*/
query(queryObj?: { [key: string]: any }) {
if (queryObj) return new Query(this._client, this._parameters, this._queryParams, this._variants, this._contentTypeUid, queryObj);
Expand All @@ -251,9 +259,9 @@ export class Entries extends BaseQuery {

/**
* @method variants
* @memberof Entry
* @memberof Entries
* @description The variant header will be added to axios client
* @returns {Entry}
* @returns {Entries}
* @example
* import contentstack from '@contentstack/delivery-sdk'
*
Expand Down
Loading