Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DX | 24-03-2025 | Release #153

Merged
merged 10 commits into from
Mar 20, 2025
4 changes: 3 additions & 1 deletion .talismanrc
Original file line number Diff line number Diff line change
@@ -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
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
22 changes: 10 additions & 12 deletions package-lock.json

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

10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand Down
3 changes: 1 addition & 2 deletions src/lib/base-query.ts
Original file line number Diff line number Diff line change
@@ -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={}
Expand Down
7 changes: 0 additions & 7 deletions src/lib/internal-types.ts

This file was deleted.

3 changes: 1 addition & 2 deletions src/lib/pagination.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { PaginationObj } from './types';
import { queryParams } from './internal-types';
import { PaginationObj, queryParams } from './types';

export class Pagination {
_queryParams: queryParams = {};
Expand Down
3 changes: 1 addition & 2 deletions src/lib/query.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
6 changes: 4 additions & 2 deletions src/lib/synchronization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand All @@ -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 };
Expand Down
10 changes: 10 additions & 0 deletions src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
59 changes: 30 additions & 29 deletions test/unit/synchronization.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ jest.mock('@contentstack/core');
const getDataMock = <jest.Mock<typeof core.getData>>(<unknown>core.getData);

describe('Synchronization function', () => {
const SYNC_URL = '/stacks/sync';
beforeEach(() => {
getDataMock.mockImplementation((_client, _url, params) => {
const resp: any = axiosGetMock;
Expand All @@ -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: '<page_tkn>' });
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: '<page_tkn>' });
expect(getDataMock.mock.calls[0][2].params).toHaveProperty('pagination_token');
expect(getDataMock.mock.calls[0][2].params).toEqual({ pagination_token: '<page_tkn>' });
});
it('should have only sync_token param when sync is called with sync_token.', async () => {
await syncCall({ syncToken: '<sync_tkn>' });
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: '<sync_tkn>' });
expect(getDataMock.mock.calls[0][2].params).toHaveProperty('sync_token');
expect(getDataMock.mock.calls[0][2].params).toEqual({ sync_token: '<sync_tkn>' });
});
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',
});
Expand All @@ -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',
Expand Down