Skip to content

Commit cdedf94

Browse files
feat: added live preview query function to stack
1 parent 35f368e commit cdedf94

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/lib/contentstack.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export function Stack(config: StackConfig): StackClass {
4040

4141
if (config.live_preview?.enable === true) {
4242
if (config.live_preview?.management_token != null && config.live_preview?.preview_token == null) {
43-
config.host = 'api.contentstack.com'
43+
config.host = 'api.contentstack.io'
4444
config.live_preview.host = config.host
4545
} else if (config.live_preview?.preview_token != null && config.live_preview?.management_token == null) {
4646
config.host = 'rest-preview.contentstack.com'

src/lib/stack.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { StackConfig, SyncStack, SyncType } from './types';
1+
import { StackConfig, SyncStack, SyncType, LivePreviewQuery } from './types';
22
import { AxiosInstance } from '@contentstack/core';
33
import { Asset } from './asset';
44
import { AssetQuery } from './asset-query';
@@ -15,6 +15,7 @@ export class Stack {
1515
constructor(client: AxiosInstance, config: StackConfig) {
1616
this._client = client;
1717
this.config = config;
18+
this.config.live_preview = config.live_preview
1819
}
1920

2021
/**
@@ -141,4 +142,12 @@ export class Stack {
141142
async sync(params: SyncType | SyncStack = {}, recursive = false) {
142143
return await synchronization(this._client, params, recursive);
143144
}
145+
146+
livePreviewQuery(query: LivePreviewQuery) {
147+
if (this.config.live_preview) {
148+
this.config.live_preview.live_preview = query.live_preview || 'init';
149+
this.config.live_preview.contentTypeUid = query.contentTypeUid;
150+
this.config.live_preview.entryUid = query.entryUid
151+
}
152+
}
144153
}

0 commit comments

Comments
 (0)