From a383b349fa27c9b222ae49d148b11a0a19b42489 Mon Sep 17 00:00:00 2001 From: Nadeem Patwekar Date: Wed, 7 Aug 2024 14:01:50 +0530 Subject: [PATCH 1/3] feat: live preview configured --- CHANGELOG.md | 4 ++++ src/lib/contentstack.ts | 15 +++------------ src/lib/stack.ts | 11 ++++++++--- test/api/contenttype-query.spec.ts | 9 ++++++--- test/api/live-preview.spec.ts | 4 ++-- test/unit/live-preview.spec.ts | 4 ++-- test/utils/stack-instance.ts | 5 +++++ 7 files changed, 30 insertions(+), 22 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 32a8fb5..c86d724 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ ## Change log +### Version: 4.2.0 +#### Date: August-08-2024 +Feat: fetch asset by any field-uid other that asset-uid + ### Version: 4.1.0 #### Date: August-08-2024 Feat: fetch asset by any field-uid other that asset-uid diff --git a/src/lib/contentstack.ts b/src/lib/contentstack.ts index f6e66d1..3535c51 100644 --- a/src/lib/contentstack.ts +++ b/src/lib/contentstack.ts @@ -40,17 +40,8 @@ export function stack(config: StackConfig): StackClass { live_preview: {} as any }; - if (config.live_preview?.enable === true) { - if (config.live_preview?.management_token != null && config.live_preview?.preview_token == null) { - config.host = config.live_preview.host - } else if (config.live_preview?.preview_token != null && config.live_preview?.management_token == null) { - config.host = config.live_preview.host - } - } else { - defaultConfig.defaultHostname = config.host ? config.host : getHost(config.region, config.host); - config.host = config.host || defaultConfig.defaultHostname; - defaultConfig.live_preview = config.live_preview - } + defaultConfig.defaultHostname = config.host || getHost(config.region, config.host); + config.host = defaultConfig.defaultHostname; if (config.apiKey) { defaultConfig.headers.api_key = config.apiKey; @@ -78,7 +69,7 @@ export function stack(config: StackConfig): StackClass { defaultConfig.headers['X-User-Agent'] = 'contentstack-delivery-typescript-{{PLATFORM}}/' + version; - // return new Stack(httpClient(defaultConfig), config); + const client = httpClient(defaultConfig as any); if (config.logHandler) client.defaults.logHandler = config.logHandler; diff --git a/src/lib/stack.ts b/src/lib/stack.ts index f14ca02..f73a0cd 100644 --- a/src/lib/stack.ts +++ b/src/lib/stack.ts @@ -15,6 +15,7 @@ export class Stack { constructor(client: AxiosInstance, config: StackConfig) { this._client = client; this.config = config; + this._client.stackConfig = this.config; } /** @@ -144,9 +145,13 @@ export class Stack { livePreviewQuery(query: LivePreviewQuery) { if (this.config.live_preview) { - this.config.live_preview.live_preview = query.live_preview || 'init'; - this.config.live_preview.contentTypeUid = query.contentTypeUid; - this.config.live_preview.entryUid = query.entryUid + const livePreviewParams: any = { + ...this.config.live_preview, + live_preview: query.live_preview || 'init', + contentTypeUid: query.contentTypeUid, + entryUid: query.entryUid + } + this._client.stackConfig.live_preview = livePreviewParams; } } } diff --git a/test/api/contenttype-query.spec.ts b/test/api/contenttype-query.spec.ts index b67f7b4..db167e6 100644 --- a/test/api/contenttype-query.spec.ts +++ b/test/api/contenttype-query.spec.ts @@ -1,11 +1,14 @@ +// @ts-nocheck import { ContentTypeQuery } from '../../src/lib/contenttype-query'; import { stackInstance } from '../utils/stack-instance'; -import { TContentTypes } from './types'; +import { TContentType, TContentTypes } from './types'; const stack = stackInstance(); describe('ContentTypeQuery API test cases', () => { - it('should check for content_types are defined', async () => { - const result = await makeContentTypeQuery().find(); + it.only('should check for content_types are defined', async () => { + const result = await makeContentTypeQuery().find(); + console.log('🚀 ~ it.only ~ result:', result.content_types?.length); + expect(result.content_types).toBeDefined(); expect(result.content_types[0]._version).toBeDefined(); expect(result.content_types[0].uid).toBeDefined(); diff --git a/test/api/live-preview.spec.ts b/test/api/live-preview.spec.ts index d50835a..b05cb45 100644 --- a/test/api/live-preview.spec.ts +++ b/test/api/live-preview.spec.ts @@ -38,7 +38,7 @@ describe('Live preview tests', () => { expect(livePreviewObject).toHaveProperty('enable'); expect(livePreviewObject).toHaveProperty('host'); expect(livePreviewObject).not.toHaveProperty('preview'); - expect(stack.config.host).toBe('api.contentstack.io'); + expect(stack.config.host).toBe('cdn.contentstack.io'); }); test('should check host when live preview is disabled and management token is provided', () => { @@ -74,7 +74,7 @@ describe('Live preview tests', () => { expect(livePreviewObject).toHaveProperty('enable'); expect(livePreviewObject).toHaveProperty('host'); expect(livePreviewObject).not.toHaveProperty('preview'); - expect(stack.config.host).toBe('rest-preview.contentstack.com'); + expect(stack.config.host).toBe('cdn.contentstack.io'); }); test('should check host when live preview is disabled and preview token is provided', () => { diff --git a/test/unit/live-preview.spec.ts b/test/unit/live-preview.spec.ts index 392ea10..060bfe2 100644 --- a/test/unit/live-preview.spec.ts +++ b/test/unit/live-preview.spec.ts @@ -29,7 +29,7 @@ describe('Live preview tests', () => { expect(livePreviewObject).toHaveProperty('enable'); expect(livePreviewObject).toHaveProperty('host'); expect(livePreviewObject).not.toHaveProperty('preview'); - expect(stack.config.host).toBe('api.contentstack.io'); + expect(stack.config.host).toBe('cdn.contentstack.io'); }); test('should check host when live preview is disabled and management token is provided', () => { @@ -68,7 +68,7 @@ describe('Live preview tests', () => { expect(livePreviewObject).toHaveProperty('host'); expect(livePreviewObject).toHaveProperty('preview_token'); expect(livePreviewObject).not.toHaveProperty('management_token'); - expect(stack.config.host).toBe('rest-preview.contentstack.com'); + expect(stack.config.host).toBe('cdn.contentstack.io'); }); test('should check host when live preview is disabled and preview token is provided', () => { diff --git a/test/utils/stack-instance.ts b/test/utils/stack-instance.ts index 9b1d55a..577657a 100644 --- a/test/utils/stack-instance.ts +++ b/test/utils/stack-instance.ts @@ -9,6 +9,11 @@ function stackInstance() { apiKey: process.env.API_KEY || '', deliveryToken: process.env.DELIVERY_TOKEN || '', environment: process.env.ENVIRONMENT || '', + live_preview: { + enable: true, + preview_token: "abcda", + host: "xyz,contentstack.com", + } }; return contentstack.stack(params); From c4089477583cb5aff868b744b5cc1f74e7d8e01e Mon Sep 17 00:00:00 2001 From: Nadeem Patwekar Date: Wed, 7 Aug 2024 17:48:57 +0530 Subject: [PATCH 2/3] chore: removed console log --- test/api/contenttype-query.spec.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/test/api/contenttype-query.spec.ts b/test/api/contenttype-query.spec.ts index db167e6..8a44b6e 100644 --- a/test/api/contenttype-query.spec.ts +++ b/test/api/contenttype-query.spec.ts @@ -7,7 +7,6 @@ const stack = stackInstance(); describe('ContentTypeQuery API test cases', () => { it.only('should check for content_types are defined', async () => { const result = await makeContentTypeQuery().find(); - console.log('🚀 ~ it.only ~ result:', result.content_types?.length); expect(result.content_types).toBeDefined(); expect(result.content_types[0]._version).toBeDefined(); From c5a46dfce4bbb48995d20467ee8ae8baac8388e0 Mon Sep 17 00:00:00 2001 From: Nadeem Patwekar Date: Wed, 7 Aug 2024 17:56:40 +0530 Subject: [PATCH 3/3] chore: version and changelog fixes --- .talismanrc | 2 +- CHANGELOG.md | 4 +-- package-lock.json | 71 ++++++++++++++++++++++++++++++++++++++++------- package.json | 4 +-- 4 files changed, 66 insertions(+), 15 deletions(-) diff --git a/.talismanrc b/.talismanrc index 2264ad1..5e77b2f 100644 --- a/.talismanrc +++ b/.talismanrc @@ -4,7 +4,7 @@ fileignoreconfig: - filename: test/utils/mocks.ts checksum: a1cb4b1890a584f1facd30f2a0974c97a66f91417022be79d00516338e244227 - filename: package-lock.json - checksum: 6c9beae17fc270641d855026896e49a1458a6b3a026df30265c51420d364d18a + checksum: 96574fb5fc78856631105fb10913a630466662907e7f8e7bebb5f0d566259b9d - filename: test/typescript/taxonomy.test.ts checksum: e4bdf633e147fd60d929d379f20c814eed5f68b11421d7b53ec8826e9142de37 - filename: src/core/modules/taxonomy.js diff --git a/CHANGELOG.md b/CHANGELOG.md index c86d724..a59e919 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,8 @@ ## Change log ### Version: 4.2.0 -#### Date: August-08-2024 -Feat: fetch asset by any field-uid other that asset-uid +#### Date: August-07-2024 +Feat: Live Preview configuration changes ### Version: 4.1.0 #### Date: August-08-2024 diff --git a/package-lock.json b/package-lock.json index 1f1a958..63936d9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,14 +1,14 @@ { "name": "@contentstack/delivery-sdk", - "version": "4.1.0", + "version": "4.2.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@contentstack/delivery-sdk", - "version": "4.1.0", + "version": "4.2.0", "dependencies": { - "@contentstack/core": "^1.0.3", + "@contentstack/core": "^1.0.4", "@contentstack/utils": "^1.3.8", "@types/humps": "^2.0.6", "axios": "^1.7.2", @@ -30,6 +30,57 @@ "webpack-cli": "^5.1.4" } }, + "../contentstack-js-core": { + "name": "@contentstack/core", + "version": "1.0.4", + "extraneous": true, + "dependencies": { + "axios": "^1.7.2", + "axios-mock-adapter": "^1.22.0", + "lodash": "^4.17.21", + "qs": "^6.12.1", + "tslib": "^2.6.2" + }, + "devDependencies": { + "@commitlint/cli": "^17.8.1", + "@commitlint/config-conventional": "^17.8.1", + "@cspell/eslint-plugin": "^6.31.3", + "@types/jest": "28.1.1", + "@types/lodash": "^4.17.0", + "@types/node": "16.11.7", + "@types/qs": "^6.9.14", + "@typescript-eslint/eslint-plugin": "^5.62.0", + "@typescript-eslint/parser": "^5.62.0", + "babel-jest": "28.1.1", + "commitizen": "^4.3.0", + "eslint": "~8.15.0", + "eslint-config-airbnb-typescript": "^17.1.0", + "eslint-config-prettier": "8.1.0", + "eslint-import-resolver-webpack": "^0.13.8", + "eslint-plugin-cypress": "^2.15.1", + "eslint-plugin-eslint-comments": "^3.2.0", + "eslint-plugin-functional": "^4.4.1", + "eslint-plugin-import": "^2.29.1", + "eslint-plugin-jsx-a11y": "^6.8.0", + "eslint-plugin-prettier": "^4.2.1", + "eslint-plugin-promise": "^6.1.1", + "eslint-plugin-react": "^7.34.1", + "eslint-plugin-react-hooks": "^4.6.0", + "eslint-plugin-spellcheck": "^0.0.20", + "husky": "^8.0.3", + "jest": "28.1.1", + "jest-environment-jsdom": "28.1.1", + "jest-html-reporters": "^3.1.7", + "jest-junit": "^15.0.0", + "prettier": "^2.8.8", + "ts-jest": "28.0.5", + "ts-loader": "^9.5.1", + "ts-node": "10.9.1", + "typescript": "~4.8.4", + "webpack": "^5.91.0", + "webpack-cli": "^4.10.0" + } + }, "node_modules/@ampproject/remapping": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/@ampproject/remapping/-/remapping-2.3.0.tgz", @@ -1852,8 +1903,8 @@ "dev": true }, "node_modules/@contentstack/core": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/@contentstack/core/-/core-1.0.3.tgz", + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/@contentstack/core/-/core-1.0.4.tgz", "integrity": "sha512-yZaZM/I5NWY1LskyXvvkMG6CIqQN92EFb5cB7jeA8ahZ8RSF/5pDBKRM6P3BcHRfQ8JQOWkFs4M5ZiDTadIHrA==", "dependencies": { "axios": "^1.6.8", @@ -3652,8 +3703,8 @@ "dev": true }, "node_modules/@tsconfig/node14": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/@tsconfig/node14/-/node14-1.0.3.tgz", + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/@tsconfig/node14/-/node14-1.0.4.tgz", "integrity": "sha512-ysT8mhdixWK6Hw3i1V2AeRqZ5WfXg1G43mqoYlM2nc6388Fq5jcXyr5mRsqViLx/GJYdoL0bfXD8nmF+Zn/Iow==", "dev": true }, @@ -9549,9 +9600,9 @@ ] }, "node_modules/qs": { - "version": "6.12.2", - "resolved": "https://registry.npmjs.org/qs/-/qs-6.12.2.tgz", - "integrity": "sha512-x+NLUpx9SYrcwXtX7ob1gnkSems4i/mGZX5SlYxwIau6RrUSODO89TR/XDGGpn5RPWSYIB+aSfuSlV5+CmbTBg==", + "version": "6.13.0", + "resolved": "https://registry.npmjs.org/qs/-/qs-6.13.0.tgz", + "integrity": "sha512-+38qI9SOr8tfZ4QmJNplMUxqjbe7LKvvZgWdExBOmd+egZTtjLB67Gu0HRX3u/XOq7UU2Nx6nsjvS16Z9uwfpg==", "dependencies": { "side-channel": "^1.0.6" }, diff --git a/package.json b/package.json index bc8e5a0..3558af4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@contentstack/delivery-sdk", - "version": "4.1.0", + "version": "4.2.0", "type": "commonjs", "main": "./dist/cjs/src/index.js", "types": "./dist/types/src/index.d.ts", @@ -20,7 +20,7 @@ "build:types": "node tools/cleanup types && tsc -p config/tsconfig.types.json" }, "dependencies": { - "@contentstack/core": "^1.0.3", + "@contentstack/core": "^1.1.0", "@contentstack/utils": "^1.3.8", "@types/humps": "^2.0.6", "axios": "^1.7.2",