diff --git a/.github/workflows/npm-publish.yml b/.github/workflows/npm-publish.yml new file mode 100644 index 00000000..a7544553 --- /dev/null +++ b/.github/workflows/npm-publish.yml @@ -0,0 +1,34 @@ +# This workflow will publish a package to GitHub Packages when a release is created +# For more information see: https://help.github.com/actions/language-and-framework-guides/publishing-nodejs-packages + +name: Publish package to NPM repository +on: + release: + types: [created] + +jobs: + publish-npm: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: '12.x' + registry-url: 'https://registry.npmjs.org' + - run: npm ci + - run: npm publish + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} + publish-git: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: '12.x' + registry-url: 'https://registry.npmjs.org' + scope: '@contentstack' + - run: npm ci + - run: npm publish + env: + NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.npmignore b/.npmignore index cf2dc799..47e14fe6 100644 --- a/.npmignore +++ b/.npmignore @@ -18,4 +18,5 @@ src .env *.tgz .talismanrc -tap-html.html \ No newline at end of file +tap-html.html +.github \ No newline at end of file diff --git a/.talismanrc b/.talismanrc index 66357cc2..045ea59c 100644 --- a/.talismanrc +++ b/.talismanrc @@ -1,4 +1,4 @@ threshold: medium fileignoreconfig: - filename: package-lock.json - checksum: 032d3a56d28528673b84e083a30d726d15b7c0616d1d6e7e4936d7e6c05534ee + checksum: be538ba2f4b106e5de0a55a3137271f659901e287ec09e8ae93351543242712e \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 373ec498..c4f0e925 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,9 @@ ## Change log + +### Version: 3.15.3 +#### Date: July-26-2022 +##### New Features: + - Live preview with reference in entry on SSR web app issue resolved ### Version: 3.15.2 #### Date: May-03-2022 ##### New Features: diff --git a/README.md b/README.md index bfde0be4..13b323bb 100755 --- a/README.md +++ b/README.md @@ -195,7 +195,7 @@ We have introduced Image Delivery APIs that let you retrieve images and then man For example, if you want to crop an image (with width as 300 and height as 400), you simply need to append query parameters at the end of the image URL, such as, https://images.contentstack.io/owl.jpg?crop=300,400. There are several more parameters that you can use for your images. -[Read Image Delivery API documentation](https://www.contentstack.com/docs/apis/image-delivery-api/). +[Read Image Delivery API documentation](https://www.contentstack.com/docs/developers/apis/image-delivery-api/). Following are Image Delivery API examples. diff --git a/contentstack-templates/tmpl/layout.tmpl b/contentstack-templates/tmpl/layout.tmpl index f75de724..85c39d4a 100755 --- a/contentstack-templates/tmpl/layout.tmpl +++ b/contentstack-templates/tmpl/layout.tmpl @@ -206,7 +206,7 @@ Query.setCachePolicy(Contentstack.CachePolicy.CACHE_THEN_NETWORK)
We have introduced Image Delivery APIs that let you retrieve images and then manipulate and optimize them for your digital properties. It lets you perform a host of other actions such as crop, trim, resize, rotate, overlay, and so on.
For example, if you want to crop an image (with width as 300 and height as 400), you simply need to append query parameters at the end of the image URL, such as, https://images.contentstack.io/owl.jpg?crop=300,400. There are several more parameters that you can use for your images.
-Read Image Delivery API documentation.
+Read Image Delivery API documentation.
Following are Image Delivery API examples.
@@ -233,7 +233,7 @@ const imageUrl = Stack.imageTransform(imageUrl, {Copyright © 2016-2021 Contentstack. All Rights Reserved
diff --git a/package-lock.json b/package-lock.json index 90c3224f..1248b540 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "contentstack", - "version": "3.15.2", + "version": "3.15.4", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -542,11 +542,11 @@ "dev": true }, "@contentstack/utils": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/@contentstack/utils/-/utils-1.1.1.tgz", - "integrity": "sha512-lf+OWthCoLzs81fHrZ8sz0d5IX5iLt0eAuyqpHGvAS+EGOvEoBwMg0tBcA8+GNImvRARCGCwM4dCJub3YkFoIA==", + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/@contentstack/utils/-/utils-1.1.3.tgz", + "integrity": "sha512-0CDjFR95Norw8/MVhiY0WX4gr12ovQOtf8+gn76hcLbfP/N8ydr9o5fjRgxPmzgNGZ9MlEn/y06CN+BSj0G+yw==", "requires": { - "node-html-parser": "^1.4.2" + "node-html-parser": "^5.4.1" } }, "@discoveryjs/json-ext": { @@ -1102,6 +1102,55 @@ "chalk": "^4.0.0" } }, + "@jridgewell/gen-mapping": { + "version": "0.3.2", + "resolved": "https://registry.npmjs.org/@jridgewell/gen-mapping/-/gen-mapping-0.3.2.tgz", + "integrity": "sha512-mh65xKQAzI6iBcFzwv28KVWSmCkdRBWoOh+bYQGW3+6OZvbbN3TqMGo5hqYxQniRcH9F2VZIoJCm4pa3BPDK/A==", + "dev": true, + "requires": { + "@jridgewell/set-array": "^1.0.1", + "@jridgewell/sourcemap-codec": "^1.4.10", + "@jridgewell/trace-mapping": "^0.3.9" + } + }, + "@jridgewell/resolve-uri": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/@jridgewell/resolve-uri/-/resolve-uri-3.1.0.tgz", + "integrity": "sha512-F2msla3tad+Mfht5cJq7LSXcdudKTWCVYUgw6pLFOOHSTtZlj6SWNYAp+AhuqLmWdBO2X5hPrLcu8cVP8fy28w==", + "dev": true + }, + "@jridgewell/set-array": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/@jridgewell/set-array/-/set-array-1.1.2.tgz", + "integrity": "sha512-xnkseuNADM0gt2bs+BvhO0p78Mk762YnZdsuzFV018NoG1Sj1SCQvpSqa7XUaTam5vAGasABV9qXASMKnFMwMw==", + "dev": true + }, + "@jridgewell/source-map": { + "version": "0.3.2", + "resolved": "https://registry.npmjs.org/@jridgewell/source-map/-/source-map-0.3.2.tgz", + "integrity": "sha512-m7O9o2uR8k2ObDysZYzdfhb08VuEml5oWGiosa1VdaPZ/A6QyPkAJuwN0Q1lhULOf6B7MtQmHENS743hWtCrgw==", + "dev": true, + "requires": { + "@jridgewell/gen-mapping": "^0.3.0", + "@jridgewell/trace-mapping": "^0.3.9" + } + }, + "@jridgewell/sourcemap-codec": { + "version": "1.4.14", + "resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.4.14.tgz", + "integrity": "sha512-XPSJHWmi394fuUuzDnGz1wiKqWfo1yXecHQMRf2l6hztTO+nPru658AyDngaBe7isIxEkRsPR3FZh+s7iVa4Uw==", + "dev": true + }, + "@jridgewell/trace-mapping": { + "version": "0.3.15", + "resolved": "https://registry.npmjs.org/@jridgewell/trace-mapping/-/trace-mapping-0.3.15.tgz", + "integrity": "sha512-oWZNOULl+UbhsgB51uuZzglikfIKSUBO/M9W2OfEjn7cmqoAiCgmv9lyACTUacZwBz0ITnJ2NqjU8Tx0DHL88g==", + "dev": true, + "requires": { + "@jridgewell/resolve-uri": "^3.0.3", + "@jridgewell/sourcemap-codec": "^1.4.10" + } + }, "@open-draft/until": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/@open-draft/until/-/until-1.0.3.tgz", @@ -2495,7 +2544,7 @@ "babel-plugin-transform-strict-mode": { "version": "6.24.1", "resolved": "https://registry.npmjs.org/babel-plugin-transform-strict-mode/-/babel-plugin-transform-strict-mode-6.24.1.tgz", - "integrity": "sha1-1fr3qleKZbvlkc9e2uBKDGcCB1g=", + "integrity": "sha512-j3KtSpjyLSJxNoCDrhwiJad8kw0gJ9REGj8/CqL0HeRyLnvUNYV9zcqluL6QJSXh3nfsLEmSLvwRfGzrgR96Pw==", "dev": true, "requires": { "babel-runtime": "^6.22.0", @@ -2765,6 +2814,11 @@ "integrity": "sha512-XpNj6GDQzdfW+r2Wnn7xiSAd7TM3jzkxGXBGTtWKuSXv1xUV+azxAm8jdWZN06QTQk+2N2XB9jRDkvbmQmcRtg==", "dev": true }, + "boolbase": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/boolbase/-/boolbase-1.0.0.tgz", + "integrity": "sha512-JZOSA7Mo9sNGB8+UjSgzdLtokWAky1zbztM3WRLCbZ70/3cTANmQmOdR7y2g+J0e2WXywy1yS468tY+IruqEww==" + }, "brace-expansion": { "version": "1.1.11", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", @@ -3235,6 +3289,58 @@ "integrity": "sha1-iNf/fsDfuG9xPch7u0LQRNPmxBs=", "dev": true }, + "css-select": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/css-select/-/css-select-4.3.0.tgz", + "integrity": "sha512-wPpOYtnsVontu2mODhA19JrqWxNsfdatRKd64kmpRbQgh1KtItko5sTnEpPdpSaJszTOhEMlF/RPz28qj4HqhQ==", + "requires": { + "boolbase": "^1.0.0", + "css-what": "^6.0.1", + "domhandler": "^4.3.1", + "domutils": "^2.8.0", + "nth-check": "^2.0.1" + }, + "dependencies": { + "dom-serializer": { + "version": "1.4.1", + "resolved": "https://registry.npmjs.org/dom-serializer/-/dom-serializer-1.4.1.tgz", + "integrity": "sha512-VHwB3KfrcOOkelEG2ZOfxqLZdfkil8PtJi4P8N2MMXucZq2yLp75ClViUlOVwyoHEDjYU433Aq+5zWP61+RGag==", + "requires": { + "domelementtype": "^2.0.1", + "domhandler": "^4.2.0", + "entities": "^2.0.0" + } + }, + "domelementtype": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/domelementtype/-/domelementtype-2.3.0.tgz", + "integrity": "sha512-OLETBj6w0OsagBwdXnPdN0cnMfF9opN69co+7ZrbfPGrdpPVNBUj02spi6B1N7wChLQiPn4CSH/zJvXw56gmHw==" + }, + "domhandler": { + "version": "4.3.1", + "resolved": "https://registry.npmjs.org/domhandler/-/domhandler-4.3.1.tgz", + "integrity": "sha512-GrwoxYN+uWlzO8uhUXRl0P+kHE4GtVPfYzVLcUxPL7KNdHKj66vvlhiweIHqYYXWlw+T8iLMp42Lm67ghw4WMQ==", + "requires": { + "domelementtype": "^2.2.0" + } + }, + "domutils": { + "version": "2.8.0", + "resolved": "https://registry.npmjs.org/domutils/-/domutils-2.8.0.tgz", + "integrity": "sha512-w96Cjofp72M5IIhpjgobBimYEfoPjx1Vx0BSX9P30WBdZW2WIKU0T1Bd0kz2eNZ9ikjKgHbEyKx8BB6H1L3h3A==", + "requires": { + "dom-serializer": "^1.0.1", + "domelementtype": "^2.2.0", + "domhandler": "^4.2.0" + } + } + } + }, + "css-what": { + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/css-what/-/css-what-6.1.0.tgz", + "integrity": "sha512-HTUrgRJ7r4dsZKU6GjmpfRK1O76h97Z8MfS1G0FozR+oF2kG6Vfe8JE6zwrkbxigziPHinCJ+gCPjA9EaBDtRw==" + }, "cssom": { "version": "0.4.4", "resolved": "https://registry.npmjs.org/cssom/-/cssom-0.4.4.tgz", @@ -3580,8 +3686,7 @@ "entities": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/entities/-/entities-2.1.0.tgz", - "integrity": "sha512-hCx1oky9PFrJ611mf0ifBLBRW8lUUVRlFolb5gWRfIELabBlbp9xZvrqZLZAs+NxFnbfQoeGd8wDkygjg7U85w==", - "dev": true + "integrity": "sha512-hCx1oky9PFrJ611mf0ifBLBRW8lUUVRlFolb5gWRfIELabBlbp9xZvrqZLZAs+NxFnbfQoeGd8wDkygjg7U85w==" }, "envinfo": { "version": "7.8.1", @@ -6757,9 +6862,9 @@ } }, "localStorage": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/localStorage/-/localStorage-1.0.3.tgz", - "integrity": "sha1-5riaV7t2ChVqOMyH4PJVD27UE9g=" + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/localStorage/-/localStorage-1.0.4.tgz", + "integrity": "sha512-r35zrihcDiX+dqWlJSeIwS9nrF95OQTgqMFm3FB2D/+XgdmZtcutZOb7t0xXkhOEM8a9kpuu7cc28g1g36I5DQ==" }, "locate-path": { "version": "2.0.0", @@ -7059,10 +7164,11 @@ } }, "node-html-parser": { - "version": "1.4.9", - "resolved": "https://registry.npmjs.org/node-html-parser/-/node-html-parser-1.4.9.tgz", - "integrity": "sha512-UVcirFD1Bn0O+TSmloHeHqZZCxHjvtIeGdVdGMhyZ8/PWlEiZaZ5iJzR189yKZr8p0FXN58BUeC7RHRkf/KYGw==", + "version": "5.4.2", + "resolved": "https://registry.npmjs.org/node-html-parser/-/node-html-parser-5.4.2.tgz", + "integrity": "sha512-RaBPP3+51hPne/OolXxcz89iYvQvKOydaqoePpOgXcrOKZhjVIzmpKZz+Hd/RBO2/zN2q6CNJhQzucVz+u3Jyw==", "requires": { + "css-select": "^4.2.1", "he": "1.2.0" } }, @@ -7137,6 +7243,14 @@ "path-key": "^3.0.0" } }, + "nth-check": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/nth-check/-/nth-check-2.1.1.tgz", + "integrity": "sha512-lqjrjmaOoAnWfMmBPL+XNnynZh2+swxiX3WUE0s4yEHI6m+AwrK2UZOimIRl3X/4QctVqS8AiZjFqyOGrMXb/w==", + "requires": { + "boolbase": "^1.0.0" + } + }, "nwsapi": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/nwsapi/-/nwsapi-2.2.0.tgz", @@ -7543,7 +7657,7 @@ "path-exists": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-3.0.0.tgz", - "integrity": "sha1-zg6+ql94yxiSXqfYENe1mwEP1RU=", + "integrity": "sha512-bpC7GYwiDYQ4wYLe+FA8lhRjhQCMcQGuSgGGqDkg/QerRWw9CmGRT0iSOVRSZJ29NMLZgIzqaljJ63oaL4NIJQ==", "dev": true }, "path-is-absolute": { @@ -9936,27 +10050,27 @@ } }, "terser": { - "version": "5.12.1", - "resolved": "https://registry.npmjs.org/terser/-/terser-5.12.1.tgz", - "integrity": "sha512-NXbs+7nisos5E+yXwAD+y7zrcTkMqb0dEJxIGtSKPdCBzopf7ni4odPul2aechpV7EXNvOudYOX2bb5tln1jbQ==", + "version": "5.15.0", + "resolved": "https://registry.npmjs.org/terser/-/terser-5.15.0.tgz", + "integrity": "sha512-L1BJiXVmheAQQy+as0oF3Pwtlo4s3Wi1X2zNZ2NxOB4wx9bdS9Vk67XQENLFdLYGCK/Z2di53mTj/hBafR+dTA==", "dev": true, "requires": { + "@jridgewell/source-map": "^0.3.2", "acorn": "^8.5.0", "commander": "^2.20.0", - "source-map": "~0.7.2", "source-map-support": "~0.5.20" }, "dependencies": { "acorn": { - "version": "8.7.0", - "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.7.0.tgz", - "integrity": "sha512-V/LGr1APy+PXIwKebEWrkZPwoeoF+w1jiOBUmuxuiUIaOHtob8Qc9BTrYo7VuI5fR8tqsy+buA2WFooR5olqvQ==", + "version": "8.8.0", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.8.0.tgz", + "integrity": "sha512-QOxyigPVrpZ2GXT+PFyZTl6TtOFc5egxHIP9IlQ+RbupQuX4RkT/Bee4/kQuC02Xkzg84JcT7oLYtDIQxp+v7w==", "dev": true }, "source-map": { - "version": "0.7.3", - "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.7.3.tgz", - "integrity": "sha512-CkCj6giN3S+n9qrYiBTX5gystlENnRW5jZeNLHpe6aue+SrHcG5VYwujhW9s4dY31mEGsxBDrHR6oI69fTXsaQ==", + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", + "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==", "dev": true }, "source-map-support": { @@ -9967,14 +10081,6 @@ "requires": { "buffer-from": "^1.0.0", "source-map": "^0.6.0" - }, - "dependencies": { - "source-map": { - "version": "0.6.1", - "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", - "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==", - "dev": true - } } } } diff --git a/package.json b/package.json old mode 100755 new mode 100644 index 088a1a48..1b879d35 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "contentstack", - "version": "3.15.2", + "version": "3.15.4", "description": "Contentstack Javascript SDK", "homepage": "https://www.contentstack.com/", "author": { @@ -11,7 +11,7 @@ "browser": "dist/web/contentstack.js", "react-native": "dist/react-native/contentstack.js", "types": "./index.d.ts", - "_id": "contentstack@3.15.0", + "_id": "contentstack@3.15.4", "scripts": { "test": "npm run test:e2e && npm run test:typescript", "test:e2e": "tape test/index.js | tap-html --out ./tap-html.html", @@ -55,11 +55,11 @@ ], "dist": { "shasum": "a328ed07240476a26b31a23261355dc929e1da63", - "tarball": "https://registry.npmjs.org/contentstack/-/contentstack-3.15.0.tgz" + "tarball": "https://registry.npmjs.org/contentstack/-/contentstack-3.15.4.tgz" }, "license": "MIT", "directories": {}, - "_resolved": "https://registry.npmjs.org/contentstack/-/contentstack-3.15.0.tgz", + "_resolved": "https://registry.npmjs.org/contentstack/-/contentstack-3.15.4.tgz", "_npmOperationalInternal": { "host": "packages-18-east.internal.npmjs.com", "tmp": "tmp/contentstack-3.15.0.tgz_1477830884275_0.9869455888401717" @@ -103,9 +103,9 @@ "webpack-node-externals": "^3.0.0" }, "dependencies": { - "@contentstack/utils": "^1.1.1", + "@contentstack/utils": "^1.1.3", "es6-promise": "^4.1.1", "isomorphic-fetch": "^3.0.0", - "localStorage": "1.0.3" + "localStorage": "1.0.4" } } diff --git a/src/core/lib/request.js b/src/core/lib/request.js index 06cb2b29..ec14ec3e 100755 --- a/src/core/lib/request.js +++ b/src/core/lib/request.js @@ -68,6 +68,7 @@ function fetchRetry(url, headers, fetchOptions, resolve, reject, retryDelay = 30 function onError (error) { if (retryLimit === 0) { + fetchOptions.logHandler('error', error); reject(error); }else { var msDelay = retryDelay @@ -89,23 +90,28 @@ function fetchRetry(url, headers, fetchOptions, resolve, reject, retryDelay = 30 }) } } + fetchOptions.logHandler('info', { url: url, option: option}); fetch(url, option) .then(function(response) { + fetchOptions.logHandler('info', response); let data = response.json(); if (response.ok && response.status === 200) { resolve(data); } else { data.then((json) => { if (fetchOptions.retryCondition && fetchOptions.retryCondition(response)) { - onError(json) + onError(json) } else { + fetchOptions.logHandler('error', json); reject(json) } }).catch(() => { + fetchOptions.logHandler('error', {status: response.status, statusText: response.statusText}); reject({status: response.status, statusText: response.statusText}) }); } }).catch((error) => { + fetchOptions.logHandler('error', error); reject(error) }); } \ No newline at end of file diff --git a/src/core/modules/assets.js b/src/core/modules/assets.js index 3e361d7c..74c4887f 100755 --- a/src/core/modules/assets.js +++ b/src/core/modules/assets.js @@ -75,7 +75,7 @@ export default class Assets { this._query[key] = value; return this; } else { - console.error("Kindly provide a valid parameters."); + this.fetchOptions.logHandler('error',"Kindly provide a valid parameters."); } } @@ -117,9 +117,9 @@ export default class Assets { } } var options = Utils.mergeDeep(this.fetchOptions, fetchOptions); - return Utils.sendRequest(this, options); + return Utils.sendRequest(Utils.mergeDeep({}, this), options); } else { - console.error("Kindly provide an asset uid. e.g. .Assets('asset_uid')"); + fetchOptions.logHandler('error', "Kindly provide an asset uid. e.g. .Assets('asset_uid')"); } } } \ No newline at end of file diff --git a/src/core/modules/entry.js b/src/core/modules/entry.js index dfa4b185..2794623b 100755 --- a/src/core/modules/entry.js +++ b/src/core/modules/entry.js @@ -83,7 +83,7 @@ export default class Entry { this.queryCachePolicy = policy; } } else { - console.error("Kindly provide the valid policy"); + this.fetchOptions.logHandler('error', "Kindly provide the valid policy"); } return this; } @@ -135,7 +135,7 @@ export default class Entry { } return this; } else { - console.error("Argument should be a String or an Array."); + this.fetchOptions.logHandler('error', "Argument should be a String or an Array."); } } @@ -160,7 +160,7 @@ export default class Entry { this._query['locale'] = language_code; return this; } else { - console.error("Argument should be a String."); + this.fetchOptions.logHandler('error', "Argument should be a String."); } } @@ -179,7 +179,7 @@ export default class Entry { this._query[key] = value; return this; } else { - console.error("First argument should be a String."); + this.fetchOptions.logHandler('error', "First argument should be a String."); } } @@ -323,7 +323,7 @@ export default class Entry { this._query[key] = value; return this; } else { - console.error("Kindly provide valid parameters."); + this.fetchOptions.logHandler('error', "Kindly provide valid parameters."); } } @@ -358,9 +358,9 @@ export default class Entry { } }; var options = Utils.mergeDeep(this.fetchOptions, fetchOptions); - return Utils.sendRequest(this, options); + return Utils.sendRequest(Utils.mergeDeep({}, this), options); } else { - console.error("Kindly provide an entry uid. e.g. .Entry('asset_uid')"); + this.fetchOptions.logHandler('error', "Kindly provide an entry uid. e.g. .Entry('asset_uid')"); } } } \ No newline at end of file diff --git a/src/core/modules/query.js b/src/core/modules/query.js index 367b7f9b..5704ae7d 100755 --- a/src/core/modules/query.js +++ b/src/core/modules/query.js @@ -9,7 +9,7 @@ const _extend = { this._query['query'][key][type] = value; return this; } else { - console.error("Kindly provide valid parameters."); + this.fetchOptions.logHandler('error', "Kindly provide valid parameters."); } }; }, @@ -22,7 +22,7 @@ const _extend = { this._query['query'][key][type] = this._query['query'][key][type].concat(value); return this; } else { - console.error("Kindly provide valid parameters."); + this.fetchOptions.logHandler('error', "Kindly provide valid parameters."); } }; }, @@ -33,7 +33,7 @@ const _extend = { this._query['query'][key]['$exists'] = bool; return this; } else { - console.error("Kindly provide valid parameters."); + this.fetchOptions.logHandler('error', "Kindly provide valid parameters."); } }; }, @@ -61,7 +61,7 @@ const _extend = { this._query[type] = key; return this; } else { - console.error("Argument should be a string."); + this.fetchOptions.logHandler('error', "Argument should be a string."); } }; }, @@ -71,7 +71,7 @@ const _extend = { this._query[type] = value; return this; } else { - console.error("Argument should be a number."); + this.fetchOptions.logHandler('error', "Argument should be a number."); } } } @@ -395,7 +395,7 @@ export default class Query extends Entry { return this; } else { - console.error("Kindly provide valid parameters."); + this.fetchOptions.logHandler('error', "Kindly provide valid parameters."); } } @@ -420,7 +420,7 @@ export default class Query extends Entry { this._query['query'][key] = value; return this; } else { - console.error("Kindly provide valid parameters."); + this.fetchOptions.logHandler('error', "Kindly provide valid parameters."); } } @@ -476,7 +476,7 @@ export default class Query extends Entry { this._query['query'] = Utils.mergeDeep(this._query['query'], query); return this; } else { - console.error("Kindly provide valid parameters"); + this.fetchOptions.logHandler('error', "Kindly provide valid parameters"); } } @@ -587,7 +587,7 @@ export default class Query extends Entry { this._query['tags'] = values; return this; } else { - console.error("Kindly provide valid parameters"); + this.fetchOptions.logHandler('error', "Kindly provide valid parameters"); } } @@ -651,7 +651,7 @@ export default class Query extends Entry { this._query[key] = value; return this; } else { - console.error("Kindly provide valid parameters."); + this.fetchOptions.logHandler('error', "Kindly provide valid parameters."); } } @@ -691,7 +691,7 @@ export default class Query extends Entry { if (options) this._query['query'][key]['$options'] = options; return this; } else { - console.error("Kindly provide valid parameters."); + this.fetchOptions.logHandler('error', "Kindly provide valid parameters."); } } @@ -717,7 +717,7 @@ export default class Query extends Entry { this._query['typeahead'] = value; return this; } else { - console.error("Kindly provide valid parameters."); + this.fetchOptions.logHandler('error', "Kindly provide valid parameters."); } } @@ -762,7 +762,7 @@ export default class Query extends Entry { } }; var options = Utils.mergeDeep(this.fetchOptions, fetchOptions); - return Utils.sendRequest(this, options); + return Utils.sendRequest(Utils.mergeDeep({}, this), options); } /** @@ -799,7 +799,7 @@ export default class Query extends Entry { } }; var options = Utils.mergeDeep({}, this.fetchOptions); - return Utils.sendRequest(this, options); + return Utils.sendRequest(Utils.mergeDeep({}, this), options); } } \ No newline at end of file diff --git a/src/core/stack.js b/src/core/stack.js index 4137e700..4abc6a3f 100755 --- a/src/core/stack.js +++ b/src/core/stack.js @@ -25,6 +25,7 @@ let errorRetry = [408, 429] * @param param.fetchOptions.retryCondition - A function to determine if the error can be retried. Default retry is on status codes 408, 429. * @param param.fetchOptions.retryDelayOptions.base - The base number of milliseconds to use in the exponential backoff for operation retries. * @param param.fetchOptions.retryDelayOptions.customBackoff - A custom function that accepts a retry count and error and returns the amount of time to delay in milliseconds. + * @param param.fetchOptions.logHandler - A function for logging of requests, responses and errors * * @example * var Stack = Contentstack.Stack({ @@ -33,7 +34,7 @@ let errorRetry = [408, 429] * 'environment':'environment_name', * 'region': 'us', * 'fetchOptions': { - * + * * } * }); * @@ -49,6 +50,18 @@ export default class Stack { return true; } return false + }, + logHandler: (level, data) => { + if (level === 'error' && data) { + console.error(`[error] ${data}`) + return + } else if (level === 'warning' && data) { + console.warn(`[warning] ${data}`) + return + } else if (level === 'info' && data) { + console.info(`[info] ${data}`) + return + } } }; this.config = Utils.mergeDeep({}, config) @@ -80,10 +93,10 @@ export default class Stack { this.environment = stack_arguments[0].environment; return this; } else { - console.error("Kindly provide valid object parameters. The specified API Key, Delivery Token, or Environment Name is invalid."); + this.fetchOptions.logHandler('error', "Kindly provide valid object parameters. The specified API Key, Delivery Token, or Environment Name is invalid."); } case 3: - console.warn("WARNING! Obsolete function called. Function 'Contentstack.Stack(api_key, delivery_token, environment)' has been deprecated, please use 'Contentstack.Stack({api_key, delivery_token, environment, region, branch, fetchOptions})' function instead!"); + this.fetchOptions.logHandler('warning', "WARNING! Obsolete function called. Function 'Contentstack.Stack(api_key, delivery_token, environment)' has been deprecated, please use 'Contentstack.Stack({api_key, delivery_token, environment, region, branch, fetchOptions})' function instead!"); if (typeof stack_arguments[0] === "string" && typeof stack_arguments[1] === "string" && typeof stack_arguments[2] === "string") { this.headers = { api_key: stack_arguments[0], @@ -92,10 +105,10 @@ export default class Stack { this.environment = stack_arguments[2]; return this; } else { - console.error("Kindly provide valid string parameters."); + this.fetchOptions.logHandler('error', "Kindly provide valid string parameters."); } case 4: - console.warn("WARNING! Obsolete function called. Function 'Contentstack.Stack(api_key, delivery_token, environment)' has been deprecated, please use 'Contentstack.Stack({api_key, delivery_token, environment, region, branch, fetchOptions})' function instead!"); + this.fetchOptions.logHandler('warning', "WARNING! Obsolete function called. Function 'Contentstack.Stack(api_key, delivery_token, environment)' has been deprecated, please use 'Contentstack.Stack({api_key, delivery_token, environment, region, branch, fetchOptions})' function instead!"); if (typeof stack_arguments[0] === "string" && typeof stack_arguments[1] === "string" && typeof stack_arguments[2] === "string") { this.headers = { api_key: stack_arguments[0], @@ -103,7 +116,7 @@ export default class Stack { }; this.environment = stack_arguments[2]; } else { - console.error("Kindly provide valid string parameters."); + this.fetchOptions.logHandler('error', "Kindly provide valid string parameters."); } if (stack_arguments[3]) { if(typeof stack_arguments[3] === "string" && stack_arguments[3] !== undefined && stack_arguments[3] !== "us") { @@ -114,7 +127,7 @@ export default class Stack { } return this; case 5: - console.warn("WARNING! Obsolete function called. Function 'Contentstack.Stack(api_key, delivery_token, environment)' has been deprecated, please use 'Contentstack.Stack({api_key, delivery_token, environment, region, branch, fetchOptions})' function instead!"); + this.fetchOptions.logHandler('warning', "WARNING! Obsolete function called. Function 'Contentstack.Stack(api_key, delivery_token, environment)' has been deprecated, please use 'Contentstack.Stack({api_key, delivery_token, environment, region, branch, fetchOptions})' function instead!"); if (typeof stack_arguments[0] === "string" && typeof stack_arguments[1] === "string" && typeof stack_arguments[2] === "string") { this.headers = { api_key: stack_arguments[0], @@ -122,7 +135,7 @@ export default class Stack { }; this.environment = stack_arguments[2]; } else { - console.error("Kindly provide valid string parameters."); + this.fetchOptions.logHandler('error', "Kindly provide valid string parameters."); } if (stack_arguments[3]) { @@ -137,7 +150,7 @@ export default class Stack { } return this; default: - console.error("Kindly provide valid parameters to initialize the Contentstack javascript-SDK Stack."); + this.fetchOptions.logHandler('error', "Kindly provide valid parameters to initialize the Contentstack javascript-SDK Stack."); } } @@ -203,7 +216,7 @@ export default class Stack { this.queryCachePolicy = policy; } } else { - console.error("Kindly provide the valid policy"); + this.fetchOptions.logHandler('error', "Kindly provide the valid policy"); } return this; } @@ -211,7 +224,7 @@ export default class Stack { livePreviewQuery(query) { if (this.live_preview) { - this.live_preview.live_preview = query.live_preview; + this.live_preview.live_preview = query.live_preview || 'init'; this.live_preview.content_type_uid = query.content_type_uid; this.live_preview.entry_uid = query.entry_uid } @@ -520,7 +533,7 @@ export default class Stack { } } var options = Utils.mergeDeep(this.fetchOptions, fetchOptions); - return Utils.sendRequest(this, options); + return Utils.sendRequest(Utils.mergeDeep({}, this), options); } /** diff --git a/test/typescript/asset-query.test.ts b/test/typescript/asset-query.test.ts index c7bfc56c..723b3dd2 100644 --- a/test/typescript/asset-query.test.ts +++ b/test/typescript/asset-query.test.ts @@ -1,6 +1,10 @@ import * as Contentstack from '../..'; -const stack = Contentstack.Stack({ api_key: 'api_key', delivery_token: 'delivery_token', environment: 'environment'}); +const stack = Contentstack.Stack({ api_key: 'api_key', delivery_token: 'delivery_token', environment: 'environment', fetchOptions: { + logHandler: () => { + + } +}}); describe('Asset Query Test', () => { test('Asset Query with UID', done => { diff --git a/test/typescript/asset.test.ts b/test/typescript/asset.test.ts index d9e64bd3..29b5b5f7 100644 --- a/test/typescript/asset.test.ts +++ b/test/typescript/asset.test.ts @@ -1,6 +1,11 @@ import * as Contentstack from '../..'; -const stack = Contentstack.Stack({ api_key: 'api_key', delivery_token: 'delivery_token', environment: 'environment'}); +const stack = Contentstack.Stack({ api_key: 'api_key', delivery_token: 'delivery_token', environment: 'environment',fetchOptions: { + logHandler: () => { + + } +} +}); describe('Asset Test', () => { test('Asset with UID', done => { diff --git a/test/typescript/contentType.test.ts b/test/typescript/contentType.test.ts index b4720af1..ca879ac1 100644 --- a/test/typescript/contentType.test.ts +++ b/test/typescript/contentType.test.ts @@ -1,6 +1,10 @@ import * as Contentstack from '../..'; -const stack = Contentstack.Stack({ api_key: 'api_key', delivery_token: 'delivery_token', environment: 'environment'}); +const stack = Contentstack.Stack({ api_key: 'api_key', delivery_token: 'delivery_token', environment: 'environment', fetchOptions: { + logHandler: () => { + + } +}}); describe('ContentType Test', () => { test('ContentType UID', done => { const contentType = stack.ContentType('uid'); diff --git a/test/typescript/entry-query.test.ts b/test/typescript/entry-query.test.ts index 71326f72..104e3838 100644 --- a/test/typescript/entry-query.test.ts +++ b/test/typescript/entry-query.test.ts @@ -1,6 +1,10 @@ import * as Contentstack from '../..'; -const stack = Contentstack.Stack({ api_key: 'api_key', delivery_token: 'delivery_token', environment: 'environment'}); +const stack = Contentstack.Stack({ api_key: 'api_key', delivery_token: 'delivery_token', environment: 'environment', fetchOptions: { + logHandler: () => { + + } +}}); describe('Entry Query Test', () => { test('Entry Query with UID', done => { diff --git a/test/typescript/entry.test.ts b/test/typescript/entry.test.ts index 4d8da800..910e0815 100644 --- a/test/typescript/entry.test.ts +++ b/test/typescript/entry.test.ts @@ -1,6 +1,10 @@ import * as Contentstack from '../..'; -const stack = Contentstack.Stack({ api_key: 'api_key', delivery_token: 'delivery_token', environment: 'environment'}); +const stack = Contentstack.Stack({ api_key: 'api_key', delivery_token: 'delivery_token', environment: 'environment', fetchOptions: { + logHandler: () => { + + } +}}); describe('Entry Test', () => { test('Entry with UID', done => { diff --git a/test/typescript/stack.test.ts b/test/typescript/stack.test.ts index 4f1fa158..7fa6f67d 100644 --- a/test/typescript/stack.test.ts +++ b/test/typescript/stack.test.ts @@ -41,7 +41,10 @@ describe('Stack tests', () => { test('Stack initialization with fetchOptions test', done => { const stack = Contentstack.Stack({ api_key: 'api_key', delivery_token: 'delivery_token', environment: 'environment', fetchOptions:{ - timeout: 2000 + timeout: 2000, + logHandler: () => { + + } }}); expect(stack.cachePolicy).toEqual(Contentstack.CachePolicy.IGNORE_CACHE); expect(stack.environment).toEqual('environment'); @@ -79,7 +82,10 @@ describe('Stack tests', () => { fetchOptions:{ timeout: 2000, retryLimit: 4, - retryDelay: 40 + retryDelay: 40, + logHandler: () => { + + } } }; const stack = Contentstack.Stack(config); @@ -104,7 +110,10 @@ describe('Stack tests', () => { fetchOptions:{ timeout: 2000, retryLimit: 4, - retryDelay: 40 + retryDelay: 40, + logHandler: () => { + + } } }; const stack = Contentstack.Stack(config); @@ -139,7 +148,10 @@ describe('Stack tests', () => { fetchOptions:{ timeout: 2000, retryLimit: 4, - retryDelay: 40 + retryDelay: 40, + logHandler: () => { + + } } }; const stack = Contentstack.Stack(config); @@ -167,7 +179,10 @@ describe('Stack tests', () => { test('Stack initialization with region EU and fetchOptions test', done => { const stack = Contentstack.Stack('api_key', 'delivery_token', 'environment', Contentstack.Region.EU, { - timeout: 2000 + timeout: 2000, + logHandler: () => { + + } }); expect(stack.cachePolicy).toEqual(Contentstack.CachePolicy.IGNORE_CACHE); expect(stack.environment).toEqual('environment');