diff --git a/.talismanrc b/.talismanrc index 9575fda..42ae5d0 100644 --- a/.talismanrc +++ b/.talismanrc @@ -1,6 +1,8 @@ fileignoreconfig: - filename: package-lock.json - checksum: 14aa4a8464718071ee723fc67f0f77748e41818f949a5b9b688da24cf1dd8bf0 + checksum: ffe61fb2806dc761b2f8e560b3d27aa58ae2fe2bdf5a48f68d80ee0fb74ffdb6 +- filename: src/lib/types.ts + checksum: 1eb6d6ec971934d65017dae2f82d6d6ef1cd0e6bfd50f43a9b46f30182307230 - filename: test/unit/image-transform.spec.ts checksum: 7beabdd07bd35d620668fcd97e1a303b9cbc40170bf3008a376d75ce0895de2a - filename: test/utils/mocks.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index f114973..6f97299 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +### Version: 4.6.1 +#### Date: March-24-2025 +Fix: Update imports and dependencies +Fix: Unit test cases + ### Version: 4.6.0 #### Date: March-10-2025 Enh: Added GCP-EU support diff --git a/package-lock.json b/package-lock.json index 421faa9..6586161 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,34 +1,34 @@ { "name": "@contentstack/delivery-sdk", - "version": "4.6.0", + "version": "4.6.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@contentstack/delivery-sdk", - "version": "4.6.0", + "version": "4.6.1", "license": "MIT", "dependencies": { "@contentstack/core": "^1.2.0", "@contentstack/utils": "^1.3.19", - "@types/humps": "^2.0.6", "axios": "^1.8.2", - "dotenv": "^16.4.7", - "humps": "^2.0.1", - "path-browserify": "^1.0.1" + "humps": "^2.0.1" }, "devDependencies": { "@nrwl/jest": "^17.3.2", + "@types/humps": "^2.0.6", "@types/jest": "^29.5.14", "@types/node-localstorage": "^1.3.3", "axios-mock-adapter": "^1.22.0", "babel-jest": "^29.7.0", + "dotenv": "^16.4.7", "esbuild-plugin-file-path-extensions": "^2.1.4", "ignore-loader": "^0.1.2", "jest": "^29.7.0", "jest-environment-jsdom": "^29.7.0", "jest-html-reporters": "^3.1.7", "jest-junit": "^16.0.0", + "path-browserify": "^1.0.1", "ts-jest": "^29.2.6", "ts-loader": "^9.5.2", "ts-node": "^10.9.2", @@ -1890,7 +1890,6 @@ "version": "1.2.0", "resolved": "https://registry.npmjs.org/@contentstack/core/-/core-1.2.0.tgz", "integrity": "sha512-+lvpw0QxJ6A77iqCQN8swo2IhtxaXx/Cwe2r/RE0TrFhWWdJyoIgdySA+LfYnqgxpOIv0B05ix98+xWbkNkwSQ==", - "license": "MIT", "dependencies": { "axios": "^1.7.9", "axios-mock-adapter": "^2.1.0", @@ -1915,8 +1914,7 @@ "node_modules/@contentstack/utils": { "version": "1.3.19", "resolved": "https://registry.npmjs.org/@contentstack/utils/-/utils-1.3.19.tgz", - "integrity": "sha512-8xZJXBvdYlmXr480Iu162TFwP1LrDMGy0YeEjFrOTIgWZnKDJPwyFGkqaIkTxCbcLw2yrMhsxyZEy4LFrvVFuQ==", - "license": "MIT" + "integrity": "sha512-8xZJXBvdYlmXr480Iu162TFwP1LrDMGy0YeEjFrOTIgWZnKDJPwyFGkqaIkTxCbcLw2yrMhsxyZEy4LFrvVFuQ==" }, "node_modules/@cspotcode/source-map-support": { "version": "0.8.1", @@ -4060,7 +4058,7 @@ "version": "2.0.6", "resolved": "https://registry.npmjs.org/@types/humps/-/humps-2.0.6.tgz", "integrity": "sha512-Fagm1/a/1J9gDKzGdtlPmmTN5eSw/aaTzHtj740oSfo+MODsSY2WglxMmhTdOglC8nxqUhGGQ+5HfVtBvxo3Kg==", - "license": "MIT" + "dev": true }, "node_modules/@types/istanbul-lib-coverage": { "version": "2.0.6", @@ -5645,7 +5643,7 @@ "version": "16.4.7", "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.4.7.tgz", "integrity": "sha512-47qPchRCykZC03FhkYAhrvwU4xDBFIj1QPqaarj6mdM/hgUzfPHcpkHJOn3mJAufFeeAxAzeGsr5X0M4k6fLZQ==", - "license": "BSD-2-Clause", + "dev": true, "engines": { "node": ">=12" }, @@ -8812,7 +8810,7 @@ "version": "1.0.1", "resolved": "https://registry.npmjs.org/path-browserify/-/path-browserify-1.0.1.tgz", "integrity": "sha512-b7uo2UCUOYZcnF/3ID0lulOJi/bafxa1xPe7ZPsammBSpjSWQkjNxlt635YGS2MiR9GjvuXCtz2emr3jbsz98g==", - "license": "MIT" + "dev": true }, "node_modules/path-exists": { "version": "4.0.0", diff --git a/package.json b/package.json index 946352e..f232339 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@contentstack/delivery-sdk", - "version": "4.6.0", + "version": "4.6.1", "type": "module", "license": "MIT", "main": "./dist/legacy/index.cjs", @@ -35,11 +35,8 @@ "dependencies": { "@contentstack/core": "^1.2.0", "@contentstack/utils": "^1.3.19", - "@types/humps": "^2.0.6", "axios": "^1.8.2", - "dotenv": "^16.4.7", - "humps": "^2.0.1", - "path-browserify": "^1.0.1" + "humps": "^2.0.1" }, "files": [ "dist", @@ -48,16 +45,19 @@ ], "devDependencies": { "@nrwl/jest": "^17.3.2", + "@types/humps": "^2.0.6", "@types/jest": "^29.5.14", "@types/node-localstorage": "^1.3.3", "axios-mock-adapter": "^1.22.0", "babel-jest": "^29.7.0", + "dotenv": "^16.4.7", "esbuild-plugin-file-path-extensions": "^2.1.4", "ignore-loader": "^0.1.2", "jest": "^29.7.0", "jest-environment-jsdom": "^29.7.0", "jest-html-reporters": "^3.1.7", "jest-junit": "^16.0.0", + "path-browserify": "^1.0.1", "ts-jest": "^29.2.6", "ts-loader": "^9.5.2", "ts-node": "^10.9.2", diff --git a/src/lib/base-query.ts b/src/lib/base-query.ts index cb99594..3f214f6 100644 --- a/src/lib/base-query.ts +++ b/src/lib/base-query.ts @@ -1,7 +1,6 @@ import { AxiosInstance, getData } from '@contentstack/core'; import { Pagination } from './pagination'; -import { FindResponse } from './types'; -import { params } from './internal-types'; +import { FindResponse, params } from './types'; export class BaseQuery extends Pagination { _parameters: params = {}; // Params of query class ?query={} diff --git a/src/lib/internal-types.ts b/src/lib/internal-types.ts deleted file mode 100644 index 5c998d8..0000000 --- a/src/lib/internal-types.ts +++ /dev/null @@ -1,7 +0,0 @@ -export type params = { - [key: string]: any -} - -export type queryParams = { - [key: string]: string | boolean | number | string[] -} diff --git a/src/lib/pagination.ts b/src/lib/pagination.ts index c5c5d5d..0a4748a 100644 --- a/src/lib/pagination.ts +++ b/src/lib/pagination.ts @@ -1,5 +1,4 @@ -import { PaginationObj } from './types'; -import { queryParams } from './internal-types'; +import { PaginationObj, queryParams } from './types'; export class Pagination { _queryParams: queryParams = {}; diff --git a/src/lib/query.ts b/src/lib/query.ts index d2f519e..fb1cee6 100644 --- a/src/lib/query.ts +++ b/src/lib/query.ts @@ -1,7 +1,6 @@ import { AxiosInstance } from '@contentstack/core'; import { BaseQuery } from './base-query'; -import { BaseQueryParameters, QueryOperation, QueryOperator, TaxonomyQueryOperation } from './types'; -import { params, queryParams } from './internal-types'; +import { BaseQueryParameters, QueryOperation, QueryOperator, TaxonomyQueryOperation, params, queryParams } from './types'; export class Query extends BaseQuery { private _contentTypeUid?: string; diff --git a/src/lib/synchronization.ts b/src/lib/synchronization.ts index c597c72..27abf41 100644 --- a/src/lib/synchronization.ts +++ b/src/lib/synchronization.ts @@ -5,6 +5,8 @@ import humps from 'humps'; export async function synchronization(client: AxiosInstance, params: SyncStack | SyncType = {}, recursive = false) { const config: AxiosRequestConfig = { params }; + const SYNC_URL = '/stacks/sync'; + if (!('paginationToken' in params || 'syncToken' in params)) { // for every config except sync and pagination token config.params = { ...params, init: true }; @@ -15,13 +17,13 @@ export async function synchronization(client: AxiosInstance, params: SyncStack | config.params = { ...config.params, type: type.join(',') }; } - let response: AxiosResponse = await getData(client, '/sync', { params: humps.decamelizeKeys(config) }); + let response: AxiosResponse = await getData(client, SYNC_URL, { params: humps.decamelizeKeys(config.params) }); const data = response.data; while (recursive && 'pagination_token' in response.data) { const recResponse: AxiosResponse = await getData( client, - '/sync', + SYNC_URL, humps.decamelizeKeys({ paginationToken: data.pagination_token }) ); recResponse.data.items = { ...response.data.items, ...recResponse.data.items }; diff --git a/src/lib/types.ts b/src/lib/types.ts index 3988f20..78769bd 100644 --- a/src/lib/types.ts +++ b/src/lib/types.ts @@ -2,6 +2,16 @@ import { HttpClientParams } from '@contentstack/core'; import { PersistanceStoreOptions, StorageType } from '../persistance'; +// Internal Types +export type params = { + [key: string]: any +} + +export type queryParams = { + [key: string]: string | boolean | number | string[] +} + +// External Types export enum Region { US = 'us', EU = 'eu', diff --git a/test/unit/synchronization.spec.ts b/test/unit/synchronization.spec.ts index 780ef19..fa21fc2 100644 --- a/test/unit/synchronization.spec.ts +++ b/test/unit/synchronization.spec.ts @@ -9,6 +9,7 @@ jest.mock('@contentstack/core'); const getDataMock = >(core.getData); describe('Synchronization function', () => { + const SYNC_URL = '/stacks/sync'; beforeEach(() => { getDataMock.mockImplementation((_client, _url, params) => { const resp: any = axiosGetMock; @@ -28,63 +29,63 @@ describe('Synchronization function', () => { }; it('should have valid init and environment params as req params when no request params is passed', async () => { await await synchronization(httpClient({})); - expect(getDataMock.mock.calls[0][1]).toBe('/sync'); - expect(getDataMock.mock.calls[0][2].params.params).toHaveProperty('init'); - expect(getDataMock.mock.calls[0][2].params.params).toEqual({ init: true }); + expect(getDataMock.mock.calls[0][1]).toBe(SYNC_URL); + expect(getDataMock.mock.calls[0][2].params).toHaveProperty('init'); + expect(getDataMock.mock.calls[0][2].params).toEqual({ init: true }); }); it('should have only pagination_token param when sync is called with pagination_token.', async () => { await syncCall({ paginationToken: '' }); - expect(getDataMock.mock.calls[0][1]).toBe('/sync'); + expect(getDataMock.mock.calls[0][1]).toBe(SYNC_URL); expect(getDataMock.mock.calls[0][2].params).not.toHaveProperty('init'); expect(getDataMock.mock.calls[0][2].params).not.toHaveProperty('environment'); - expect(getDataMock.mock.calls[0][2].params.params).toHaveProperty('pagination_token'); - expect(getDataMock.mock.calls[0][2].params.params).toEqual({ pagination_token: '' }); + expect(getDataMock.mock.calls[0][2].params).toHaveProperty('pagination_token'); + expect(getDataMock.mock.calls[0][2].params).toEqual({ pagination_token: '' }); }); it('should have only sync_token param when sync is called with sync_token.', async () => { await syncCall({ syncToken: '' }); - expect(getDataMock.mock.calls[0][1]).toBe('/sync'); + expect(getDataMock.mock.calls[0][1]).toBe(SYNC_URL); expect(getDataMock.mock.calls[0][2].params).not.toHaveProperty('init'); expect(getDataMock.mock.calls[0][2].params).not.toHaveProperty('environment'); - expect(getDataMock.mock.calls[0][2].params.params).toHaveProperty('sync_token'); - expect(getDataMock.mock.calls[0][2].params.params).toEqual({ sync_token: '' }); + expect(getDataMock.mock.calls[0][2].params).toHaveProperty('sync_token'); + expect(getDataMock.mock.calls[0][2].params).toEqual({ sync_token: '' }); }); it('should have valid content_type_uid when content_type_uid is passed as param', async () => { await syncCall({ contentTypeUid: 'session' }); - expect(getDataMock.mock.calls[0][1]).toBe('/sync'); - expect(getDataMock.mock.calls[0][2].params.params).toHaveProperty('init'); - expect(getDataMock.mock.calls[0][2].params.params).toHaveProperty('content_type_uid'); - expect(getDataMock.mock.calls[0][2].params.params).toEqual({ + expect(getDataMock.mock.calls[0][1]).toBe(SYNC_URL); + expect(getDataMock.mock.calls[0][2].params).toHaveProperty('init'); + expect(getDataMock.mock.calls[0][2].params).toHaveProperty('content_type_uid'); + expect(getDataMock.mock.calls[0][2].params).toEqual({ init: true, content_type_uid: 'session', }); }); it('should have valid locale when a locale is passed as param', async () => { await syncCall({ locale: LOCALE }); - expect(getDataMock.mock.calls[0][1]).toBe('/sync'); - expect(getDataMock.mock.calls[0][2].params.params).toHaveProperty('init'); - expect(getDataMock.mock.calls[0][2].params.params).toHaveProperty('locale'); - expect(getDataMock.mock.calls[0][2].params.params).toEqual({ + expect(getDataMock.mock.calls[0][1]).toBe(SYNC_URL); + expect(getDataMock.mock.calls[0][2].params).toHaveProperty('init'); + expect(getDataMock.mock.calls[0][2].params).toHaveProperty('locale'); + expect(getDataMock.mock.calls[0][2].params).toEqual({ init: true, locale: LOCALE, }); }); it('should have valid date structure and other required params when start_date is passed as param', async () => { await syncCall({ startDate: '2018-10-22' }); - expect(getDataMock.mock.calls[0][1]).toBe('/sync'); - expect(getDataMock.mock.calls[0][2].params.params).toHaveProperty('init'); - expect(getDataMock.mock.calls[0][2].params.params).toHaveProperty('start_date'); - expect(getDataMock.mock.calls[0][2].params.params).toEqual({ + expect(getDataMock.mock.calls[0][1]).toBe(SYNC_URL); + expect(getDataMock.mock.calls[0][2].params).toHaveProperty('init'); + expect(getDataMock.mock.calls[0][2].params).toHaveProperty('start_date'); + expect(getDataMock.mock.calls[0][2].params).toEqual({ init: true, start_date: '2018-10-22', }); }); it('should have valid publish_type when type is passed as param', async () => { await syncCall({ type: [PublishType.ENTRY_PUBLISHED] }); - expect(getDataMock.mock.calls[0][1]).toBe('/sync'); - expect(getDataMock.mock.calls[0][2].params.params).toHaveProperty('init'); - expect(getDataMock.mock.calls[0][2].params.params).toHaveProperty('type'); - expect(getDataMock.mock.calls[0][2].params.params).toEqual({ + expect(getDataMock.mock.calls[0][1]).toBe(SYNC_URL); + expect(getDataMock.mock.calls[0][2].params).toHaveProperty('init'); + expect(getDataMock.mock.calls[0][2].params).toHaveProperty('type'); + expect(getDataMock.mock.calls[0][2].params).toEqual({ init: true, type: 'entry_published', }); @@ -95,10 +96,10 @@ describe('Synchronization function', () => { startDate: '2018-10-22', type: [PublishType.ENTRY_PUBLISHED, PublishType.CONTENT_TYPE_DELETED], }); - expect(getDataMock.mock.calls[0][1]).toBe('/sync'); - expect(getDataMock.mock.calls[0][2].params.params).toHaveProperty('init'); - expect(getDataMock.mock.calls[0][2].params.params).toHaveProperty('type'); - expect(getDataMock.mock.calls[0][2].params.params).toEqual({ + expect(getDataMock.mock.calls[0][1]).toBe(SYNC_URL); + expect(getDataMock.mock.calls[0][2].params).toHaveProperty('init'); + expect(getDataMock.mock.calls[0][2].params).toHaveProperty('type'); + expect(getDataMock.mock.calls[0][2].params).toEqual({ init: true, start_date: '2018-10-22', locale: 'en-us',