Skip to content

Commit c6b7c1e

Browse files
feat: Support new REST preview service
The REST preview service introduces its own preview token and API endpoint for Live preview. This values will be used to fetch entry data for live preview. Replaced api.contentstack.io to rest-preview.contentstack.com and replaced to fixes: https://contentstack.atlassian.net/browse/VC-311
1 parent 46b0e59 commit c6b7c1e

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const config = {
1313
},
1414
live_preview: {
1515
enable: false,
16-
host: 'api.contentstack.io'
16+
host: 'rest-preview.contentstack.com'
1717
}
1818
};
1919

index.d.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ export interface ContentTypeCollection {
7474

7575
export interface LivePreview {
7676
host: string
77-
management_token: string
77+
preview_token?: string
78+
management_token?: string
7879
enable: boolean
7980
}
8081

src/core/lib/utils.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ export function sendRequest(queryObject, options) {
242242
if(queryObject.requestParams.headers['access_token'])
243243
delete queryObject.requestParams.headers['access_token'];
244244

245-
queryObject.requestParams.headers['authorization'] = queryObject.live_preview.management_token
245+
queryObject.requestParams.headers['authorization'] = queryObject.live_preview.preview_token || queryObject.live_preview.management_token;
246246
} else if(queryObject.live_preview.live_preview) {
247247
cachePolicy = 1; // cache then network
248248
}
@@ -472,7 +472,8 @@ function generateReferenceMap (references) {
472472

473473
async function updateLivePreviewReferenceEntry(referenceMap, entry, stack, options, handlerOptions) {
474474
const {live_preview:livePreview, requestParams} = stack;
475-
const { content_type_uid: livePreviewContentTypeUid, management_token } = livePreview;
475+
const { content_type_uid: livePreviewContentTypeUid, preview_token } =
476+
livePreview;
476477

477478

478479
async function findReferenceAndFetchEntry(referenceMap, entry, setReference) {
@@ -509,7 +510,7 @@ async function updateLivePreviewReferenceEntry(referenceMap, entry, stack, optio
509510
stack.requestParams.method = "GET"
510511

511512
delete stack.requestParams.headers.access_token
512-
stack.requestParams.headers.authorization = management_token
513+
stack.requestParams.headers.authorization = preview_token;
513514

514515
const data = await Request(stack, options);
515516
data.entry._content_type_uid = livePreviewContentTypeUid;

0 commit comments

Comments
 (0)