From 6ad194bfa19fa20cd71384f7365b010ab4b4cf66 Mon Sep 17 00:00:00 2001 From: reeshika-h Date: Mon, 24 Nov 2025 10:12:21 +0530 Subject: [PATCH 1/7] Improve error messages for invalid arguments and keys in Entries, Entry, and Query classes for better clarity and user guidance. --- src/lib/entries.ts | 2 +- src/lib/entry.ts | 2 +- src/lib/query.ts | 48 ++++++++++++++-------------- src/persistance/persistance-store.ts | 2 +- 4 files changed, 27 insertions(+), 27 deletions(-) diff --git a/src/lib/entries.ts b/src/lib/entries.ts index c7727d3..4b38508 100644 --- a/src/lib/entries.ts +++ b/src/lib/entries.ts @@ -150,7 +150,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("Invalid argument. Provide a string or an array and try again."); } return this; } diff --git a/src/lib/entry.ts b/src/lib/entry.ts index 077c8cd..3104b69 100644 --- a/src/lib/entry.ts +++ b/src/lib/entry.ts @@ -112,7 +112,7 @@ export class Entry { (this._queryParams['include[]'] as string[]).push(...(Array.isArray(value) ? value : [value])); }); } else { - console.error("Argument should be a String or an Array."); + console.error("Invalid argument. Provide a string or an array and try again."); } return this; } diff --git a/src/lib/query.ts b/src/lib/query.ts index 96ecc1d..b69f744 100644 --- a/src/lib/query.ts +++ b/src/lib/query.ts @@ -73,7 +73,7 @@ export class Query extends BaseQuery { additionalData?: object ): Query { if (!this.isValidAlphanumeric(fieldUid)) { - console.error("Invalid fieldUid:", fieldUid); + console.error("Invalid fieldUid. Provide an alphanumeric field UID and try again."); return this; } if (queryOperation == QueryOperation.EQUALS) { @@ -102,7 +102,7 @@ export class Query extends BaseQuery { */ regex(fieldUid: string, regexPattern: string, options?: string): Query { if (!this.isValidAlphanumeric(fieldUid)) { - console.error("Invalid fieldUid:", fieldUid); + console.error("Invalid fieldUid. Provide an alphanumeric field UID and try again."); return this; } if (!this.isValidRegexPattern(regexPattern)) { @@ -226,11 +226,11 @@ export class Query extends BaseQuery { */ containedIn(key: string, value: (string | number | boolean)[]): Query { if (!this.isValidAlphanumeric(key)) { - console.error("Invalid key:", key); + console.error("Invalid key. Provide an alphanumeric key and try again."); return this; } if (!this.isValidValue(value)) { - console.error("Invalid value:", value); + console.error("Invalid value. Provide an array of strings, numbers, or booleans and try again."); return this; } this._parameters[key] = { '$in': value }; @@ -252,11 +252,11 @@ export class Query extends BaseQuery { */ notContainedIn(key: string, value: (string | number | boolean)[]): Query { if (!this.isValidAlphanumeric(key)) { - console.error("Invalid key:", key); + console.error("Invalid key. Provide an alphanumeric key and try again."); return this; } if (!this.isValidValue(value)) { - console.error("Invalid value:", value); + console.error("Invalid value. Provide an array of strings, numbers, or booleans and try again."); return this; } this._parameters[key] = { '$nin': value }; @@ -278,7 +278,7 @@ export class Query extends BaseQuery { */ exists(key: string): Query { if (!this.isValidAlphanumeric(key)) { - console.error("Invalid key:", key); + console.error("Invalid key. Provide an alphanumeric key and try again."); return this; } this._parameters[key] = { '$exists': true }; @@ -300,7 +300,7 @@ export class Query extends BaseQuery { */ notExists(key: string): Query { if (!this.isValidAlphanumeric(key)) { - console.error("Invalid key:", key); + console.error("Invalid key. Provide an alphanumeric key and try again."); return this; } this._parameters[key] = { '$exists': false }; @@ -367,11 +367,11 @@ export class Query extends BaseQuery { */ equalTo(key: string, value: string | number | boolean): Query { if (!this.isValidAlphanumeric(key)) { - console.error("Invalid key:", key); + console.error("Invalid key. Provide an alphanumeric key and try again."); return this; } if (typeof value !== 'string' && typeof value !== 'number') { - console.error("Invalid value (expected string or number):", value); + console.error("Invalid value. Provide a string or number and try again."); return this; } this._parameters[key] = value; @@ -392,11 +392,11 @@ export class Query extends BaseQuery { */ notEqualTo(key: string, value: string | number | boolean): Query { if (!this.isValidAlphanumeric(key)) { - console.error("Invalid key:", key); + console.error("Invalid key. Provide an alphanumeric key and try again."); return this; } if (typeof value !== 'string' && typeof value !== 'number') { - console.error("Invalid value (expected string or number):", value); + console.error("Invalid value. Provide a string or number and try again."); return this; } this._parameters[key] = { '$ne': value }; @@ -418,7 +418,7 @@ export class Query extends BaseQuery { */ referenceIn(key: string, query: Query): Query { if (!this.isValidAlphanumeric(key)) { - console.error("Invalid key:", key); + console.error("Invalid key. Provide an alphanumeric key and try again."); return this; } this._parameters[key] = { '$in_query': query._parameters } @@ -440,7 +440,7 @@ export class Query extends BaseQuery { */ referenceNotIn(key: string, query: Query): Query { if (!this.isValidAlphanumeric(key)) { - console.error("Invalid key:", key); + console.error("Invalid key. Provide an alphanumeric key and try again."); return this; } this._parameters[key] = { '$nin_query': query._parameters } @@ -462,7 +462,7 @@ export class Query extends BaseQuery { */ tags(values: (string | number | boolean)[]): Query { if (!this.isValidValue(values)) { - console.error("Invalid value:", values); + console.error("Invalid value. Provide an array of strings, numbers, or booleans and try again."); return this; } this._parameters['tags'] = values; @@ -484,7 +484,7 @@ export class Query extends BaseQuery { */ search(key: string): Query { if (!this.isValidAlphanumeric(key)) { - console.error("Invalid key:", key); + console.error("Invalid key. Provide an alphanumeric key and try again."); return this; } this._queryParams['typeahead'] = key @@ -506,11 +506,11 @@ export class Query extends BaseQuery { */ lessThan(key: string, value: (string | number)): Query { if (!this.isValidAlphanumeric(key)) { - console.error("Invalid key:", key); + console.error("Invalid key. Provide an alphanumeric key and try again."); return this; } if (typeof value !== 'string' && typeof value !== 'number') { - console.error("Invalid value (expected string or number):", value); + console.error("Invalid value. Provide a string or number and try again."); return this; } @@ -533,11 +533,11 @@ export class Query extends BaseQuery { */ lessThanOrEqualTo(key: string, value: (string | number)): Query { if (!this.isValidAlphanumeric(key)) { - console.error("Invalid key:", key); + console.error("Invalid key. Provide an alphanumeric key and try again."); return this; } if (typeof value !== 'string' && typeof value !== 'number') { - console.error("Invalid value (expected string or number):", value); + console.error("Invalid value. Provide a string or number and try again."); return this; } this._parameters[key] = { '$lte': value }; @@ -559,11 +559,11 @@ export class Query extends BaseQuery { */ greaterThan(key: string, value: (string | number)): Query { if (!this.isValidAlphanumeric(key)) { - console.error("Invalid key:", key); + console.error("Invalid key. Provide an alphanumeric key and try again."); return this; } if (typeof value !== 'string' && typeof value !== 'number') { - console.error("Invalid value (expected string or number):", value); + console.error("Invalid value. Provide a string or number and try again."); return this; } this._parameters[key] = { '$gt': value }; @@ -585,11 +585,11 @@ export class Query extends BaseQuery { */ greaterThanOrEqualTo(key: string, value: (string | number)): Query { if (!this.isValidAlphanumeric(key)) { - console.error("Invalid key:", key); + console.error("Invalid key. Provide an alphanumeric key and try again."); return this; } if (typeof value !== 'string' && typeof value !== 'number') { - console.error("Invalid value (expected string or number):", value); + console.error("Invalid value. Provide a string or number and try again."); return this; } this._parameters[key] = { '$gte': value }; diff --git a/src/persistance/persistance-store.ts b/src/persistance/persistance-store.ts index 008e569..b76e751 100644 --- a/src/persistance/persistance-store.ts +++ b/src/persistance/persistance-store.ts @@ -33,7 +33,7 @@ export class PersistanceStore { break; case 'customStorage': if (!store) { - throw new TypeError('StorageType `customStorage` should have `storage`.'); + throw new TypeError('Missing storage for customStorage. Provide a storage object with get, set, and remove methods and try again.'); } else { this.store = store; } From 704a2279dfe0aed0efeb009e205995ebf0e3b027 Mon Sep 17 00:00:00 2001 From: reeshika-h Date: Mon, 24 Nov 2025 10:47:07 +0530 Subject: [PATCH 2/7] Refactor error handling in Entries, Entry, and Query classes to utilize centralized error messages for improved consistency and clarity. --- src/index.ts | 1 + src/lib/entries.ts | 3 +- src/lib/entry.ts | 3 +- src/lib/error-messages.ts | 43 +++++++++++++++ src/lib/query.ts | 55 ++++++++++--------- src/persistance/persistance-store.ts | 3 +- .../content-validation-comprehensive.spec.ts | 13 +++-- .../query-optimization-comprehensive.spec.ts | 22 ++++---- test/unit/query.spec.ts | 51 ++++++++--------- 9 files changed, 122 insertions(+), 72 deletions(-) create mode 100644 src/lib/error-messages.ts diff --git a/src/index.ts b/src/index.ts index d108292..9ffa67e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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; diff --git a/src/lib/entries.ts b/src/lib/entries.ts index 4b38508..30f5e44 100644 --- a/src/lib/entries.ts +++ b/src/lib/entries.ts @@ -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; @@ -150,7 +151,7 @@ export class Entries extends BaseQuery { (this._queryParams['include[]'] as string[]).push(...(Array.isArray(value) ? value : [value])); }); } else { - console.error("Invalid argument. Provide a string or an array and try again."); + console.error(ErrorMessages.INVALID_ARGUMENT_STRING_OR_ARRAY); } return this; } diff --git a/src/lib/entry.ts b/src/lib/entry.ts index 3104b69..086b9e7 100644 --- a/src/lib/entry.ts +++ b/src/lib/entry.ts @@ -1,4 +1,5 @@ import { AxiosInstance, getData } from '@contentstack/core'; +import { ErrorMessages } from './error-messages'; interface EntryResponse { entry: T; @@ -112,7 +113,7 @@ export class Entry { (this._queryParams['include[]'] as string[]).push(...(Array.isArray(value) ? value : [value])); }); } else { - console.error("Invalid argument. Provide a string or an array and try again."); + console.error(ErrorMessages.INVALID_ARGUMENT_STRING_OR_ARRAY); } return this; } diff --git a/src/lib/error-messages.ts b/src/lib/error-messages.ts new file mode 100644 index 0000000..acf92bb --- /dev/null +++ b/src/lib/error-messages.ts @@ -0,0 +1,43 @@ +/** + * Centralized error messages for the Contentstack SDK + * This file contains all user-facing error messages used throughout the SDK + */ + +export const ErrorMessages = { + // Field/Key validation errors + INVALID_FIELD_UID: 'Invalid fieldUid. Provide an alphanumeric field UID and try again.', + INVALID_KEY: 'Invalid key. Provide an alphanumeric key and try again.', + INVALID_REFERENCE_UID: (uid: string) => `Invalid referenceUid: ${uid}. Must be alphanumeric.`, + + // Value validation errors + INVALID_VALUE_STRING_OR_NUMBER: 'Invalid value. Provide a string or number and try again.', + INVALID_VALUE_ARRAY: 'Invalid value. Provide an array of strings, numbers, or booleans and try again.', + INVALID_ARGUMENT_STRING_OR_ARRAY: 'Invalid argument. Provide a string or an array and try again.', + + // Storage errors + MISSING_CUSTOM_STORAGE: 'Missing storage for customStorage. Provide a storage object with get, set, and remove methods and try again.', + + // Regex validation errors + INVALID_REGEX_PATTERN: 'Invalid regexPattern: Must be a valid regular expression', + + // Slack/Integration errors (for future use if sanity-report-ts-sdk.js is added) + SLACK_MESSAGE_FAILED: (details?: string) => + `Failed to send Slack message. Check the SLACK_WEBHOOK_URL and SLACK_CHANNEL configuration and try again.${details ? ` Details: ${details}` : ''}`, + SLACK_FAILURE_DETAILS_FAILED: (details?: string) => + `Failed to send failure details to Slack. Verify SLACK_WEBHOOK_URL, SLACK_CHANNEL, and SLACK_TOKEN settings and try again.${details ? ` Details: ${details}` : ''}`, +} as const; + +/** + * Error codes for programmatic error handling + */ +export enum ErrorCode { + INVALID_FIELD_UID = 'INVALID_FIELD_UID', + INVALID_KEY = 'INVALID_KEY', + INVALID_REFERENCE_UID = 'INVALID_REFERENCE_UID', + INVALID_VALUE = 'INVALID_VALUE', + INVALID_ARGUMENT = 'INVALID_ARGUMENT', + MISSING_STORAGE = 'MISSING_STORAGE', + INVALID_REGEX = 'INVALID_REGEX', + SLACK_ERROR = 'SLACK_ERROR', +} + diff --git a/src/lib/query.ts b/src/lib/query.ts index b69f744..1e0f735 100644 --- a/src/lib/query.ts +++ b/src/lib/query.ts @@ -2,6 +2,7 @@ import { AxiosInstance, getData } from '@contentstack/core'; import { BaseQuery } from './base-query'; import { BaseQueryParameters, QueryOperation, QueryOperator, TaxonomyQueryOperation, params, queryParams, FindResponse } from './types'; import { encodeQueryParams } from './utils'; +import { ErrorMessages } from './error-messages'; export class Query extends BaseQuery { private _contentTypeUid?: string; @@ -73,7 +74,7 @@ export class Query extends BaseQuery { additionalData?: object ): Query { if (!this.isValidAlphanumeric(fieldUid)) { - console.error("Invalid fieldUid. Provide an alphanumeric field UID and try again."); + console.error(ErrorMessages.INVALID_FIELD_UID); return this; } if (queryOperation == QueryOperation.EQUALS) { @@ -102,11 +103,11 @@ export class Query extends BaseQuery { */ regex(fieldUid: string, regexPattern: string, options?: string): Query { if (!this.isValidAlphanumeric(fieldUid)) { - console.error("Invalid fieldUid. Provide an alphanumeric field UID and try again."); + console.error(ErrorMessages.INVALID_FIELD_UID); return this; } if (!this.isValidRegexPattern(regexPattern)) { - throw new Error("Invalid regexPattern: Must be a valid regular expression"); + throw new Error(ErrorMessages.INVALID_REGEX_PATTERN); } else { this._parameters[fieldUid] = { $regex: regexPattern }; @@ -134,7 +135,7 @@ export class Query extends BaseQuery { whereIn(referenceUid: string, queryInstance: Query): Query { // eslint-disable-next-line @typescript-eslint/naming-convention, prettier/prettier if (!this.isValidAlphanumeric(referenceUid)) { - throw new Error("Invalid referenceUid: Must be alphanumeric."); + throw new Error(ErrorMessages.INVALID_REFERENCE_UID(referenceUid)); } this._parameters[referenceUid] = { '$in_query': queryInstance._parameters }; return this; @@ -159,7 +160,7 @@ export class Query extends BaseQuery { whereNotIn(referenceUid: string, queryInstance: Query): Query { // eslint-disable-next-line @typescript-eslint/naming-convention, prettier/prettier if (!this.isValidAlphanumeric(referenceUid)) { - throw new Error("Invalid referenceUid: Must be alphanumeric."); + throw new Error(ErrorMessages.INVALID_REFERENCE_UID(referenceUid)); } this._parameters[referenceUid] = { '$nin_query': queryInstance._parameters }; return this; @@ -226,11 +227,11 @@ export class Query extends BaseQuery { */ containedIn(key: string, value: (string | number | boolean)[]): Query { if (!this.isValidAlphanumeric(key)) { - console.error("Invalid key. Provide an alphanumeric key and try again."); + console.error(ErrorMessages.INVALID_KEY); return this; } if (!this.isValidValue(value)) { - console.error("Invalid value. Provide an array of strings, numbers, or booleans and try again."); + console.error(ErrorMessages.INVALID_VALUE_ARRAY); return this; } this._parameters[key] = { '$in': value }; @@ -252,11 +253,11 @@ export class Query extends BaseQuery { */ notContainedIn(key: string, value: (string | number | boolean)[]): Query { if (!this.isValidAlphanumeric(key)) { - console.error("Invalid key. Provide an alphanumeric key and try again."); + console.error(ErrorMessages.INVALID_KEY); return this; } if (!this.isValidValue(value)) { - console.error("Invalid value. Provide an array of strings, numbers, or booleans and try again."); + console.error(ErrorMessages.INVALID_VALUE_ARRAY); return this; } this._parameters[key] = { '$nin': value }; @@ -278,7 +279,7 @@ export class Query extends BaseQuery { */ exists(key: string): Query { if (!this.isValidAlphanumeric(key)) { - console.error("Invalid key. Provide an alphanumeric key and try again."); + console.error(ErrorMessages.INVALID_KEY); return this; } this._parameters[key] = { '$exists': true }; @@ -300,7 +301,7 @@ export class Query extends BaseQuery { */ notExists(key: string): Query { if (!this.isValidAlphanumeric(key)) { - console.error("Invalid key. Provide an alphanumeric key and try again."); + console.error(ErrorMessages.INVALID_KEY); return this; } this._parameters[key] = { '$exists': false }; @@ -367,11 +368,11 @@ export class Query extends BaseQuery { */ equalTo(key: string, value: string | number | boolean): Query { if (!this.isValidAlphanumeric(key)) { - console.error("Invalid key. Provide an alphanumeric key and try again."); + console.error(ErrorMessages.INVALID_KEY); return this; } if (typeof value !== 'string' && typeof value !== 'number') { - console.error("Invalid value. Provide a string or number and try again."); + console.error(ErrorMessages.INVALID_VALUE_STRING_OR_NUMBER); return this; } this._parameters[key] = value; @@ -392,11 +393,11 @@ export class Query extends BaseQuery { */ notEqualTo(key: string, value: string | number | boolean): Query { if (!this.isValidAlphanumeric(key)) { - console.error("Invalid key. Provide an alphanumeric key and try again."); + console.error(ErrorMessages.INVALID_KEY); return this; } if (typeof value !== 'string' && typeof value !== 'number') { - console.error("Invalid value. Provide a string or number and try again."); + console.error(ErrorMessages.INVALID_VALUE_STRING_OR_NUMBER); return this; } this._parameters[key] = { '$ne': value }; @@ -418,7 +419,7 @@ export class Query extends BaseQuery { */ referenceIn(key: string, query: Query): Query { if (!this.isValidAlphanumeric(key)) { - console.error("Invalid key. Provide an alphanumeric key and try again."); + console.error(ErrorMessages.INVALID_KEY); return this; } this._parameters[key] = { '$in_query': query._parameters } @@ -440,7 +441,7 @@ export class Query extends BaseQuery { */ referenceNotIn(key: string, query: Query): Query { if (!this.isValidAlphanumeric(key)) { - console.error("Invalid key. Provide an alphanumeric key and try again."); + console.error(ErrorMessages.INVALID_KEY); return this; } this._parameters[key] = { '$nin_query': query._parameters } @@ -462,7 +463,7 @@ export class Query extends BaseQuery { */ tags(values: (string | number | boolean)[]): Query { if (!this.isValidValue(values)) { - console.error("Invalid value. Provide an array of strings, numbers, or booleans and try again."); + console.error(ErrorMessages.INVALID_VALUE_ARRAY); return this; } this._parameters['tags'] = values; @@ -484,7 +485,7 @@ export class Query extends BaseQuery { */ search(key: string): Query { if (!this.isValidAlphanumeric(key)) { - console.error("Invalid key. Provide an alphanumeric key and try again."); + console.error(ErrorMessages.INVALID_KEY); return this; } this._queryParams['typeahead'] = key @@ -506,11 +507,11 @@ export class Query extends BaseQuery { */ lessThan(key: string, value: (string | number)): Query { if (!this.isValidAlphanumeric(key)) { - console.error("Invalid key. Provide an alphanumeric key and try again."); + console.error(ErrorMessages.INVALID_KEY); return this; } if (typeof value !== 'string' && typeof value !== 'number') { - console.error("Invalid value. Provide a string or number and try again."); + console.error(ErrorMessages.INVALID_VALUE_STRING_OR_NUMBER); return this; } @@ -533,11 +534,11 @@ export class Query extends BaseQuery { */ lessThanOrEqualTo(key: string, value: (string | number)): Query { if (!this.isValidAlphanumeric(key)) { - console.error("Invalid key. Provide an alphanumeric key and try again."); + console.error(ErrorMessages.INVALID_KEY); return this; } if (typeof value !== 'string' && typeof value !== 'number') { - console.error("Invalid value. Provide a string or number and try again."); + console.error(ErrorMessages.INVALID_VALUE_STRING_OR_NUMBER); return this; } this._parameters[key] = { '$lte': value }; @@ -559,11 +560,11 @@ export class Query extends BaseQuery { */ greaterThan(key: string, value: (string | number)): Query { if (!this.isValidAlphanumeric(key)) { - console.error("Invalid key. Provide an alphanumeric key and try again."); + console.error(ErrorMessages.INVALID_KEY); return this; } if (typeof value !== 'string' && typeof value !== 'number') { - console.error("Invalid value. Provide a string or number and try again."); + console.error(ErrorMessages.INVALID_VALUE_STRING_OR_NUMBER); return this; } this._parameters[key] = { '$gt': value }; @@ -585,11 +586,11 @@ export class Query extends BaseQuery { */ greaterThanOrEqualTo(key: string, value: (string | number)): Query { if (!this.isValidAlphanumeric(key)) { - console.error("Invalid key. Provide an alphanumeric key and try again."); + console.error(ErrorMessages.INVALID_KEY); return this; } if (typeof value !== 'string' && typeof value !== 'number') { - console.error("Invalid value. Provide a string or number and try again."); + console.error(ErrorMessages.INVALID_VALUE_STRING_OR_NUMBER); return this; } this._parameters[key] = { '$gte': value }; diff --git a/src/persistance/persistance-store.ts b/src/persistance/persistance-store.ts index b76e751..12bffe1 100644 --- a/src/persistance/persistance-store.ts +++ b/src/persistance/persistance-store.ts @@ -3,6 +3,7 @@ import { localStorage } from './storages/local-storage'; import { memoryStorage } from './storages/memory-storage'; import { Storage } from './types/storage'; import { StorageType } from './types/storage-type'; +import { ErrorMessages } from '../lib/error-messages'; export class PersistanceStore { protected store: Storage = localStorage; @@ -33,7 +34,7 @@ export class PersistanceStore { break; case 'customStorage': if (!store) { - throw new TypeError('Missing storage for customStorage. Provide a storage object with get, set, and remove methods and try again.'); + throw new TypeError(ErrorMessages.MISSING_CUSTOM_STORAGE); } else { this.store = store; } diff --git a/test/unit/content-validation-comprehensive.spec.ts b/test/unit/content-validation-comprehensive.spec.ts index 5bebc36..e7c639b 100644 --- a/test/unit/content-validation-comprehensive.spec.ts +++ b/test/unit/content-validation-comprehensive.spec.ts @@ -10,6 +10,7 @@ import { Entries } from '../../src/lib/entries'; import { GlobalField } from '../../src/lib/global-field'; import { QueryOperation, QueryOperator, TaxonomyQueryOperation } from '../../src/lib/types'; import { MOCK_CLIENT_OPTIONS } from '../utils/constant'; +import { ErrorMessages } from '../../src/lib/error-messages'; describe('Content Validation - Comprehensive Test Suite', () => { let client: AxiosInstance; @@ -659,8 +660,8 @@ describe('Content Validation - Comprehensive Test Suite', () => { query.where('123invalid', QueryOperation.EQUALS, 'test'); // Check that console.error was called for invalid field UIDs - // Note: The validation function only logs for the first invalid field encountered - expect(consoleSpy).toHaveBeenCalledWith('Invalid fieldUid:', 'invalid field'); + expect(consoleSpy).toHaveBeenCalledWith(ErrorMessages.INVALID_FIELD_UID); + expect(consoleSpy).toHaveBeenCalledTimes(3); consoleSpy.mockRestore(); }); @@ -694,8 +695,8 @@ describe('Content Validation - Comprehensive Test Suite', () => { expect(() => query.regex('title', '[A-Z]+')).not.toThrow(); // Invalid regex patterns - expect(() => query.regex('title', '[a-z')).toThrow('Invalid regexPattern: Must be a valid regular expression'); - expect(() => query.regex('title', '*invalid')).toThrow('Invalid regexPattern: Must be a valid regular expression'); + expect(() => query.regex('title', '[a-z')).toThrow(ErrorMessages.INVALID_REGEX_PATTERN); + expect(() => query.regex('title', '*invalid')).toThrow(ErrorMessages.INVALID_REGEX_PATTERN); }); it('should validate query value types', () => { @@ -713,8 +714,8 @@ describe('Content Validation - Comprehensive Test Suite', () => { query.equalTo('title', [] as any); query.equalTo('title', {} as any); - expect(consoleSpy).toHaveBeenCalledWith('Invalid value (expected string or number):', []); - expect(consoleSpy).toHaveBeenCalledWith('Invalid value (expected string or number):', {}); + expect(consoleSpy).toHaveBeenCalledWith(ErrorMessages.INVALID_VALUE_STRING_OR_NUMBER); + expect(consoleSpy).toHaveBeenCalledTimes(2); consoleSpy.mockRestore(); }); diff --git a/test/unit/query-optimization-comprehensive.spec.ts b/test/unit/query-optimization-comprehensive.spec.ts index c2ccaed..cebed47 100644 --- a/test/unit/query-optimization-comprehensive.spec.ts +++ b/test/unit/query-optimization-comprehensive.spec.ts @@ -5,6 +5,7 @@ import { Query } from '../../src/lib/query'; import { QueryOperation, QueryOperator } from '../../src/lib/types'; import { entryFindMock } from '../utils/mocks'; import { Entries } from '../../src/lib/entries'; +import { ErrorMessages } from '../../src/lib/error-messages'; // Mock @contentstack/core jest.mock('@contentstack/core', () => ({ @@ -177,9 +178,8 @@ describe('Query Optimization - Comprehensive Test Suite', () => { query.where('field@symbol', QueryOperation.EQUALS, 'value'); query.where('field#hash', QueryOperation.EQUALS, 'value'); - expect(consoleSpy).toHaveBeenCalledWith('Invalid fieldUid:', 'invalid field'); - expect(consoleSpy).toHaveBeenCalledWith('Invalid fieldUid:', 'field@symbol'); - expect(consoleSpy).toHaveBeenCalledWith('Invalid fieldUid:', 'field#hash'); + expect(consoleSpy).toHaveBeenCalledWith(ErrorMessages.INVALID_FIELD_UID); + expect(consoleSpy).toHaveBeenCalledTimes(3); consoleSpy.mockRestore(); }); @@ -191,8 +191,8 @@ describe('Query Optimization - Comprehensive Test Suite', () => { expect(() => query.regex('title', '^Demo')).not.toThrow(); // Invalid regex patterns - expect(() => query.regex('title', '[a-z')).toThrow('Invalid regexPattern: Must be a valid regular expression'); - expect(() => query.regex('title', '*invalid')).toThrow('Invalid regexPattern: Must be a valid regular expression'); + expect(() => query.regex('title', '[a-z')).toThrow(ErrorMessages.INVALID_REGEX_PATTERN); + expect(() => query.regex('title', '*invalid')).toThrow(ErrorMessages.INVALID_REGEX_PATTERN); }); it('should validate containedIn values for proper types', () => { @@ -207,8 +207,8 @@ describe('Query Optimization - Comprehensive Test Suite', () => { query.containedIn('invalid', [{}, null, undefined] as any); query.containedIn('mixed_invalid', ['valid', {}, 'also_valid'] as any); - expect(consoleSpy).toHaveBeenCalledWith('Invalid value:', [{}, null, undefined]); - expect(consoleSpy).toHaveBeenCalledWith('Invalid value:', ['valid', {}, 'also_valid']); + expect(consoleSpy).toHaveBeenCalledWith(ErrorMessages.INVALID_VALUE_ARRAY); + expect(consoleSpy).toHaveBeenCalledTimes(2); consoleSpy.mockRestore(); }); @@ -221,7 +221,7 @@ describe('Query Optimization - Comprehensive Test Suite', () => { expect(() => query.whereIn('valid_ref', subQuery)).not.toThrow(); // Invalid reference UID - expect(() => query.whereIn('invalid ref', subQuery)).toThrow('Invalid referenceUid: Must be alphanumeric.'); + expect(() => query.whereIn('invalid ref', subQuery)).toThrow(ErrorMessages.INVALID_REFERENCE_UID('invalid ref')); }); it('should validate value types for comparison operations', () => { @@ -239,8 +239,8 @@ describe('Query Optimization - Comprehensive Test Suite', () => { query.equalTo('also_invalid', [] as any); query.lessThan('bad_value', {} as any); - expect(consoleSpy).toHaveBeenCalledWith('Invalid value (expected string or number):', {}); - expect(consoleSpy).toHaveBeenCalledWith('Invalid value (expected string or number):', []); + expect(consoleSpy).toHaveBeenCalledWith(ErrorMessages.INVALID_VALUE_STRING_OR_NUMBER); + expect(consoleSpy).toHaveBeenCalledTimes(3); consoleSpy.mockRestore(); }); @@ -254,7 +254,7 @@ describe('Query Optimization - Comprehensive Test Suite', () => { // Invalid search key query.search('invalid search'); - expect(consoleSpy).toHaveBeenCalledWith('Invalid key:', 'invalid search'); + expect(consoleSpy).toHaveBeenCalledWith(ErrorMessages.INVALID_KEY); consoleSpy.mockRestore(); }); diff --git a/test/unit/query.spec.ts b/test/unit/query.spec.ts index d244a27..be55243 100644 --- a/test/unit/query.spec.ts +++ b/test/unit/query.spec.ts @@ -5,6 +5,7 @@ import { Query } from '../../src/lib/query'; import { QueryOperation, QueryOperator } from '../../src/lib/types'; import { entryFindMock } from '../utils/mocks'; import { Entries } from '../../src/lib/entries'; +import { ErrorMessages } from '../../src/lib/error-messages'; describe('Query class', () => { let client: AxiosInstance; @@ -183,155 +184,155 @@ describe('Query class', () => { it('should log error and return this when where() receives invalid fieldUid', () => { const result = query.where('invalid@field!', QueryOperation.EQUALS, 'value'); - expect(consoleErrorSpy).toHaveBeenCalledWith('Invalid fieldUid:', 'invalid@field!'); + expect(consoleErrorSpy).toHaveBeenCalledWith(ErrorMessages.INVALID_FIELD_UID); expect(result).toBe(query); expect(query._parameters['invalid@field!']).toBeUndefined(); }); it('should log error and return this when regex() receives invalid fieldUid', () => { const result = query.regex('invalid@field!', '^test'); - expect(consoleErrorSpy).toHaveBeenCalledWith('Invalid fieldUid:', 'invalid@field!'); + expect(consoleErrorSpy).toHaveBeenCalledWith(ErrorMessages.INVALID_FIELD_UID); expect(result).toBe(query); }); it('should log error and return this when containedIn() receives invalid key', () => { const result = query.containedIn('invalid@key!', ['value1', 'value2']); - expect(consoleErrorSpy).toHaveBeenCalledWith('Invalid key:', 'invalid@key!'); + expect(consoleErrorSpy).toHaveBeenCalledWith(ErrorMessages.INVALID_KEY); expect(result).toBe(query); expect(query._parameters['invalid@key!']).toBeUndefined(); }); it('should log error and return this when containedIn() receives invalid value', () => { const result = query.containedIn('validKey', ['value1', {invalid: 'object'}] as any); - expect(consoleErrorSpy).toHaveBeenCalledWith('Invalid value:', ['value1', {invalid: 'object'}]); + expect(consoleErrorSpy).toHaveBeenCalledWith(ErrorMessages.INVALID_VALUE_ARRAY); expect(result).toBe(query); }); it('should log error and return this when notContainedIn() receives invalid key', () => { const result = query.notContainedIn('invalid@key!', ['value1', 'value2']); - expect(consoleErrorSpy).toHaveBeenCalledWith('Invalid key:', 'invalid@key!'); + expect(consoleErrorSpy).toHaveBeenCalledWith(ErrorMessages.INVALID_KEY); expect(result).toBe(query); }); it('should log error and return this when notContainedIn() receives invalid value', () => { const result = query.notContainedIn('validKey', [null] as any); - expect(consoleErrorSpy).toHaveBeenCalledWith('Invalid value:', [null]); + expect(consoleErrorSpy).toHaveBeenCalledWith(ErrorMessages.INVALID_VALUE_ARRAY); expect(result).toBe(query); }); it('should log error and return this when exists() receives invalid key', () => { const result = query.exists('invalid@key!'); - expect(consoleErrorSpy).toHaveBeenCalledWith('Invalid key:', 'invalid@key!'); + expect(consoleErrorSpy).toHaveBeenCalledWith(ErrorMessages.INVALID_KEY); expect(result).toBe(query); }); it('should log error and return this when notExists() receives invalid key', () => { const result = query.notExists('invalid@key!'); - expect(consoleErrorSpy).toHaveBeenCalledWith('Invalid key:', 'invalid@key!'); + expect(consoleErrorSpy).toHaveBeenCalledWith(ErrorMessages.INVALID_KEY); expect(result).toBe(query); }); it('should log error and return this when equalTo() receives invalid key', () => { const result = query.equalTo('invalid@key!', 'value'); - expect(consoleErrorSpy).toHaveBeenCalledWith('Invalid key:', 'invalid@key!'); + expect(consoleErrorSpy).toHaveBeenCalledWith(ErrorMessages.INVALID_KEY); expect(result).toBe(query); }); it('should log error and return this when equalTo() receives invalid value (null)', () => { const result = query.equalTo('validKey', null as any); - expect(consoleErrorSpy).toHaveBeenCalledWith('Invalid value (expected string or number):', null); + expect(consoleErrorSpy).toHaveBeenCalledWith(ErrorMessages.INVALID_VALUE_STRING_OR_NUMBER); expect(result).toBe(query); }); it('should log error and return this when equalTo() receives invalid value (undefined)', () => { const result = query.equalTo('validKey', undefined as any); - expect(consoleErrorSpy).toHaveBeenCalledWith('Invalid value (expected string or number):', undefined); + expect(consoleErrorSpy).toHaveBeenCalledWith(ErrorMessages.INVALID_VALUE_STRING_OR_NUMBER); expect(result).toBe(query); }); it('should log error and return this when notEqualTo() receives invalid key', () => { const result = query.notEqualTo('invalid@key!', 'value'); - expect(consoleErrorSpy).toHaveBeenCalledWith('Invalid key:', 'invalid@key!'); + expect(consoleErrorSpy).toHaveBeenCalledWith(ErrorMessages.INVALID_KEY); expect(result).toBe(query); }); it('should log error and return this when notEqualTo() receives invalid value', () => { const result = query.notEqualTo('validKey', {} as any); - expect(consoleErrorSpy).toHaveBeenCalledWith('Invalid value (expected string or number):', {}); + expect(consoleErrorSpy).toHaveBeenCalledWith(ErrorMessages.INVALID_VALUE_STRING_OR_NUMBER); expect(result).toBe(query); }); it('should log error and return this when referenceIn() receives invalid key', () => { const subQuery = getQueryObject(client, 'content_type_uid'); const result = query.referenceIn('invalid@key!', subQuery); - expect(consoleErrorSpy).toHaveBeenCalledWith('Invalid key:', 'invalid@key!'); + expect(consoleErrorSpy).toHaveBeenCalledWith(ErrorMessages.INVALID_KEY); expect(result).toBe(query); }); it('should log error and return this when referenceNotIn() receives invalid key', () => { const subQuery = getQueryObject(client, 'content_type_uid'); const result = query.referenceNotIn('invalid@key!', subQuery); - expect(consoleErrorSpy).toHaveBeenCalledWith('Invalid key:', 'invalid@key!'); + expect(consoleErrorSpy).toHaveBeenCalledWith(ErrorMessages.INVALID_KEY); expect(result).toBe(query); }); it('should log error and return this when tags() receives invalid value', () => { const result = query.tags([{invalid: 'object'}] as any); - expect(consoleErrorSpy).toHaveBeenCalledWith('Invalid value:', [{invalid: 'object'}]); + expect(consoleErrorSpy).toHaveBeenCalledWith(ErrorMessages.INVALID_VALUE_ARRAY); expect(result).toBe(query); }); it('should log error and return this when search() receives invalid key', () => { const result = query.search('invalid@search!'); - expect(consoleErrorSpy).toHaveBeenCalledWith('Invalid key:', 'invalid@search!'); + expect(consoleErrorSpy).toHaveBeenCalledWith(ErrorMessages.INVALID_KEY); expect(result).toBe(query); }); it('should log error and return this when lessThan() receives invalid key', () => { const result = query.lessThan('invalid@key!', 10); - expect(consoleErrorSpy).toHaveBeenCalledWith('Invalid key:', 'invalid@key!'); + expect(consoleErrorSpy).toHaveBeenCalledWith(ErrorMessages.INVALID_KEY); expect(result).toBe(query); }); it('should log error and return this when lessThan() receives invalid value', () => { const result = query.lessThan('validKey', {} as any); - expect(consoleErrorSpy).toHaveBeenCalledWith('Invalid value (expected string or number):', {}); + expect(consoleErrorSpy).toHaveBeenCalledWith(ErrorMessages.INVALID_VALUE_STRING_OR_NUMBER); expect(result).toBe(query); }); it('should log error and return this when lessThanOrEqualTo() receives invalid key', () => { const result = query.lessThanOrEqualTo('invalid@key!', 10); - expect(consoleErrorSpy).toHaveBeenCalledWith('Invalid key:', 'invalid@key!'); + expect(consoleErrorSpy).toHaveBeenCalledWith(ErrorMessages.INVALID_KEY); expect(result).toBe(query); }); it('should log error and return this when lessThanOrEqualTo() receives invalid value', () => { const result = query.lessThanOrEqualTo('validKey', [] as any); - expect(consoleErrorSpy).toHaveBeenCalledWith('Invalid value (expected string or number):', []); + expect(consoleErrorSpy).toHaveBeenCalledWith(ErrorMessages.INVALID_VALUE_STRING_OR_NUMBER); expect(result).toBe(query); }); it('should log error and return this when greaterThan() receives invalid key', () => { const result = query.greaterThan('invalid@key!', 10); - expect(consoleErrorSpy).toHaveBeenCalledWith('Invalid key:', 'invalid@key!'); + expect(consoleErrorSpy).toHaveBeenCalledWith(ErrorMessages.INVALID_KEY); expect(result).toBe(query); }); it('should log error and return this when greaterThan() receives invalid value', () => { const result = query.greaterThan('validKey', null as any); - expect(consoleErrorSpy).toHaveBeenCalledWith('Invalid value (expected string or number):', null); + expect(consoleErrorSpy).toHaveBeenCalledWith(ErrorMessages.INVALID_VALUE_STRING_OR_NUMBER); expect(result).toBe(query); }); it('should log error and return this when greaterThanOrEqualTo() receives invalid key', () => { const result = query.greaterThanOrEqualTo('invalid@key!', 10); - expect(consoleErrorSpy).toHaveBeenCalledWith('Invalid key:', 'invalid@key!'); + expect(consoleErrorSpy).toHaveBeenCalledWith(ErrorMessages.INVALID_KEY); expect(result).toBe(query); }); it('should log error and return this when greaterThanOrEqualTo() receives invalid value', () => { const result = query.greaterThanOrEqualTo('validKey', undefined as any); - expect(consoleErrorSpy).toHaveBeenCalledWith('Invalid value (expected string or number):', undefined); + expect(consoleErrorSpy).toHaveBeenCalledWith(ErrorMessages.INVALID_VALUE_STRING_OR_NUMBER); expect(result).toBe(query); }); From 870666af233f7155c8ab4ace2bccf0d748d73ee8 Mon Sep 17 00:00:00 2001 From: reeshika-h Date: Mon, 24 Nov 2025 12:43:23 +0530 Subject: [PATCH 3/7] workflow fix 1 --- test/unit/content-validation-comprehensive.spec.ts | 13 ++++++------- test/unit/entries.spec.ts | 3 ++- test/unit/entry.spec.ts | 3 ++- test/unit/query-optimization-comprehensive.spec.ts | 6 +++--- test/unit/query.spec.ts | 4 ++-- 5 files changed, 15 insertions(+), 14 deletions(-) diff --git a/test/unit/content-validation-comprehensive.spec.ts b/test/unit/content-validation-comprehensive.spec.ts index e7c639b..7533bd8 100644 --- a/test/unit/content-validation-comprehensive.spec.ts +++ b/test/unit/content-validation-comprehensive.spec.ts @@ -654,14 +654,13 @@ describe('Content Validation - Comprehensive Test Suite', () => { query.where('view_count', QueryOperation.IS_GREATER_THAN, 100); query.where('is_published', QueryOperation.EQUALS, true); - // Invalid field UIDs + // Invalid field UIDs (note: field-with-dashes is actually valid as hyphens are allowed) query.where('invalid field', QueryOperation.EQUALS, 'test'); - query.where('field-with-dashes', QueryOperation.EQUALS, 'test'); - query.where('123invalid', QueryOperation.EQUALS, 'test'); + query.where('field@symbol', QueryOperation.EQUALS, 'test'); // Check that console.error was called for invalid field UIDs expect(consoleSpy).toHaveBeenCalledWith(ErrorMessages.INVALID_FIELD_UID); - expect(consoleSpy).toHaveBeenCalledTimes(3); + expect(consoleSpy).toHaveBeenCalledTimes(2); consoleSpy.mockRestore(); }); @@ -708,14 +707,14 @@ describe('Content Validation - Comprehensive Test Suite', () => { // Valid value types query.equalTo('title', 'string value'); query.equalTo('view_count', 123); - query.equalTo('is_published', true); - // Invalid value types for equalTo (expects string, number, or boolean) + // Invalid value types for equalTo (expects string or number, not boolean) + query.equalTo('is_published', true as any); // boolean triggers error query.equalTo('title', [] as any); query.equalTo('title', {} as any); expect(consoleSpy).toHaveBeenCalledWith(ErrorMessages.INVALID_VALUE_STRING_OR_NUMBER); - expect(consoleSpy).toHaveBeenCalledTimes(2); + expect(consoleSpy).toHaveBeenCalledTimes(3); consoleSpy.mockRestore(); }); diff --git a/test/unit/entries.spec.ts b/test/unit/entries.spec.ts index aa6f233..ebd2b5d 100644 --- a/test/unit/entries.spec.ts +++ b/test/unit/entries.spec.ts @@ -5,6 +5,7 @@ import MockAdapter from 'axios-mock-adapter'; import { entryFetchMock, entryFindMock } from '../utils/mocks'; import { Query } from '../../src/lib/query'; import { QueryOperation, QueryOperator, TaxonomyQueryOperation } from '../../src/lib/types'; +import { ErrorMessages } from '../../src/lib/error-messages'; describe('Entries class', () => { let entry: Entries; @@ -46,7 +47,7 @@ describe('Entries class', () => { it('should log error when includeReference called with no arguments', () => { const consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation(); entry.includeReference(); - expect(consoleErrorSpy).toHaveBeenCalledWith('Argument should be a String or an Array.'); + expect(consoleErrorSpy).toHaveBeenCalledWith(ErrorMessages.INVALID_ARGUMENT_STRING_OR_ARRAY); consoleErrorSpy.mockRestore(); }); diff --git a/test/unit/entry.spec.ts b/test/unit/entry.spec.ts index 47bc5d4..fd33610 100644 --- a/test/unit/entry.spec.ts +++ b/test/unit/entry.spec.ts @@ -4,6 +4,7 @@ import { Entry } from '../../src/lib/entry'; import MockAdapter from 'axios-mock-adapter'; import { entryFetchMock } from '../utils/mocks'; import { getData } from '@contentstack/core'; +import { ErrorMessages } from '../../src/lib/error-messages'; describe('Entry class', () => { let entry: Entry; @@ -52,7 +53,7 @@ describe('Entry class', () => { it('should log error when includeReference called with no arguments', () => { const consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation(); entry.includeReference(); - expect(consoleErrorSpy).toHaveBeenCalledWith('Argument should be a String or an Array.'); + expect(consoleErrorSpy).toHaveBeenCalledWith(ErrorMessages.INVALID_ARGUMENT_STRING_OR_ARRAY); consoleErrorSpy.mockRestore(); }); diff --git a/test/unit/query-optimization-comprehensive.spec.ts b/test/unit/query-optimization-comprehensive.spec.ts index cebed47..648c64a 100644 --- a/test/unit/query-optimization-comprehensive.spec.ts +++ b/test/unit/query-optimization-comprehensive.spec.ts @@ -230,17 +230,17 @@ describe('Query Optimization - Comprehensive Test Suite', () => { // Valid values query.equalTo('title', 'string value'); query.equalTo('count', 42); - query.equalTo('is_published', true); query.lessThan('score', 100); query.greaterThan('rating', 3.5); - // Invalid values + // Invalid values (note: boolean is also invalid for equalTo as it only accepts string or number) + query.equalTo('is_published', true as any); // boolean triggers error query.equalTo('invalid', {} as any); query.equalTo('also_invalid', [] as any); query.lessThan('bad_value', {} as any); expect(consoleSpy).toHaveBeenCalledWith(ErrorMessages.INVALID_VALUE_STRING_OR_NUMBER); - expect(consoleSpy).toHaveBeenCalledTimes(3); + expect(consoleSpy).toHaveBeenCalledTimes(4); consoleSpy.mockRestore(); }); diff --git a/test/unit/query.spec.ts b/test/unit/query.spec.ts index be55243..820a272 100644 --- a/test/unit/query.spec.ts +++ b/test/unit/query.spec.ts @@ -338,12 +338,12 @@ describe('Query class', () => { it('should throw error when whereIn() receives invalid referenceUid', () => { const subQuery = getQueryObject(client, 'content_type_uid'); - expect(() => query.whereIn('invalid@ref!', subQuery)).toThrow('Invalid referenceUid: Must be alphanumeric.'); + expect(() => query.whereIn('invalid@ref!', subQuery)).toThrow(ErrorMessages.INVALID_REFERENCE_UID('invalid@ref!')); }); it('should throw error when whereNotIn() receives invalid referenceUid', () => { const subQuery = getQueryObject(client, 'content_type_uid'); - expect(() => query.whereNotIn('invalid@ref!', subQuery)).toThrow('Invalid referenceUid: Must be alphanumeric.'); + expect(() => query.whereNotIn('invalid@ref!', subQuery)).toThrow(ErrorMessages.INVALID_REFERENCE_UID('invalid@ref!')); }); }); From a505458b67f4916017012eb28b0bf47e3ef82a71 Mon Sep 17 00:00:00 2001 From: raj pandey Date: Tue, 25 Nov 2025 20:05:56 +0530 Subject: [PATCH 4/7] Fixed the JSDoc Strings --- src/lib/asset-query.ts | 10 +- src/lib/asset.ts | 10 +- src/lib/base-query.ts | 9 +- src/lib/cache.ts | 10 ++ src/lib/content-type.ts | 9 +- src/lib/contentstack.ts | 2 +- src/lib/contenttype-query.ts | 4 +- src/lib/entries.ts | 35 +++-- src/lib/entry.ts | 18 +-- src/lib/global-field-query.ts | 6 +- src/lib/global-field.ts | 14 +- src/lib/image-transform.ts | 82 ++++++----- src/lib/pagination.ts | 4 +- src/lib/query.ts | 131 +++++++++++------- src/lib/stack.ts | 76 ++++++---- src/lib/utils.ts | 9 ++ .../config/persistance-storage-config.ts | 23 ++- src/persistance/persistance-store.ts | 30 ++++ src/persistance/storages/local-storage.ts | 29 ++++ src/persistance/storages/memory-storage.ts | 24 ++++ 20 files changed, 370 insertions(+), 165 deletions(-) diff --git a/src/lib/asset-query.ts b/src/lib/asset-query.ts index 0f66d63..6bec319 100644 --- a/src/lib/asset-query.ts +++ b/src/lib/asset-query.ts @@ -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'; @@ -128,7 +128,7 @@ 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 diff --git a/src/lib/asset.ts b/src/lib/asset.ts index 4d635e1..b5c7c23 100644 --- a/src/lib/asset.ts +++ b/src/lib/asset.ts @@ -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' * @@ -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' @@ -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} Promise that resolves to the asset data * @example * import contentstack from '@contentstack/delivery-sdk' * diff --git a/src/lib/base-query.ts b/src/lib/base-query.ts index a1347ed..dc9fe79 100644 --- a/src/lib/base-query.ts +++ b/src/lib/base-query.ts @@ -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>} Promise that resolves to the find response * @example * import contentstack from '@contentstack/delivery-sdk' * @@ -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(encode: boolean = false): Promise> { diff --git a/src/lib/cache.ts b/src/lib/cache.ts index 0d28f7b..83743cd 100644 --- a/src/lib/cache.ts +++ b/src/lib/cache.ts @@ -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, diff --git a/src/lib/content-type.ts b/src/lib/content-type.ts index af75fc0..d62842a 100644 --- a/src/lib/content-type.ts +++ b/src/lib/content-type.ts @@ -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; @@ -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} Promise that resolves to the content type data * @example * import contentstack from '@contentstack/delivery-sdk' * diff --git a/src/lib/contentstack.ts b/src/lib/contentstack.ts index 837b99d..9fae49a 100644 --- a/src/lib/contentstack.ts +++ b/src/lib/contentstack.ts @@ -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" }); diff --git a/src/lib/contenttype-query.ts b/src/lib/contenttype-query.ts index 50702f8..aceec4c 100644 --- a/src/lib/contenttype-query.ts +++ b/src/lib/contenttype-query.ts @@ -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' @@ -31,7 +31,7 @@ export class ContentTypeQuery { * @method find * @memberof ContentTypeQuery * @description Fetches all contentTypes of the stack - * @returns {ContentTypeQuery} + * @returns {Promise>} Promise that resolves to the find response containing content types * @example * import contentstack from '@contentstack/delivery-sdk' * diff --git a/src/lib/entries.ts b/src/lib/entries.ts index c7727d3..685268f 100644 --- a/src/lib/entries.ts +++ b/src/lib/entries.ts @@ -62,13 +62,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'; @@ -85,7 +85,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'; @@ -134,7 +134,9 @@ 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"); + * import contentstack from '@contentstack/delivery-sdk' + * + * const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" }); * const query = stack.contentType("contentTypeUid").entry().includeReference("brand") * const res = await query.find() * @@ -160,7 +162,9 @@ 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"); + * import contentstack from '@contentstack/delivery-sdk' + * + * const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" }); * const query = stack.contentType("contentTypeUid").entry().includeReferenceContentTypeUID() * const res = await query.find() * @@ -175,9 +179,11 @@ 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"); + * import contentstack from '@contentstack/delivery-sdk' + * + * const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" }); * const query = stack.contentType("contentTypeUid").entry().includeSchema() * const res = await query.find() * @@ -191,9 +197,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' * @@ -235,8 +241,9 @@ 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' * @@ -251,9 +258,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' * diff --git a/src/lib/entry.ts b/src/lib/entry.ts index 077c8cd..d74fd79 100644 --- a/src/lib/entry.ts +++ b/src/lib/entry.ts @@ -97,7 +97,9 @@ export class Entry { * 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"); + * import contentstack from '@contentstack/delivery-sdk' + * + * const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" }); * const query = stack.contentType("contentTypeUid").entry(entry_uid).includeReference("brand").fetch() * * @param {string} referenceFieldUid - UID of the reference field to include. @@ -120,7 +122,7 @@ export class Entry { /** * @method includeContentType * @memberof Entry - * @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 {Entry} * @example * import contentstack from '@contentstack/delivery-sdk' @@ -154,13 +156,13 @@ export class Entry { /** * @method locale * @memberof Entry - * @description The assets published in the locale will be fetched + * @description The entry published in the locale will be fetched * @returns {Entry} * @example * import contentstack from '@contentstack/delivery-sdk' * * const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" }); - * const result = await stack.assetQuery().locale('en-us').fetch(); + * const result = await stack.contentType('contentTypeUid').entry('entryUid').locale('en-us').fetch(); */ locale(locale: string): this { this._queryParams.locale = locale; @@ -172,7 +174,7 @@ export class Entry { * @method fetch * @memberof Entry * @description Fetches the entry data on the basis of the entry uid - * @returns {Collection} + * @returns {Promise} Promise that resolves to the entry data * @example * import contentstack from '@contentstack/delivery-sdk' * @@ -208,7 +210,7 @@ export class Entry { * import contentstack from '@contentstack/delivery-sdk' * * const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" }); - * const result = stack.contentType("contentTypeUid").entry().addParams({"key": "value"}).fetch() + * const result = await stack.contentType("contentTypeUid").entry("entryUid").addParams({"key": "value"}).fetch() * * @returns {Entry} */ @@ -226,7 +228,7 @@ export class Entry { * import contentstack from '@contentstack/delivery-sdk' * * const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" }); - * const result = await stack.contentType("contentTypeUid").entry().except("fieldUID").find() + * const result = await stack.contentType("contentTypeUid").entry("entryUid").except("fieldUID").fetch() * * @param {string} fieldUid - field uid to exclude * @returns {Entry} - returns Entry object for chaining method calls @@ -253,7 +255,7 @@ export class Entry { * import contentstack from '@contentstack/delivery-sdk' * * const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" }); - * const result = await stack.contentType("contentTypeUid").entry().only("fieldUID").find() + * const result = await stack.contentType("contentTypeUid").entry("entryUid").only("fieldUID").fetch() * * @param {string} fieldUid - field uid to select * @returns {Entry} - returns Entry object for chaining method calls diff --git a/src/lib/global-field-query.ts b/src/lib/global-field-query.ts index 3cfc49d..f29328e 100644 --- a/src/lib/global-field-query.ts +++ b/src/lib/global-field-query.ts @@ -14,9 +14,11 @@ export class GlobalFieldQuery extends BaseQuery { * @description Includes the _branch top-level key in the response * @returns {GlobalFieldQuery} * @example - * const stack = contentstack.stack('apiKey','deliveryToken','environment'); + * import contentstack from '@contentstack/delivery-sdk' + * + * const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" }); * const globalFields = stack.globalField(); - * const result = globalFields.includeBranch().find(); + * const result = await globalFields.includeBranch().find(); */ includeBranch(): GlobalFieldQuery { this._queryParams.include_branch = 'true'; diff --git a/src/lib/global-field.ts b/src/lib/global-field.ts index 9b459bc..dd69ad6 100644 --- a/src/lib/global-field.ts +++ b/src/lib/global-field.ts @@ -15,9 +15,11 @@ export class GlobalField { * @description Includes the _branch top-level key in the response * @returns {GlobalField} * @example - * const stack = contentstack.stack('apiKey','deliveryToken','environment'); + * import contentstack from '@contentstack/delivery-sdk' + * + * const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" }); * const globalField = stack.globalField('global_field_uid'); - * const result = globalField.includeBranch().fetch(); + * const result = await globalField.includeBranch().fetch(); */ includeBranch(): GlobalField { this._queryParams.include_branch = 'true'; @@ -25,14 +27,16 @@ export class GlobalField { return this; } /** - * @method find + * @method fetch * @memberof GlobalField * @description Fetches comprehensive details of a specific global field - * @returns {GlobalField} + * @returns {Promise} Promise that resolves to the global field data * @example + * import contentstack from '@contentstack/delivery-sdk' + * * const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" }); * const globalField = stack.globalField('global_field_uid'); - * const result = globalField.fetch(); + * const result = await globalField.fetch(); */ async fetch(): Promise { const response = await getData(this._client, this._urlPath, { params: this._queryParams }); diff --git a/src/lib/image-transform.ts b/src/lib/image-transform.ts index 64bfc80..6b9db55 100644 --- a/src/lib/image-transform.ts +++ b/src/lib/image-transform.ts @@ -53,7 +53,7 @@ export class ImageTransform { /** * @method format * @memberof ImageTransform - * @description The format parameter lets you converts a given image from one format to another. + * @description The format parameter lets you convert a given image from one format to another. * @param {Format} format - Specifies the format to change to. * @returns {ImageTransform} * @example @@ -72,11 +72,12 @@ export class ImageTransform { * @method resize * @memberof ImageTransform * @description The resize parameter lets you resize the image in terms of width, height, upscaling the image. - * @param {string | number} width - Specifies the width to resize the image to. + * @param {object} options - Resize options object + * @param {string | number} [options.width] - Specifies the width to resize the image to. * The value can be in pixels (for example, 400) or in percentage (for example, 0.60 OR '60p') - * @param {string | number} height - Specifies the height to resize the image to. + * @param {string | number} [options.height] - Specifies the height to resize the image to. * The value can be in pixels (for example, 400) or in percentage (for example, 0.60 OR '60p') - * @param {string} disable - The disable parameter disables the functionality that is enabled by default. + * @param {string} [options.disable] - The disable parameter disables the functionality that is enabled by default. * As of now, there is only one value, i.e., upscale, that you can use with the disable parameter. * @returns {ImageTransform} * @example @@ -108,20 +109,21 @@ export class ImageTransform { * the height and width in pixels or percentage value, or defining height and width in aspect ratio. * You can also define a sub region (i.e., define the starting point for crop) before cropping the image, * or you can offset the image on its X and Y axis (i.e., define the centre point of the crop) before cropping the image. - * @returns {ImageTransform} - * @param {string | number} width - Specifies the width to resize the image to. + * @param {object} options - Crop options object + * @param {string | number} options.width - Specifies the width to resize the image to. * The value can be in pixels (for example, 400) or in percentage (for example, 0.60 OR '60p') - * @param {string | number} height - Specifies the height to resize the image to. + * @param {string | number} options.height - Specifies the height to resize the image to. * The value can be in pixels (for example, 400) or in percentage (for example, 0.60 OR '60p') - * @param {string | number} xval - (Optional) For CropBy Region, xval defines the X-axis position + * @param {string | number} [options.xval] - (Optional) For CropBy Region, xval defines the X-axis position * of the top left corner of the crop. For CropBy Offset, xval defines the horizontal offset of the crop region. - * @param {string | number} yval - (Optional) For CropBy Region, yval defines the Y-axis position + * @param {string | number} [options.yval] - (Optional) For CropBy Region, yval defines the Y-axis position * of the top left corner of the crop. For CropBy Offset, yval defines the vertical offset of the crop region. - * @param {CropBy} cropBy - (Optional) Specifies the CropBy type. Values are DEFAULT, ASPECTRATIO, REGION, OFFSET. - * @param {boolean} safe - (Optional) Ensures that the output image never returns an error due to the specified crop area being + * @param {CropBy} [options.cropBy] - (Optional) Specifies the CropBy type. Values are DEFAULT, ASPECTRATIO, REGION, OFFSET. + * @param {boolean} [options.safe] - (Optional) Ensures that the output image never returns an error due to the specified crop area being * out of bounds. The output image is returned as an intersection of the source image and the defined crop area. - * @param {boolean} smart - (Optional) Ensures crop is done using content-aware algorithms. Content-aware image cropping returns a + * @param {boolean} [options.smart] - (Optional) Ensures crop is done using content-aware algorithms. Content-aware image cropping returns a * cropped image that automatically fits the defined dimensions while intelligently including the most important components of the image. + * @returns {ImageTransform} * @example * const url = 'www.example.com'; * const transformObj = new ImageTransform().crop({ width: 100, height: 200 }) @@ -177,8 +179,11 @@ export class ImageTransform { this.obj.crop = [width.toString(), height.toString(), `offset-x${xval}`, `offset-y${yval}`]; } } - if (safe) this.obj.crop = [...this.obj.crop, 'safe']; - if (smart) this.obj.crop = [...this.obj.crop, 'smart']; + // Only add safe/smart when crop is an array (not for ASPECTRATIO which is a string) + if (Array.isArray(this.obj.crop)) { + if (safe) this.obj.crop = [...this.obj.crop, 'safe']; + if (smart) this.obj.crop = [...this.obj.crop, 'smart']; + } return this; } @@ -187,8 +192,8 @@ export class ImageTransform { * @method fit * @memberof ImageTransform * @description The fit parameter enables you to fit the given image properly within the specified height and width. - * @returns {ImageTransform} * @param {FitBy} type - Specifies fit type (BOUNDS or CROP). + * @returns {ImageTransform} * @example * const url = 'www.example.com'; * const transformObj = new ImageTransform().resize({ width: 200, height: 200 }).fit(FitBy.BOUNDS); @@ -204,9 +209,9 @@ export class ImageTransform { /** * @method trim * @memberof ImageTransform - * @description The trim parameterlets you trim an image from the edges. This is especially useful for removing border or white spaces. - * @returns {ImageTransform} + * @description The trim parameter lets you trim an image from the edges. This is especially useful for removing border or white spaces. * @param {number | number[]} trimValues - specifies values for top, right, bottom, and left edges of an image. + * @returns {ImageTransform} * @example * const url = 'www.example.com'; * const transformObj = new ImageTransform().trim([25, 50, 75, 90]); @@ -234,9 +239,9 @@ export class ImageTransform { * @memberof ImageTransform * @description The orient parameter lets you control the cardinal orientation of the given image. Using this parameter, * you can orient the image right or left, flip horizontally or vertically or both - * @returns {ImageTransform} * @param {Orientation} orientType - Type of Orientation. Values are DEFAULT, FLIP_HORIZONTAL, FLIP_HORIZONTAL_VERTICAL, * FLIP_VERTICAL, FLIP_HORIZONTAL_LEFT, RIGHT, FLIP_HORIZONTAL_RIGHT, LEFT. + * @returns {ImageTransform} * @example * const url = 'www.example.com'; * const transformObj = new ImageTransform().orient(Orientation.FLIP_HORIZONTAL); @@ -254,18 +259,19 @@ export class ImageTransform { * @memberof ImageTransform * @description The overlay parameter allows you to put one image on top of another. * You need to specify the relative URL of the image as value for this parameter. - * @returns {ImageTransform} - * @param {string} relativeURL - URL of the image to overlay on base image - * @param {OverlayAlign | OverlayAlign[]} align - lets you define the position of the overlay image. + * @param {object} options - Overlay options object + * @param {string} options.relativeURL - URL of the image to overlay on base image + * @param {OverlayAlign | OverlayAlign[]} [options.align] - lets you define the position of the overlay image. * Accepted values are TOP, BOTTOM, LEFT, RIGHT, MIDDLE, CENTER. - * @param {OverlayRepeat} repeat - lets you define how the overlay image will be repeated on the given image. + * @param {OverlayRepeat} [options.repeat] - lets you define how the overlay image will be repeated on the given image. * Accepted values are X, Y, BOTH. - * @param {string | number} width - lets you define the width of the overlay image. + * @param {string | number} [options.width] - lets you define the width of the overlay image. * For pixels, use any whole number between 1 and 8192. For percentages, use any decimal number between 0.0 and 0.99. - * @param {string | number} height - lets you define the height of the overlay image. + * @param {string | number} [options.height] - lets you define the height of the overlay image. * For pixels, use any whole number between 1 and 8192. For percentages, use any decimal number between 0.0 and 0.99 - * @param {number | number[]} pad - lets you add extra pixels to the edges of an image. + * @param {number | number[]} [options.pad] - lets you add extra pixels to the edges of an image. * This is useful if you want to add whitespace or border to an image. + * @returns {ImageTransform} * @example * const url = 'www.example.com'; * const transformObj = new ImageTransform().overlay({ relativeURL: overlayImgURL }); @@ -315,8 +321,8 @@ export class ImageTransform { * @memberof ImageTransform * @description The padding parameter lets you add extra pixels to the edges of an image. * This is useful if you want to add whitespace or border to an image. - * @returns {ImageTransform} * @param {number | number[]} padding - padding value in pixels or percentages + * @returns {ImageTransform} * @example * const url = 'www.example.com'; * const transformObj = new ImageTransform().padding([25, 50, 75, 90]); @@ -337,9 +343,9 @@ export class ImageTransform { /** * @method bgColor * @memberof ImageTransform - * @description The bgColor parameter lets you set a backgroud color for the given image. - * @returns {ImageTransform} + * @description The bgColor parameter lets you set a background color for the given image. * @param {string | number[]} color - color of the background + * @returns {ImageTransform} * @example * const url = 'www.example.com'; * const transformObj = new ImageTransform().bgColor('cccccc'); @@ -361,8 +367,8 @@ export class ImageTransform { * @method dpr * @memberof ImageTransform * @description The dpr parameter lets you deliver images with appropriate size to devices that come with a defined device pixel ratio. - * @returns {ImageTransform} * @param {number} dprValue - value of device pixel ratio 1-10000 or 0.0 to 9999.999 + * @returns {ImageTransform} * @example * const url = 'www.example.com'; * const transformObj = new ImageTransform().resize({ width: 300, height: 500 }).dpr(10); @@ -379,8 +385,8 @@ export class ImageTransform { * @method blur * @memberof ImageTransform * @description The blur parameter allows you to decrease the focus and clarity of a given image. - * @returns {ImageTransform} * @param {number} blurValue - to set the blur intensity between 1-1000. + * @returns {ImageTransform} * @example * const url = 'www.example.com'; * const transformObj = new ImageTransform().blur(10); @@ -415,10 +421,10 @@ export class ImageTransform { * @method sharpen * @memberof ImageTransform * @description The sharpen parameter allows you to increase the definition of the edges of objects in an image. - * @returns {ImageTransform} * @param {number} amount - [0-10] specifies the amount of contrast to be set for the image edges * @param {number} radius - [1-1000] specifies the radius of the image edges * @param {number} threshold - [0-255] specifies the range of image edges that need to be ignored while sharpening + * @returns {ImageTransform} * @example * const url = 'www.example.com'; * const transformObj = new ImageTransform().sharpen(5, 1000, 2); @@ -435,8 +441,8 @@ export class ImageTransform { * @method saturation * @memberof ImageTransform * @description The saturation parameter allows you to increase or decrease the intensity of the colors in a given image. - * @returns {ImageTransform} * @param {number} saturationValue - to set the saturation of image between -100 to 100 + * @returns {ImageTransform} * @example * const url = 'www.example.com'; * const transformObj = new ImageTransform().saturation(-80.99); @@ -452,9 +458,9 @@ export class ImageTransform { /** * @method contrast * @memberof ImageTransform - * @description The contrast parameter lets you enable the functionality that automates certain image optimization features. - * @returns {ImageTransform} + * @description The contrast parameter lets you adjust the contrast level of the image. * @param {number} contrastValue - to set the contrast of image between -100 to 100 + * @returns {ImageTransform} * @example * const url = 'www.example.com'; * const transformObj = new ImageTransform().contrast(-80.99); @@ -470,9 +476,9 @@ export class ImageTransform { /** * @method brightness * @memberof ImageTransform - * @description The brightness parameter lets you enable the functionality that automates certain image optimization features. + * @description The brightness parameter lets you adjust the brightness level of the image. + * @param {number} brightnessValue - to set the brightness of image between -100 to 100 * @returns {ImageTransform} - * @param {number} contrastValue - to set the brightness of image between -100 to 100 * @example * const url = 'www.example.com'; * const transformObj = new ImageTransform().brightness(80.50); @@ -490,9 +496,9 @@ export class ImageTransform { * @memberof ImageTransform * @description The resizeFilter parameter allows you to use the resizing filter to increase or * decrease the number of pixels in a given image. - * @returns {ImageTransform} * @param {ResizeFilter} type - type of Filter to apply * Values are NEAREST, BILINEAR, BICUBIC, LANCZOS2, LANCZOS3. + * @returns {ImageTransform} * @example * const url = 'www.example.com'; * const transformObj = new ImageTransform().resize({ width: 500, height: 550 }).resizeFilter(ResizeFilter.NEAREST); @@ -511,12 +517,12 @@ export class ImageTransform { * @description The canvas parameter allows you to increase the size of the canvas that surrounds an image. * You can specify the height and width of the canvas area in pixels or percentage or define the height and width * of the aspect ratio of the canvas. You can also define the starting point for the canvas area or offset the canvas on its X and Y axis. - * @returns {ImageTransform} * @param {string | number} width - sets width of the canvas * @param {string | number} height - sets height of the canvas * @param {string | number} xval - defines the X-axis position of the top left corner or horizontal offset * @param {string | number} yval - defines the Y-axis position of the top left corner or vertical offset * @param {CanvasBy} canvasBy - Specifies the canvasBy type. Accepted values are DEFAULT, ASPECTRATIO, REGION, OFFSET. + * @returns {ImageTransform} * @example * const url = 'www.example.com'; * const transformObj = new ImageTransform().canvas({ width: 100, height: 200 }); diff --git a/src/lib/pagination.ts b/src/lib/pagination.ts index 0a4748a..6005f08 100644 --- a/src/lib/pagination.ts +++ b/src/lib/pagination.ts @@ -6,8 +6,8 @@ export class Pagination { * @method constructor * @memberof Pagination * @description Create a pagination class object to paginate through the query response - * @param {baseQuery} object of class BaseQUery - * @param {paginationObj} object to send skip and limit values + * @param {BaseQuery} object of class BaseQuery + * @param {PaginationObj} object to send skip and limit values * @example * import contentstack from '@contentstack/delivery-sdk' * diff --git a/src/lib/query.ts b/src/lib/query.ts index 96ecc1d..e731ffd 100644 --- a/src/lib/query.ts +++ b/src/lib/query.ts @@ -97,7 +97,7 @@ export class Query extends BaseQuery { * const query = stack.contentType("contentTypeUid").entry().query(); * const result = await query.regex('title','^Demo').find() * // OR - * const result = await query..regex('title','^Demo', 'i').find() // regex with options + * const result = await query.regex('title','^Demo', 'i').find() // regex with options * @returns {Query} */ regex(fieldUid: string, regexPattern: string, options?: string): Query { @@ -122,9 +122,12 @@ export class Query extends BaseQuery { * The query retrieves all entries that satisfy the query conditions made on referenced fields * This method sets the '$in_query' parameter to a reference field UID and a query instance in the API request. * @example - * const stack = contentstack.stack("apiKey", "deliveryKey", "environment"); + * import contentstack from '@contentstack/delivery-sdk' + * + * const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" }); * const query = stack.contentType("contentTypeUid").entry().query(); - * query.whereIn("brand") + * const subQuery = stack.contentType("referencedContentTypeUid").entry().query().where("title", QueryOperation.EQUALS, "value"); + * query.whereIn("brand", subQuery) * const res = await query.find() * * @param {string} referenceUid - UID of the reference field to query. @@ -147,9 +150,12 @@ export class Query extends BaseQuery { * This query works the opposite of $in_query and retrieves all entries that does not satisfy query conditions made on referenced fields. * This method sets the '$nin_query' parameter to a reference field UID and a query instance in the API request. * @example - * const stack = contentstack.stack("apiKey", "deliveryKey", "environment"); + * import contentstack from '@contentstack/delivery-sdk' + * + * const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" }); * const query = stack.contentType("contentTypeUid").entry().query(); - * query.whereNotIn("brand") + * const subQuery = stack.contentType("referencedContentTypeUid").entry().query().where("title", QueryOperation.EQUALS, "value"); + * query.whereNotIn("brand", subQuery) * const res = await query.find() * * @param {string} referenceUid - UID of the reference field to query. @@ -171,10 +177,12 @@ export class Query extends BaseQuery { * @description In case of '$and' get entries that satisfy all the conditions provided in the '$and' query and * in case of '$or' query get all entries that satisfy at least one of the given conditions provided in the '$or' query. * @example - * const stack = contentstack.stack("apiKey", "deliveryKey", "environment"); + * import contentstack from '@contentstack/delivery-sdk' + * + * const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" }); * const query = stack.contentType("contentType1Uid").entry().query(); - * const subQuery1 = stack.contentType("contentType2Uid").query().where("price", QueryOperation.IS_LESS_THAN, fields=90); - * const subQuery2 = stack.contentType("contentType3Uid").query().where("discount", QueryOperation.INCLUDES, fields=[20, 45]); + * const subQuery1 = stack.contentType("contentType2Uid").entry().query().where("price", QueryOperation.IS_LESS_THAN, 90); + * const subQuery2 = stack.contentType("contentType3Uid").entry().query().where("discount", QueryOperation.INCLUDES, [20, 45]); * query.queryOperator(QueryOperator.AND, subQuery1, subQuery2) * const res = await query.find() * @@ -201,9 +209,10 @@ export class Query extends BaseQuery { * * const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" }); * const query = stack.contentType("contentTypeUid").entry().query(); - * const result = await query.query({'brand': {'$nin_query': {'title': 'Apple Inc.'}}}).getQuery() + * const result = query.getQuery() * // OR - * const asset = await stack.asset().query({'brand': {'$nin_query': {'title': 'Apple Inc.'}}}).getQuery() + * const assetQuery = stack.asset().query(); + * const assetResult = assetQuery.getQuery() * * @returns {Query} */ @@ -214,7 +223,9 @@ export class Query extends BaseQuery { /** * @method containedIn * @memberof Query - * @description Returns the raw (JSON) query based on the filters applied on Query object. + * @description Filters entries where the field value is contained in the provided array of values + * @param {string} key - The field UID to filter on + * @param {(string | number | boolean)[]} value - Array of values to match against * @example * import contentstack from '@contentstack/delivery-sdk' * @@ -238,9 +249,11 @@ export class Query extends BaseQuery { } /** - * @method NoContainedIn + * @method notContainedIn * @memberof Query - * @description Returns the raw (JSON) query based on the filters applied on Query object. + * @description Filters entries where the field value is not contained in the provided array of values + * @param {string} key - The field UID to filter on + * @param {(string | number | boolean)[]} value - Array of values to exclude * @example * import contentstack from '@contentstack/delivery-sdk' * @@ -266,7 +279,8 @@ export class Query extends BaseQuery { /** * @method exists * @memberof Query - * @description Returns the raw (JSON) query based on the filters applied on Query object. + * @description Filters entries where the specified field exists + * @param {string} key - The field UID to check for existence * @example * import contentstack from '@contentstack/delivery-sdk' * @@ -288,7 +302,8 @@ export class Query extends BaseQuery { /** * @method notExists * @memberof Query - * @description Returns the raw (JSON) query based on the filters applied on Query object. + * @description Filters entries where the specified field does not exist + * @param {string} key - The field UID to check for non-existence * @example * import contentstack from '@contentstack/delivery-sdk' * @@ -310,7 +325,8 @@ export class Query extends BaseQuery { /** * @method or * @memberof Query - * @description Returns the raw (JSON) query based on the filters applied on Query object. + * @description Combines multiple queries with OR logic - returns entries that match at least one of the provided queries + * @param {...Query} queries - Query instances to combine with OR logic * @example * import contentstack from '@contentstack/delivery-sdk' * @@ -333,14 +349,15 @@ export class Query extends BaseQuery { /** * @method and * @memberof Query - * @description Returns the raw (JSON) query based on the filters applied on Query object. + * @description Combines multiple queries with AND logic - returns entries that match all of the provided queries + * @param {...Query} queries - Query instances to combine with AND logic * @example * import contentstack from '@contentstack/delivery-sdk' * * const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" }); - * const query1 = stack.contentType('contenttype_uid').Entry().query().containedIn('fieldUID', ['value']); - * const query2 = stack.contentType('contenttype_uid').Entry().query().where('fieldUID', QueryOperation.EQUALS, 'value2'); - * const query = await stack.contentType('contenttype_uid').Entry().query().and(query1, query2).find(); + * const query1 = stack.contentType('contenttype_uid').entry().query().containedIn('fieldUID', ['value']); + * const query2 = stack.contentType('contenttype_uid').entry().query().where('fieldUID', QueryOperation.EQUALS, 'value2'); + * const query = await stack.contentType('contenttype_uid').entry().query().and(query1, query2).find(); * * @returns {Query} */ @@ -356,12 +373,14 @@ export class Query extends BaseQuery { /** * @method equalTo * @memberof Query - * @description Returns the raw (JSON) query based on the filters applied on Query object. + * @description Filters entries where the field value equals the specified value + * @param {string} key - The field UID to filter on + * @param {string | number | boolean} value - The value to match * @example * import contentstack from '@contentstack/delivery-sdk' * * const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" }); - * const query = await stack.contentType('contenttype_uid').Entry().query().equalTo('fieldUid', 'value').find(); + * const query = await stack.contentType('contenttype_uid').entry().query().equalTo('fieldUid', 'value').find(); * * @returns {Query} */ @@ -381,12 +400,14 @@ export class Query extends BaseQuery { /** * @method notEqualTo * @memberof Query - * @description Returns the raw (JSON) query based on the filters applied on Query object. + * @description Filters entries where the field value does not equal the specified value + * @param {string} key - The field UID to filter on + * @param {string | number | boolean} value - The value to exclude * @example * import contentstack from '@contentstack/delivery-sdk' * * const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" }); - * const query = await stack.contentType('contenttype_uid').Entry().query().notEqualTo('fieldUid', 'value').find(); + * const query = await stack.contentType('contenttype_uid').entry().query().notEqualTo('fieldUid', 'value').find(); * * @returns {Query} */ @@ -406,13 +427,15 @@ export class Query extends BaseQuery { /** * @method referenceIn * @memberof Query - * @description Returns the raw (JSON) query based on the filters applied on Query object. + * @description Filters entries where the reference field matches entries from the provided query + * @param {string} key - The reference field UID to filter on + * @param {Query} query - Query instance to match referenced entries against * @example * import contentstack from '@contentstack/delivery-sdk' * * const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" }); - * const query = stack.contentType('contenttype_uid').query().where('title', QueryOperation.EQUALS, 'value'); - * const entryQuery = await stack.contentType('contenttype_uid').query().referenceIn('reference_uid', query).find(); + * const query = stack.contentType('contenttype_uid').entry().query().where('title', QueryOperation.EQUALS, 'value'); + * const entryQuery = await stack.contentType('contenttype_uid').entry().query().referenceIn('reference_uid', query).find(); * * @returns {Query} */ @@ -428,13 +451,15 @@ export class Query extends BaseQuery { /** * @method referenceNotIn * @memberof Query - * @description Returns the raw (JSON) query based on the filters applied on Query object. + * @description Filters entries where the reference field does not match entries from the provided query + * @param {string} key - The reference field UID to filter on + * @param {Query} query - Query instance to exclude referenced entries against * @example * import contentstack from '@contentstack/delivery-sdk' * * const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" }); - * const query = stack.contentType('contenttype_uid').query().where('title', QueryOperation.EQUALS, 'value'); - * const entryQuery = await stack.contentType('contenttype_uid').query().referenceNotIn('reference_uid', query).find(); + * const query = stack.contentType('contenttype_uid').entry().query().where('title', QueryOperation.EQUALS, 'value'); + * const entryQuery = await stack.contentType('contenttype_uid').entry().query().referenceNotIn('reference_uid', query).find(); * * @returns {Query} */ @@ -450,13 +475,14 @@ export class Query extends BaseQuery { /** * @method tags * @memberof Query - * @description Returns the raw (JSON) query based on the filters applied on Query object. + * @description Filters entries that have any of the specified tags + * @param {(string | number | boolean)[]} values - Array of tag values to filter by * @example * import contentstack from '@contentstack/delivery-sdk' * * const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" }); - * const query = stack.contentType('contenttype_uid').query().where('title', QueryOperation.EQUALS, 'value'); - * const entryQuery = await stack.contentType('contenttype_uid').query().tags(['tag1']).find(); + * const query = stack.contentType('contenttype_uid').entry().query().where('title', QueryOperation.EQUALS, 'value'); + * const entryQuery = await stack.contentType('contenttype_uid').entry().query().tags(['tag1']).find(); * * @returns {Query} */ @@ -472,13 +498,14 @@ export class Query extends BaseQuery { /** * @method search * @memberof Query - * @description Returns the raw (JSON) query based on the filters applied on Query object. + * @description Enables typeahead search functionality for the query + * @param {string} key - The search term to use for typeahead search * @example * import contentstack from '@contentstack/delivery-sdk' * * const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" }); - * const query = stack.contentType('contenttype_uid').query().where('title', QueryOperation.EQUALS, 'value'); - * const entryQuery = await stack.contentType('contenttype_uid').query().search('key').find(); + * const query = stack.contentType('contenttype_uid').entry().query().where('title', QueryOperation.EQUALS, 'value'); + * const entryQuery = await stack.contentType('contenttype_uid').entry().query().search('key').find(); * * @returns {Query} */ @@ -494,13 +521,15 @@ export class Query extends BaseQuery { /** * @method lessThan * @memberof Query - * @description Returns the raw (JSON) query based on the filters applied on Query object. + * @description Filters entries where the field value is less than the specified value + * @param {string} key - The field UID to filter on + * @param {string | number} value - The value to compare against * @example * import contentstack from '@contentstack/delivery-sdk' * * const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" }); - * const query = stack.contentType('contenttype_uid').query().where('title', QueryOperation.EQUALS, 'value'); - * const entryQuery = await stack.contentType('contenttype_uid').query().lessThan('fieldUid', 'value').find(); + * const query = stack.contentType('contenttype_uid').entry().query().where('title', QueryOperation.EQUALS, 'value'); + * const entryQuery = await stack.contentType('contenttype_uid').entry().query().lessThan('fieldUid', 'value').find(); * * @returns {Query} */ @@ -521,13 +550,15 @@ export class Query extends BaseQuery { /** * @method lessThanOrEqualTo * @memberof Query - * @description Returns the raw (JSON) query based on the filters applied on Query object. + * @description Filters entries where the field value is less than or equal to the specified value + * @param {string} key - The field UID to filter on + * @param {string | number} value - The value to compare against * @example * import contentstack from '@contentstack/delivery-sdk' * * const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" }); - * const query = stack.contentType('contenttype_uid').query().where('title', QueryOperation.EQUALS, 'value'); - * const entryQuery = await stack.contentType('contenttype_uid').query().lessThanOrEqualTo('fieldUid', 'value').find(); + * const query = stack.contentType('contenttype_uid').entry().query().where('title', QueryOperation.EQUALS, 'value'); + * const entryQuery = await stack.contentType('contenttype_uid').entry().query().lessThanOrEqualTo('fieldUid', 'value').find(); * * @returns {Query} */ @@ -547,13 +578,15 @@ export class Query extends BaseQuery { /** * @method greaterThan * @memberof Query - * @description Returns the raw (JSON) query based on the filters applied on Query object. + * @description Filters entries where the field value is greater than the specified value + * @param {string} key - The field UID to filter on + * @param {string | number} value - The value to compare against * @example * import contentstack from '@contentstack/delivery-sdk' * * const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" }); - * const query = stack.contentType('contenttype_uid').query().where('title', QueryOperation.EQUALS, 'value'); - * const entryQuery = await stack.contentType('contenttype_uid').query().greaterThan('fieldUid', 'value').find(); + * const query = stack.contentType('contenttype_uid').entry().query().where('title', QueryOperation.EQUALS, 'value'); + * const entryQuery = await stack.contentType('contenttype_uid').entry().query().greaterThan('fieldUid', 'value').find(); * * @returns {Query} */ @@ -573,13 +606,15 @@ export class Query extends BaseQuery { /** * @method greaterThanOrEqualTo * @memberof Query - * @description Returns the raw (JSON) query based on the filters applied on Query object. + * @description Filters entries where the field value is greater than or equal to the specified value + * @param {string} key - The field UID to filter on + * @param {string | number} value - The value to compare against * @example * import contentstack from '@contentstack/delivery-sdk' * * const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" }); - * const query = stack.contentType('contenttype_uid').query().where('title', QueryOperation.EQUALS, 'value'); - * const entryQuery = await stack.contentType('contenttype_uid').query().greaterThanOrEqualTo('fieldUid', 'value').find(); + * const query = stack.contentType('contenttype_uid').entry().query().where('title', QueryOperation.EQUALS, 'value'); + * const entryQuery = await stack.contentType('contenttype_uid').entry().query().greaterThanOrEqualTo('fieldUid', 'value').find(); * * @returns {Query} */ diff --git a/src/lib/stack.ts b/src/lib/stack.ts index b4fe63c..f36046f 100644 --- a/src/lib/stack.ts +++ b/src/lib/stack.ts @@ -21,7 +21,7 @@ export class Stack { /** * @method asset - * @memberOf Stack + * @memberof Stack * @param {String} uid - uid of the asset * @description Creates an object for all assets of a stack by default. To retrieve a single asset, specify its UID. * @@ -45,9 +45,9 @@ export class Stack { /** * @method contentType - * @memberOf Stack - * @param {String} uid - uid of the asset - * @description Retrieves all contentTypes of a stack by default. To retrieve a single asset, specify its UID. + * @memberof Stack + * @param {String} uid - uid of the contentType + * @description Retrieves all contentTypes of a stack by default. To retrieve a single contentType, specify its UID. * * @returns {ContentType} * @example @@ -68,11 +68,12 @@ export class Stack { /** * @method Taxonomy - * @memberOf Stack + * @memberof Stack * @description Sets the url to /taxonomies/entries. Pass a query to fetch entries with taxonomies * - * @returns {TaxonomyQuery} * @example - * import contentstack from '@contentstack/typescript' + * @returns {TaxonomyQuery} + * @example + * import contentstack from '@contentstack/delivery-sdk' * * const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" }); @@ -84,14 +85,18 @@ export class Stack { /** * @method GlobalField - * @memberOf Stack - * @param {String} uid - uid of the asset - * @description Retrieves all contentTypes of a stack by default. To retrieve a single asset, specify its UID. + * @memberof Stack + * @param {String} uid - uid of the globalField + * @description Retrieves all globalFields of a stack by default. To retrieve a single globalField, specify its UID. * - * @returns {ContentType} - * const contentType = stack.contentType() // For collection of contentType + * @returns {GlobalField} + * @example + * import contentstack from '@contentstack/delivery-sdk' + * + * const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" }); + * const globalField = stack.globalField() // For collection of globalField * // OR - * const contentType = stack.contentType('contentTypeUid') // For a single contentType with uid 'contentTypeUid' + * const globalField = stack.globalField('globalFieldUid') // For a single globalField with uid 'globalFieldUid' */ globalField(): GlobalFieldQuery; globalField(uid: string): GlobalField; @@ -103,7 +108,7 @@ export class Stack { /** * @method setLocale - * @memberOf Stack + * @memberof Stack * @description Sets the locale of the API server * @param {String} locale - valid locale e.g. fr-fr * @return {Stack} @@ -120,25 +125,46 @@ export class Stack { /** * @method sync - * @memberOf Stack + * @memberof Stack * @description Syncs your Contentstack data with your app and ensures that the data is always up-to-date by providing delta updates - * @param {object} params - params is an object that supports ‘locale’, ‘start_date’, ‘content_type_uid’, and ‘type’ queries. + * @param {object} params - params is an object that supports 'locale', 'start_date', 'content_type_uid', and 'type' queries. * @example - * Stack.sync() // For initializing sync + * import contentstack from '@contentstack/delivery-sdk' + * + * const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" }); + * await stack.sync() // For initializing sync * @example - * Stack.sync({ 'locale': 'en-us'}) //For initializing sync with entries of a specific locale + * import contentstack from '@contentstack/delivery-sdk' + * + * const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" }); + * await stack.sync({ 'locale': 'en-us'}) //For initializing sync with entries of a specific locale * @example - * Stack.sync({ 'start_date': '2018-10-22'}) //For initializing sync with entries published after a specific date + * import contentstack from '@contentstack/delivery-sdk' + * + * const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" }); + * await stack.sync({ 'start_date': '2018-10-22'}) //For initializing sync with entries published after a specific date * @example - * Stack.sync({ 'content_type_uid': 'session'}) //For initializing sync with entries of a specific content type + * import contentstack from '@contentstack/delivery-sdk' + * + * const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" }); + * await stack.sync({ 'content_type_uid': 'session'}) //For initializing sync with entries of a specific content type * @example - * Stack.sync({ 'type': 'entry_published'}) + * import contentstack from '@contentstack/delivery-sdk' + * + * const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" }); + * await stack.sync({ 'type': 'entry_published'}) * //Use the type parameter to get a specific type of content. Supports'asset_published', * // 'entry_published', 'asset_unpublished', 'entry_unpublished', 'asset_deleted', 'entry_deleted', 'content_type_deleted'. * @example - * Stack.sync({'pagination_token': ''}) // For fetching the next batch of entries using pagination token + * import contentstack from '@contentstack/delivery-sdk' + * + * const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" }); + * await stack.sync({'pagination_token': ''}) // For fetching the next batch of entries using pagination token * @example - * Stack.sync({'sync_token': ''}) // For performing subsequent sync after initial sync + * import contentstack from '@contentstack/delivery-sdk' + * + * const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" }); + * await stack.sync({'sync_token': ''}) // For performing subsequent sync after initial sync * @instance */ async sync(params: SyncType | SyncStack = {}, recursive = false) { @@ -205,7 +231,7 @@ export class Stack { /** * @method setPort - * @memberOf Stack + * @memberof Stack * @description Sets the port of the host * @param {Number} port - Port Number * @return {Stack} @@ -218,7 +244,7 @@ export class Stack { /** * @method setDebug - * @memberOf Stack + * @memberof Stack * @description Sets the debug option * @param {Number} debug - Debug value * @return {Stack} diff --git a/src/lib/utils.ts b/src/lib/utils.ts index 341e1de..c23ef6b 100644 --- a/src/lib/utils.ts +++ b/src/lib/utils.ts @@ -7,10 +7,19 @@ export function getHostforRegion(region: string = "aws_na", host?: string): stri return getContentstackEndpoint(region, 'contentDelivery', true) as string; } +/** + * Checks if the code is running in a browser environment + * @returns {boolean} True if running in browser, false otherwise + */ export function isBrowser() { return (typeof window !== "undefined"); } +/** + * Encodes query parameters recursively, handling nested objects + * @param {params} params - Query parameters object to encode + * @returns {params} Encoded query parameters object + */ export function encodeQueryParams(params: params): params { const encodedParams: params = {}; diff --git a/src/persistance/config/persistance-storage-config.ts b/src/persistance/config/persistance-storage-config.ts index 39029fe..cc223d7 100644 --- a/src/persistance/config/persistance-storage-config.ts +++ b/src/persistance/config/persistance-storage-config.ts @@ -1,15 +1,32 @@ import { Storage } from '../types/storage'; import { StorageType } from '../types/storage-type'; +/** + * Configuration type for persistence store + * Can be either a custom storage with Store interface or standard storage with PersistanceStoreOptions + */ export type PersistanceStoreConfig = | (Store & PersistanceStoreOptions) | ({ storeType?: StorageType } & PersistanceStoreOptions); + +/** + * Interface for custom storage configuration + */ export interface Store { + /** Custom storage implementation */ storage: Storage; + /** Storage type identifier */ storeType: 'customStorage'; } + +/** + * Options for persistence store configuration + */ export interface PersistanceStoreOptions { - maxAge?: number; // default 24 hrs - serializer?: (content: any) => string; // default JSON.stringify - deserializer?: (cacheString: string) => any; // default JSON.parse + /** Maximum age for cached items in milliseconds (default: 24 hours) */ + maxAge?: number; + /** Serializer function for storing data (default: JSON.stringify) */ + serializer?: (content: any) => string; + /** Deserializer function for retrieving data (default: JSON.parse) */ + deserializer?: (cacheString: string) => any; } diff --git a/src/persistance/persistance-store.ts b/src/persistance/persistance-store.ts index 008e569..be6e4a7 100644 --- a/src/persistance/persistance-store.ts +++ b/src/persistance/persistance-store.ts @@ -4,11 +4,19 @@ import { memoryStorage } from './storages/memory-storage'; import { Storage } from './types/storage'; import { StorageType } from './types/storage-type'; +/** + * Persistence store for caching data with expiration support + * Supports localStorage, memoryStorage, and custom storage implementations + */ export class PersistanceStore { protected store: Storage = localStorage; readonly config: PersistanceStoreConfig; protected name: string; + /** + * Creates a new PersistanceStore instance + * @param {PersistanceStoreConfig} [config] - Configuration options for the store + */ constructor(config?: PersistanceStoreConfig) { let defaultConfig: PersistanceStoreConfig = { storeType: 'localStorage', @@ -40,6 +48,13 @@ export class PersistanceStore { break; } } + /** + * Sets an item in the store with optional expiration + * @param {string} key - The key to store the value under + * @param {any} value - The value to store + * @param {string} [contentTypeUid] - Optional content type UID for key scoping + * @param {number} [maxAge] - Optional maximum age in milliseconds (overrides config maxAge) + */ setItem(key: string, value: any, contentTypeUid?: string, maxAge?: number) { if (!key) { return; @@ -59,6 +74,12 @@ export class PersistanceStore { this.store.setItem(generatedKey, content); } + /** + * Gets an item from the store if it exists and hasn't expired + * @param {string} key - The key to retrieve + * @param {string} [contentTypeUid] - Optional content type UID for key scoping + * @returns {any} The stored value if found and not expired, undefined otherwise + */ getItem(key: string, contentTypeUid?: string): any { const generatedKey = this.generateCSKey(key, contentTypeUid); const content = this.store.getItem(generatedKey); @@ -75,11 +96,20 @@ export class PersistanceStore { } } + /** + * Removes an item from the store + * @param {string} key - The key to remove + * @param {string} [contentTypeUid] - Optional content type UID for key scoping + */ removeItem(key: string, contentTypeUid?: string) { const generatedKey = this.generateCSKey(key, contentTypeUid); this.store.removeItem(generatedKey); } + /** + * Clears all items from the store, or items matching a specific content type UID + * @param {string} [contentTypeUid] - Optional content type UID to clear only matching items + */ clear(contentTypeUid?: string) { if (!contentTypeUid) { this.store.clear(); diff --git a/src/persistance/storages/local-storage.ts b/src/persistance/storages/local-storage.ts index 5152820..9ee4479 100644 --- a/src/persistance/storages/local-storage.ts +++ b/src/persistance/storages/local-storage.ts @@ -11,13 +11,26 @@ export const localStorage: Storage = { setItem: setItem, }; +/** + * Gets the localStorage instance from the global object + * @returns {Storage} The localStorage instance + * @private + */ function _localStorage() { return iGlobal.localStorage; } +/** + * Clears all items from localStorage + */ function clear() { _localStorage().clear(); } + +/** + * Iterates over all items in localStorage and calls the callback for each + * @param {Callback} callback - Function to call for each item with (value, key) parameters + */ function each(callback: Callback) { for (let i = _localStorage().length - 1; i >= 0; i--) { const key = _localStorage().key(i); @@ -27,15 +40,31 @@ function each(callback: Callback) { } } } +/** + * Sets an item in localStorage + * @param {string} key - The key to store under + * @param {string} value - The value to store + */ function setItem(key: string, value: string) { if (!key) { return; } _localStorage().setItem(key, value); } + +/** + * Gets an item from localStorage + * @param {string} key - The key to retrieve + * @returns {string | null} The stored value or null if not found + */ function getItem(key: string): string | null { return _localStorage().getItem(key); } + +/** + * Removes an item from localStorage + * @param {string} key - The key to remove + */ function removeItem(key: string) { _localStorage().removeItem(key); } diff --git a/src/persistance/storages/memory-storage.ts b/src/persistance/storages/memory-storage.ts index bf1020b..2596c30 100644 --- a/src/persistance/storages/memory-storage.ts +++ b/src/persistance/storages/memory-storage.ts @@ -12,24 +12,48 @@ export const memoryStorage: Storage = { let memory: { [key: string]: string | null } = {}; +/** + * Clears all items from memory storage + */ function clear() { memory = {}; } + +/** + * Iterates over all items in memory storage and calls the callback for each + * @param {Callback} callback - Function to call for each item with (value, key) parameters + */ function each(callback: Callback) { for (const key in memory) { const value = getItem(key); callback(value, key); } } +/** + * Sets an item in memory storage + * @param {string} key - The key to store under + * @param {string} value - The value to store + */ function setItem(key: string, value: string) { if (!key) { return; } memory[key] = value; } + +/** + * Gets an item from memory storage + * @param {string} key - The key to retrieve + * @returns {string | null} The stored value or null if not found + */ function getItem(key: string): string | null { return memory[key]; } + +/** + * Removes an item from memory storage + * @param {string} key - The key to remove + */ function removeItem(key: string) { delete memory[key]; } From a81d173c3230d7e17fd6e37dbeb1d7fba772ea92 Mon Sep 17 00:00:00 2001 From: raj pandey Date: Tue, 25 Nov 2025 21:19:33 +0530 Subject: [PATCH 5/7] Fixed Doc string --- src/lib/asset-query.ts | 2 +- src/lib/base-query.ts | 8 ++++---- src/lib/contentstack.ts | 2 +- src/lib/entries.ts | 14 ++++++------- src/lib/entry.ts | 2 +- src/lib/query.ts | 44 ++++++++++++++++++----------------------- src/lib/stack.ts | 4 ++-- 7 files changed, 35 insertions(+), 41 deletions(-) diff --git a/src/lib/asset-query.ts b/src/lib/asset-query.ts index 6bec319..0c1b906 100644 --- a/src/lib/asset-query.ts +++ b/src/lib/asset-query.ts @@ -135,7 +135,7 @@ export class AssetQuery extends BaseQuery { * 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); diff --git a/src/lib/base-query.ts b/src/lib/base-query.ts index dc9fe79..5e885fe 100644 --- a/src/lib/base-query.ts +++ b/src/lib/base-query.ts @@ -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} */ @@ -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} */ @@ -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() * @@ -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() * diff --git a/src/lib/contentstack.ts b/src/lib/contentstack.ts index 9fae49a..c95ac48 100644 --- a/src/lib/contentstack.ts +++ b/src/lib/contentstack.ts @@ -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 { diff --git a/src/lib/entries.ts b/src/lib/entries.ts index 685268f..30f2c24 100644 --- a/src/lib/entries.ts +++ b/src/lib/entries.ts @@ -137,8 +137,8 @@ export class Entries extends BaseQuery { * import contentstack from '@contentstack/delivery-sdk' * * const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" }); - * const query = stack.contentType("contentTypeUid").entry().includeReference("brand") - * const res = await query.find() + * 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. @@ -165,8 +165,8 @@ export class Entries extends BaseQuery { * import contentstack from '@contentstack/delivery-sdk' * * const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" }); - * const query = stack.contentType("contentTypeUid").entry().includeReferenceContentTypeUID() - * const res = await query.find() + * const entries = stack.contentType("contentTypeUid").entry().includeReferenceContentTypeUID() + * const result = await entries.find() * * @returns {Entries} - Returns the Entries instance for chaining. */ @@ -184,8 +184,8 @@ export class Entries extends BaseQuery { * import contentstack from '@contentstack/delivery-sdk' * * const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" }); - * const query = stack.contentType("contentTypeUid").entry().includeSchema() - * const res = await query.find() + * const entries = stack.contentType("contentTypeUid").entry().includeSchema() + * const result = await entries.find() * * @returns {Entries} - Returns the Entries instance for chaining. */ @@ -248,7 +248,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("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); diff --git a/src/lib/entry.ts b/src/lib/entry.ts index d74fd79..c41435d 100644 --- a/src/lib/entry.ts +++ b/src/lib/entry.ts @@ -100,7 +100,7 @@ export class Entry { * import contentstack from '@contentstack/delivery-sdk' * * const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" }); - * const query = stack.contentType("contentTypeUid").entry(entry_uid).includeReference("brand").fetch() + * const result = await stack.contentType("contentTypeUid").entry(entry_uid).includeReference("brand").fetch() * * @param {string} referenceFieldUid - UID of the reference field to include. * @returns {Entry} - Returns the Entry instance for chaining. diff --git a/src/lib/query.ts b/src/lib/query.ts index e731ffd..eff5a1c 100644 --- a/src/lib/query.ts +++ b/src/lib/query.ts @@ -57,7 +57,7 @@ export class Query extends BaseQuery { * const query = stack.contentType("contentTypeUid").entry().query(); * const result = await query.where("field_UID", QueryOperation.IS_LESS_THAN, ["field1", "field2"]).find() * // OR - * const asset = await stack.asset().where("field_UID", QueryOperation.IS_LESS_THAN, ["field1", "field2"]).find() + * const asset = await stack.asset().query().where("field_UID", QueryOperation.IS_LESS_THAN, ["field1", "field2"]).find() * @example * import contentstack from '@contentstack/delivery-sdk' * @@ -128,7 +128,7 @@ export class Query extends BaseQuery { * const query = stack.contentType("contentTypeUid").entry().query(); * const subQuery = stack.contentType("referencedContentTypeUid").entry().query().where("title", QueryOperation.EQUALS, "value"); * query.whereIn("brand", subQuery) - * const res = await query.find() + * const result = await query.find() * * @param {string} referenceUid - UID of the reference field to query. * @param {Query} queryInstance - The Query instance to include in the where clause. @@ -156,7 +156,7 @@ export class Query extends BaseQuery { * const query = stack.contentType("contentTypeUid").entry().query(); * const subQuery = stack.contentType("referencedContentTypeUid").entry().query().where("title", QueryOperation.EQUALS, "value"); * query.whereNotIn("brand", subQuery) - * const res = await query.find() + * const result = await query.find() * * @param {string} referenceUid - UID of the reference field to query. * @param {Query} queryInstance - The Query instance to include in the where clause. @@ -184,7 +184,7 @@ export class Query extends BaseQuery { * const subQuery1 = stack.contentType("contentType2Uid").entry().query().where("price", QueryOperation.IS_LESS_THAN, 90); * const subQuery2 = stack.contentType("contentType3Uid").entry().query().where("discount", QueryOperation.INCLUDES, [20, 45]); * query.queryOperator(QueryOperator.AND, subQuery1, subQuery2) - * const res = await query.find() + * const result = await query.find() * * @param {QueryOperator} queryType - The type of query operator to apply. * @param {...Query[]} queryObjects - The Query instances to apply the query to. @@ -214,7 +214,7 @@ export class Query extends BaseQuery { * const assetQuery = stack.asset().query(); * const assetResult = assetQuery.getQuery() * - * @returns {Query} + * @returns {{ [key: string]: any }} The raw query object */ getQuery(): { [key: string]: any } { return this._parameters; @@ -333,7 +333,7 @@ export class Query extends BaseQuery { * const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" }); * const query1 = stack.contentType('contenttype_uid').entry().query().containedIn('fieldUID', ['value']); * const query2 = stack.contentType('contenttype_uid').entry().query().where('fieldUID', QueryOperation.EQUALS, 'value2'); - * const query = await stack.contentType('contenttype_uid').entry().query().or(query1, query2).find(); + * const result = await stack.contentType('contenttype_uid').entry().query().or(query1, query2).find(); * * @returns {Query} */ @@ -357,7 +357,7 @@ export class Query extends BaseQuery { * const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" }); * const query1 = stack.contentType('contenttype_uid').entry().query().containedIn('fieldUID', ['value']); * const query2 = stack.contentType('contenttype_uid').entry().query().where('fieldUID', QueryOperation.EQUALS, 'value2'); - * const query = await stack.contentType('contenttype_uid').entry().query().and(query1, query2).find(); + * const result = await stack.contentType('contenttype_uid').entry().query().and(query1, query2).find(); * * @returns {Query} */ @@ -380,7 +380,7 @@ export class Query extends BaseQuery { * import contentstack from '@contentstack/delivery-sdk' * * const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" }); - * const query = await stack.contentType('contenttype_uid').entry().query().equalTo('fieldUid', 'value').find(); + * const result = await stack.contentType('contenttype_uid').entry().query().equalTo('fieldUid', 'value').find(); * * @returns {Query} */ @@ -407,7 +407,7 @@ export class Query extends BaseQuery { * import contentstack from '@contentstack/delivery-sdk' * * const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" }); - * const query = await stack.contentType('contenttype_uid').entry().query().notEqualTo('fieldUid', 'value').find(); + * const result = await stack.contentType('contenttype_uid').entry().query().notEqualTo('fieldUid', 'value').find(); * * @returns {Query} */ @@ -434,8 +434,8 @@ export class Query extends BaseQuery { * import contentstack from '@contentstack/delivery-sdk' * * const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" }); - * const query = stack.contentType('contenttype_uid').entry().query().where('title', QueryOperation.EQUALS, 'value'); - * const entryQuery = await stack.contentType('contenttype_uid').entry().query().referenceIn('reference_uid', query).find(); + * const subQuery = stack.contentType('contenttype_uid').entry().query().where('title', QueryOperation.EQUALS, 'value'); + * const result = await stack.contentType('contenttype_uid').entry().query().referenceIn('reference_uid', subQuery).find(); * * @returns {Query} */ @@ -458,8 +458,8 @@ export class Query extends BaseQuery { * import contentstack from '@contentstack/delivery-sdk' * * const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" }); - * const query = stack.contentType('contenttype_uid').entry().query().where('title', QueryOperation.EQUALS, 'value'); - * const entryQuery = await stack.contentType('contenttype_uid').entry().query().referenceNotIn('reference_uid', query).find(); + * const subQuery = stack.contentType('contenttype_uid').entry().query().where('title', QueryOperation.EQUALS, 'value'); + * const result = await stack.contentType('contenttype_uid').entry().query().referenceNotIn('reference_uid', subQuery).find(); * * @returns {Query} */ @@ -481,8 +481,7 @@ export class Query extends BaseQuery { * import contentstack from '@contentstack/delivery-sdk' * * const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" }); - * const query = stack.contentType('contenttype_uid').entry().query().where('title', QueryOperation.EQUALS, 'value'); - * const entryQuery = await stack.contentType('contenttype_uid').entry().query().tags(['tag1']).find(); + * const result = await stack.contentType('contenttype_uid').entry().query().tags(['tag1']).find(); * * @returns {Query} */ @@ -504,8 +503,7 @@ export class Query extends BaseQuery { * import contentstack from '@contentstack/delivery-sdk' * * const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" }); - * const query = stack.contentType('contenttype_uid').entry().query().where('title', QueryOperation.EQUALS, 'value'); - * const entryQuery = await stack.contentType('contenttype_uid').entry().query().search('key').find(); + * const result = await stack.contentType('contenttype_uid').entry().query().search('key').find(); * * @returns {Query} */ @@ -528,8 +526,7 @@ export class Query extends BaseQuery { * import contentstack from '@contentstack/delivery-sdk' * * const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" }); - * const query = stack.contentType('contenttype_uid').entry().query().where('title', QueryOperation.EQUALS, 'value'); - * const entryQuery = await stack.contentType('contenttype_uid').entry().query().lessThan('fieldUid', 'value').find(); + * const result = await stack.contentType('contenttype_uid').entry().query().lessThan('fieldUid', 100).find(); * * @returns {Query} */ @@ -557,8 +554,7 @@ export class Query extends BaseQuery { * import contentstack from '@contentstack/delivery-sdk' * * const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" }); - * const query = stack.contentType('contenttype_uid').entry().query().where('title', QueryOperation.EQUALS, 'value'); - * const entryQuery = await stack.contentType('contenttype_uid').entry().query().lessThanOrEqualTo('fieldUid', 'value').find(); + * const result = await stack.contentType('contenttype_uid').entry().query().lessThanOrEqualTo('fieldUid', 100).find(); * * @returns {Query} */ @@ -585,8 +581,7 @@ export class Query extends BaseQuery { * import contentstack from '@contentstack/delivery-sdk' * * const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" }); - * const query = stack.contentType('contenttype_uid').entry().query().where('title', QueryOperation.EQUALS, 'value'); - * const entryQuery = await stack.contentType('contenttype_uid').entry().query().greaterThan('fieldUid', 'value').find(); + * const result = await stack.contentType('contenttype_uid').entry().query().greaterThan('fieldUid', 100).find(); * * @returns {Query} */ @@ -613,8 +608,7 @@ export class Query extends BaseQuery { * import contentstack from '@contentstack/delivery-sdk' * * const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" }); - * const query = stack.contentType('contenttype_uid').entry().query().where('title', QueryOperation.EQUALS, 'value'); - * const entryQuery = await stack.contentType('contenttype_uid').entry().query().greaterThanOrEqualTo('fieldUid', 'value').find(); + * const result = await stack.contentType('contenttype_uid').entry().query().greaterThanOrEqualTo('fieldUid', 100).find(); * * @returns {Query} */ diff --git a/src/lib/stack.ts b/src/lib/stack.ts index f36046f..781f40d 100644 --- a/src/lib/stack.ts +++ b/src/lib/stack.ts @@ -246,7 +246,7 @@ export class Stack { * @method setDebug * @memberof Stack * @description Sets the debug option - * @param {Number} debug - Debug value + * @param {boolean} debug - Debug value * @return {Stack} * @instance * */ @@ -257,7 +257,7 @@ export class Stack { /** * @method setHost - * @memberOf Stack + * @memberof Stack * @description Sets the host based on cloud region * @param {String} cloudRegion - Cloud region (e.g., 'aws_na', 'aws_eu') * @param {String} host - Optional custom host From 4309eb6d15dd521e61d63a17a4d27bb7f1b5bb3e Mon Sep 17 00:00:00 2001 From: reeshika-h Date: Thu, 4 Dec 2025 15:58:43 +0530 Subject: [PATCH 6/7] version bump --- CHANGELOG.md | 4 ++++ package-lock.json | 4 ++-- package.json | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6aa0f90..6a884b5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +### Version: 4.10.3 +#### Date: Dec-08-2025 +Feat: Improved error messages + ### Version: 4.10.2 #### Date: Nov-12-2025 Enhancement: Added logHandler interceptors for request and response logging diff --git a/package-lock.json b/package-lock.json index f4c9b83..65bec40 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@contentstack/delivery-sdk", - "version": "4.10.2", + "version": "4.10.3", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@contentstack/delivery-sdk", - "version": "4.10.2", + "version": "4.10.3", "license": "MIT", "dependencies": { "@contentstack/core": "^1.3.3", diff --git a/package.json b/package.json index 5c8cf1f..0f888e8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@contentstack/delivery-sdk", - "version": "4.10.2", + "version": "4.10.3", "type": "module", "license": "MIT", "main": "./dist/legacy/index.cjs", From fd9ccd573cbf937f479e343e4f8f56b2d47b8d84 Mon Sep 17 00:00:00 2001 From: "harshitha.d" Date: Thu, 4 Dec 2025 16:12:56 +0530 Subject: [PATCH 7/7] bump version to 4.10.4 and update changelog --- CHANGELOG.md | 6 +++++- package-lock.json | 4 ++-- package.json | 2 +- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6a884b5..9475911 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,11 @@ -### Version: 4.10.3 +### 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 diff --git a/package-lock.json b/package-lock.json index 65bec40..a1eb71c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@contentstack/delivery-sdk", - "version": "4.10.3", + "version": "4.10.4", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@contentstack/delivery-sdk", - "version": "4.10.3", + "version": "4.10.4", "license": "MIT", "dependencies": { "@contentstack/core": "^1.3.3", diff --git a/package.json b/package.json index 0f888e8..91410af 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@contentstack/delivery-sdk", - "version": "4.10.3", + "version": "4.10.4", "type": "module", "license": "MIT", "main": "./dist/legacy/index.cjs",