Skip to content

Next #48

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

Merged
merged 6 commits into from
Aug 8, 2024
Merged

Next #48

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .talismanrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
fileignoreconfig:
- filename: package-lock.json
checksum: 31acb062f1514b4e9fb8604aca11b3db3da754befe51c969c788c460ed8c390f
checksum: ebafc1a55b01b2259dacb35e2c286ad88c811974c6955d379be3205abbf1c7ff
version: ""
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
## Change log

### Version: 1.1.0
#### Date: Aug-07-2024
- Live Preview configuration changes

### Version: 1.0.3
#### Date: July-08-2024
Expand Down
28 changes: 14 additions & 14 deletions package-lock.json

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

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@contentstack/core",
"version": "1.0.3",
"version": "1.1.0",
"type": "commonjs",
"main": "./dist/cjs/src/index.js",
"types": "./dist/cjs/src/index.d.ts",
Expand All @@ -18,11 +18,11 @@
"build:types": "node tools/cleanup types && tsc -p config/tsconfig.types.json"
},
"dependencies": {
"axios": "^1.6.8",
"axios": "^1.7.2",
"axios-mock-adapter": "^1.22.0",
"lodash": "^4.17.21",
"qs": "^6.12.1",
"tslib": "^2.6.2"
"qs": "^6.13.0",
"tslib": "^2.6.3"
},
"files": [
"dist/*",
Expand Down
26 changes: 24 additions & 2 deletions src/lib/request.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,30 @@
import { Axios } from 'axios';
import { AxiosInstance } from './types';

export async function getData(instance: Axios, url: string, data?: any) {
export async function getData(instance: AxiosInstance, url: string, data?: any) {
try {
if (instance.stackConfig && instance.stackConfig.live_preview) {
const livePreviewParams = instance.stackConfig.live_preview;

if (livePreviewParams.enable) {
data.live_preview = livePreviewParams.live_preview || 'init';
}

if (livePreviewParams.preview_token) {
instance.defaults.headers.preview_token = livePreviewParams.preview_token;
instance.defaults.headers.live_preview = livePreviewParams.live_preview;
}

if (livePreviewParams.enable && livePreviewParams.live_preview && livePreviewParams.live_preview !== 'init') {
// adds protocol so host is replaced and not appended
if (livePreviewParams.host.split(0, 8) === 'https://') {
instance.defaults.baseURL = livePreviewParams.host;
} else {
instance.defaults.baseURL = 'https://' + livePreviewParams.host;
}

Check warning on line 23 in src/lib/request.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

Check warning on line 23 in src/lib/request.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch
}

Check warning on line 24 in src/lib/request.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

Check warning on line 24 in src/lib/request.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch
}

Check warning on line 25 in src/lib/request.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch
const response = await instance.get(url, { params: data });

if (response && response.data) {
return response.data;
} else {
Expand Down
1 change: 1 addition & 0 deletions src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type DefaultOptions = AxiosRequestConfig & {
export type AxiosInstance = OriginalAxiosInstance & {
httpClientParams: HttpClientParams;
defaults: DefaultOptions;
stackConfig: any;
};

/*
Expand Down
Loading