Skip to content

Commit 9cc5fea

Browse files
Merge pull request #324 from contentstack/development
fix: resolve Sync API non-Axios response issue
2 parents 358d8db + 1cf341e commit 9cc5fea

7 files changed

Lines changed: 159 additions & 120 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
#### Date: Feb-16-2026
33
Breaking: Cache persistence is now a separate plugin. When using a cache policy other than `IGNORE_CACHE`, you must pass `cacheOptions.persistenceStore`. Install `@contentstack/persistence-plugin` and use `new PersistenceStore({ ... })` as the store. The SDK no longer bundles persistence code or accepts `storeType` in `cacheOptions`.
44
Enhancement: SDK defines only the `PersistenceStore` interface (getItem/setItem); full implementation lives in the plugin for a lighter core package.
5+
Fix: Sync API returns non-Axios response causing undefined data and recursive sync failure
6+
7+
### Version: 4.11.2
8+
#### Date: feb-11-2026
9+
Fix: JS core & axios version bump
510

611

712
### Version: 4.11.2

src/common/types.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,22 @@ export interface SyncType {
127127
locale?: string;
128128
startDate?: string;
129129
}
130+
131+
export interface SyncItem {
132+
type: string;
133+
event_at: string;
134+
content_type_uid: string;
135+
data: any;
136+
}
137+
138+
export interface SyncResponse {
139+
items: SyncItem[];
140+
skip?: number;
141+
limit?: number;
142+
total_count?: number;
143+
sync_token?: string;
144+
pagination_token?: string;
145+
}
130146
export type TransformData = { [key: string]: string | string[] };
131147

132148
export enum Format {

src/sync/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
export { synchronization } from './synchronization';
2+
export type { SyncResponse, SyncItem } from '../common/types';

src/sync/synchronization.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { AxiosInstance, getData } from '@contentstack/core';
2-
import { SyncStack, SyncType, PublishType } from '../common/types';
3-
import { AxiosRequestConfig, AxiosResponse } from 'axios';
2+
import { SyncStack, SyncType, PublishType, SyncResponse } from '../common/types';
3+
import { AxiosRequestConfig } from 'axios';
44
import humps from 'humps';
55

6-
export async function synchronization(client: AxiosInstance, params: SyncStack | SyncType = {}, recursive = false) {
6+
export async function synchronization(client: AxiosInstance, params: SyncStack | SyncType = {}, recursive = false): Promise<SyncResponse> {
77
const config: AxiosRequestConfig = { params };
88
const SYNC_URL = '/stacks/sync';
99

@@ -17,18 +17,19 @@ export async function synchronization(client: AxiosInstance, params: SyncStack |
1717
config.params = { ...config.params, type: type.join(',') };
1818
}
1919

20-
let response: AxiosResponse = await getData(client, SYNC_URL, { params: humps.decamelizeKeys(config.params) });
21-
const data = response.data;
20+
// getData returns response.data directly, not the full AxiosResponse
21+
let response: SyncResponse = await getData(client, SYNC_URL, { params: humps.decamelizeKeys(config.params) });
2222

23-
while (recursive && 'pagination_token' in response.data) {
24-
const recResponse: AxiosResponse = await getData(
23+
while (recursive && 'pagination_token' in response) {
24+
const recResponse: SyncResponse = await getData(
2525
client,
2626
SYNC_URL,
27-
humps.decamelizeKeys({ paginationToken: data.pagination_token })
27+
{ params: humps.decamelizeKeys({ paginationToken: response.pagination_token }) }
2828
);
29-
recResponse.data.items = { ...response.data.items, ...recResponse.data.items };
30-
response = { ...recResponse };
29+
// Merge items from all paginated responses
30+
recResponse.items = [...response.items, ...recResponse.items];
31+
response = recResponse;
3132
}
3233

33-
return response.data;
34+
return response;
3435
}

0 commit comments

Comments
 (0)