Skip to content

Commit 366ce00

Browse files
authored
Merge pull request #153 from contentstack/development
DX | 24-03-2025 | Release
2 parents 130d53f + 7d5913d commit 366ce00

11 files changed

+70
-62
lines changed

.talismanrc

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
fileignoreconfig:
22
- filename: package-lock.json
3-
checksum: 14aa4a8464718071ee723fc67f0f77748e41818f949a5b9b688da24cf1dd8bf0
3+
checksum: ffe61fb2806dc761b2f8e560b3d27aa58ae2fe2bdf5a48f68d80ee0fb74ffdb6
4+
- filename: src/lib/types.ts
5+
checksum: 1eb6d6ec971934d65017dae2f82d6d6ef1cd0e6bfd50f43a9b46f30182307230
46
- filename: test/unit/image-transform.spec.ts
57
checksum: 7beabdd07bd35d620668fcd97e1a303b9cbc40170bf3008a376d75ce0895de2a
68
- filename: test/utils/mocks.ts

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
### Version: 4.6.1
2+
#### Date: March-24-2025
3+
Fix: Update imports and dependencies
4+
Fix: Unit test cases
5+
16
### Version: 4.6.0
27
#### Date: March-10-2025
38
Enh: Added GCP-EU support

package-lock.json

+10-12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@contentstack/delivery-sdk",
3-
"version": "4.6.0",
3+
"version": "4.6.1",
44
"type": "module",
55
"license": "MIT",
66
"main": "./dist/legacy/index.cjs",
@@ -35,11 +35,8 @@
3535
"dependencies": {
3636
"@contentstack/core": "^1.2.0",
3737
"@contentstack/utils": "^1.3.19",
38-
"@types/humps": "^2.0.6",
3938
"axios": "^1.8.2",
40-
"dotenv": "^16.4.7",
41-
"humps": "^2.0.1",
42-
"path-browserify": "^1.0.1"
39+
"humps": "^2.0.1"
4340
},
4441
"files": [
4542
"dist",
@@ -48,16 +45,19 @@
4845
],
4946
"devDependencies": {
5047
"@nrwl/jest": "^17.3.2",
48+
"@types/humps": "^2.0.6",
5149
"@types/jest": "^29.5.14",
5250
"@types/node-localstorage": "^1.3.3",
5351
"axios-mock-adapter": "^1.22.0",
5452
"babel-jest": "^29.7.0",
53+
"dotenv": "^16.4.7",
5554
"esbuild-plugin-file-path-extensions": "^2.1.4",
5655
"ignore-loader": "^0.1.2",
5756
"jest": "^29.7.0",
5857
"jest-environment-jsdom": "^29.7.0",
5958
"jest-html-reporters": "^3.1.7",
6059
"jest-junit": "^16.0.0",
60+
"path-browserify": "^1.0.1",
6161
"ts-jest": "^29.2.6",
6262
"ts-loader": "^9.5.2",
6363
"ts-node": "^10.9.2",

src/lib/base-query.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { AxiosInstance, getData } from '@contentstack/core';
22
import { Pagination } from './pagination';
3-
import { FindResponse } from './types';
4-
import { params } from './internal-types';
3+
import { FindResponse, params } from './types';
54

65
export class BaseQuery extends Pagination {
76
_parameters: params = {}; // Params of query class ?query={}

src/lib/internal-types.ts

-7
This file was deleted.

src/lib/pagination.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { PaginationObj } from './types';
2-
import { queryParams } from './internal-types';
1+
import { PaginationObj, queryParams } from './types';
32

43
export class Pagination {
54
_queryParams: queryParams = {};

src/lib/query.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { AxiosInstance } from '@contentstack/core';
22
import { BaseQuery } from './base-query';
3-
import { BaseQueryParameters, QueryOperation, QueryOperator, TaxonomyQueryOperation } from './types';
4-
import { params, queryParams } from './internal-types';
3+
import { BaseQueryParameters, QueryOperation, QueryOperator, TaxonomyQueryOperation, params, queryParams } from './types';
54

65
export class Query extends BaseQuery {
76
private _contentTypeUid?: string;

src/lib/synchronization.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import humps from 'humps';
55

66
export async function synchronization(client: AxiosInstance, params: SyncStack | SyncType = {}, recursive = false) {
77
const config: AxiosRequestConfig = { params };
8+
const SYNC_URL = '/stacks/sync';
9+
810
if (!('paginationToken' in params || 'syncToken' in params)) {
911
// for every config except sync and pagination token
1012
config.params = { ...params, init: true };
@@ -15,13 +17,13 @@ export async function synchronization(client: AxiosInstance, params: SyncStack |
1517
config.params = { ...config.params, type: type.join(',') };
1618
}
1719

18-
let response: AxiosResponse = await getData(client, '/sync', { params: humps.decamelizeKeys(config) });
20+
let response: AxiosResponse = await getData(client, SYNC_URL, { params: humps.decamelizeKeys(config.params) });
1921
const data = response.data;
2022

2123
while (recursive && 'pagination_token' in response.data) {
2224
const recResponse: AxiosResponse = await getData(
2325
client,
24-
'/sync',
26+
SYNC_URL,
2527
humps.decamelizeKeys({ paginationToken: data.pagination_token })
2628
);
2729
recResponse.data.items = { ...response.data.items, ...recResponse.data.items };

src/lib/types.ts

+10
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@
22
import { HttpClientParams } from '@contentstack/core';
33
import { PersistanceStoreOptions, StorageType } from '../persistance';
44

5+
// Internal Types
6+
export type params = {
7+
[key: string]: any
8+
}
9+
10+
export type queryParams = {
11+
[key: string]: string | boolean | number | string[]
12+
}
13+
14+
// External Types
515
export enum Region {
616
US = 'us',
717
EU = 'eu',

test/unit/synchronization.spec.ts

+30-29
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ jest.mock('@contentstack/core');
99
const getDataMock = <jest.Mock<typeof core.getData>>(<unknown>core.getData);
1010

1111
describe('Synchronization function', () => {
12+
const SYNC_URL = '/stacks/sync';
1213
beforeEach(() => {
1314
getDataMock.mockImplementation((_client, _url, params) => {
1415
const resp: any = axiosGetMock;
@@ -28,63 +29,63 @@ describe('Synchronization function', () => {
2829
};
2930
it('should have valid init and environment params as req params when no request params is passed', async () => {
3031
await await synchronization(httpClient({}));
31-
expect(getDataMock.mock.calls[0][1]).toBe('/sync');
32-
expect(getDataMock.mock.calls[0][2].params.params).toHaveProperty('init');
33-
expect(getDataMock.mock.calls[0][2].params.params).toEqual({ init: true });
32+
expect(getDataMock.mock.calls[0][1]).toBe(SYNC_URL);
33+
expect(getDataMock.mock.calls[0][2].params).toHaveProperty('init');
34+
expect(getDataMock.mock.calls[0][2].params).toEqual({ init: true });
3435
});
3536

3637
it('should have only pagination_token param when sync is called with pagination_token.', async () => {
3738
await syncCall({ paginationToken: '<page_tkn>' });
38-
expect(getDataMock.mock.calls[0][1]).toBe('/sync');
39+
expect(getDataMock.mock.calls[0][1]).toBe(SYNC_URL);
3940
expect(getDataMock.mock.calls[0][2].params).not.toHaveProperty('init');
4041
expect(getDataMock.mock.calls[0][2].params).not.toHaveProperty('environment');
41-
expect(getDataMock.mock.calls[0][2].params.params).toHaveProperty('pagination_token');
42-
expect(getDataMock.mock.calls[0][2].params.params).toEqual({ pagination_token: '<page_tkn>' });
42+
expect(getDataMock.mock.calls[0][2].params).toHaveProperty('pagination_token');
43+
expect(getDataMock.mock.calls[0][2].params).toEqual({ pagination_token: '<page_tkn>' });
4344
});
4445
it('should have only sync_token param when sync is called with sync_token.', async () => {
4546
await syncCall({ syncToken: '<sync_tkn>' });
46-
expect(getDataMock.mock.calls[0][1]).toBe('/sync');
47+
expect(getDataMock.mock.calls[0][1]).toBe(SYNC_URL);
4748
expect(getDataMock.mock.calls[0][2].params).not.toHaveProperty('init');
4849
expect(getDataMock.mock.calls[0][2].params).not.toHaveProperty('environment');
49-
expect(getDataMock.mock.calls[0][2].params.params).toHaveProperty('sync_token');
50-
expect(getDataMock.mock.calls[0][2].params.params).toEqual({ sync_token: '<sync_tkn>' });
50+
expect(getDataMock.mock.calls[0][2].params).toHaveProperty('sync_token');
51+
expect(getDataMock.mock.calls[0][2].params).toEqual({ sync_token: '<sync_tkn>' });
5152
});
5253
it('should have valid content_type_uid when content_type_uid is passed as param', async () => {
5354
await syncCall({ contentTypeUid: 'session' });
54-
expect(getDataMock.mock.calls[0][1]).toBe('/sync');
55-
expect(getDataMock.mock.calls[0][2].params.params).toHaveProperty('init');
56-
expect(getDataMock.mock.calls[0][2].params.params).toHaveProperty('content_type_uid');
57-
expect(getDataMock.mock.calls[0][2].params.params).toEqual({
55+
expect(getDataMock.mock.calls[0][1]).toBe(SYNC_URL);
56+
expect(getDataMock.mock.calls[0][2].params).toHaveProperty('init');
57+
expect(getDataMock.mock.calls[0][2].params).toHaveProperty('content_type_uid');
58+
expect(getDataMock.mock.calls[0][2].params).toEqual({
5859
init: true,
5960
content_type_uid: 'session',
6061
});
6162
});
6263
it('should have valid locale when a locale is passed as param', async () => {
6364
await syncCall({ locale: LOCALE });
64-
expect(getDataMock.mock.calls[0][1]).toBe('/sync');
65-
expect(getDataMock.mock.calls[0][2].params.params).toHaveProperty('init');
66-
expect(getDataMock.mock.calls[0][2].params.params).toHaveProperty('locale');
67-
expect(getDataMock.mock.calls[0][2].params.params).toEqual({
65+
expect(getDataMock.mock.calls[0][1]).toBe(SYNC_URL);
66+
expect(getDataMock.mock.calls[0][2].params).toHaveProperty('init');
67+
expect(getDataMock.mock.calls[0][2].params).toHaveProperty('locale');
68+
expect(getDataMock.mock.calls[0][2].params).toEqual({
6869
init: true,
6970
locale: LOCALE,
7071
});
7172
});
7273
it('should have valid date structure and other required params when start_date is passed as param', async () => {
7374
await syncCall({ startDate: '2018-10-22' });
74-
expect(getDataMock.mock.calls[0][1]).toBe('/sync');
75-
expect(getDataMock.mock.calls[0][2].params.params).toHaveProperty('init');
76-
expect(getDataMock.mock.calls[0][2].params.params).toHaveProperty('start_date');
77-
expect(getDataMock.mock.calls[0][2].params.params).toEqual({
75+
expect(getDataMock.mock.calls[0][1]).toBe(SYNC_URL);
76+
expect(getDataMock.mock.calls[0][2].params).toHaveProperty('init');
77+
expect(getDataMock.mock.calls[0][2].params).toHaveProperty('start_date');
78+
expect(getDataMock.mock.calls[0][2].params).toEqual({
7879
init: true,
7980
start_date: '2018-10-22',
8081
});
8182
});
8283
it('should have valid publish_type when type is passed as param', async () => {
8384
await syncCall({ type: [PublishType.ENTRY_PUBLISHED] });
84-
expect(getDataMock.mock.calls[0][1]).toBe('/sync');
85-
expect(getDataMock.mock.calls[0][2].params.params).toHaveProperty('init');
86-
expect(getDataMock.mock.calls[0][2].params.params).toHaveProperty('type');
87-
expect(getDataMock.mock.calls[0][2].params.params).toEqual({
85+
expect(getDataMock.mock.calls[0][1]).toBe(SYNC_URL);
86+
expect(getDataMock.mock.calls[0][2].params).toHaveProperty('init');
87+
expect(getDataMock.mock.calls[0][2].params).toHaveProperty('type');
88+
expect(getDataMock.mock.calls[0][2].params).toEqual({
8889
init: true,
8990
type: 'entry_published',
9091
});
@@ -95,10 +96,10 @@ describe('Synchronization function', () => {
9596
startDate: '2018-10-22',
9697
type: [PublishType.ENTRY_PUBLISHED, PublishType.CONTENT_TYPE_DELETED],
9798
});
98-
expect(getDataMock.mock.calls[0][1]).toBe('/sync');
99-
expect(getDataMock.mock.calls[0][2].params.params).toHaveProperty('init');
100-
expect(getDataMock.mock.calls[0][2].params.params).toHaveProperty('type');
101-
expect(getDataMock.mock.calls[0][2].params.params).toEqual({
99+
expect(getDataMock.mock.calls[0][1]).toBe(SYNC_URL);
100+
expect(getDataMock.mock.calls[0][2].params).toHaveProperty('init');
101+
expect(getDataMock.mock.calls[0][2].params).toHaveProperty('type');
102+
expect(getDataMock.mock.calls[0][2].params).toEqual({
102103
init: true,
103104
start_date: '2018-10-22',
104105
locale: 'en-us',

0 commit comments

Comments
 (0)