kontent-ai / delivery-sdk-js Goto Github PK
View Code? Open in Web Editor NEWKontent Delivery SDK for Javascript
Home Page: https://kontent.ai
License: MIT License
Kontent Delivery SDK for Javascript
Home Page: https://kontent.ai
License: MIT License
Getting an error Uncaught ReferenceError: exports is not defined
at line
Object.defineProperty(exports, "__esModule", { value: true }); var kentico_cloud_delivery_typescript_sdk_1 = require("kentico-cloud-delivery-typescript-sdk");
Importing from rxjs such as like:
import { Observable } from 'rxjs/Rx'
might cause the library to be unnecessary large. We should find out how treeshaking works in this case and if we can make it better.
Tips of how to increase code coverage: https://medium.com/walmartlabs/do-you-have-100-code-coverage-10c09a44832b
Coveralls results: https://coveralls.io/github/Enngage/KenticoCloudDeliveryTypeScriptSDK
In issue: #20 you have provided a way how to use taxonomy end point https://github.com/Enngage/KenticoCloudDeliveryTypeScriptSDK#working-with-taxonomies
When you configure the client to use the preview, requests does not contains preview API key, so responses returns status code 401.
Hi,
is there a way to set the base url for accessing kentico cloud? I would like to proxy all calls to protect sensitive data. Is there are global config parameter available?
If not can you please add a configuration?
Instead of calling:
https://preview-deliver.kenticocloud.com/{key}/items?system.type=article
it should call:
https://{custom url}/items?system.type=article
when set.
I've noticed that it appears that the client makes the API calls twice. The first call goes out, doesn't complete and then the second call goes out and then completes like it should. This is the behavior in my React app as well as the simple sample javascript app.
Hi, I have this use case in which I believe the FieldMapService
returns old data. It only happens with modular content and the scenario is as follows:
DeliveryClient.item().get()
.response.debug.rawResponse.xhr.responseText
) contains fresh data, however the processed item returned from the SDK is of an old version.IMHO, the problem lies in the fact, that same instance of DeliveryClient
is used for both requests, which has same instance of QueryService
and somewhere inside same instance of FieldMapService
caches/memoizes its processed items without clearing the cache in between consecutive requests.
To be precise, the item root item is always recomputed aside from being added to processedItems
. However, the modular content is taken from (possibly outdated) cache, which results in outdated data being returned.
I am not 100% sure I have investigated this correctly, could you please have a look?
There are a lot of models that only implement interfaces. In many cases we don't need to have full classes and could do just with having an interface.
We need to get up to speed with the .NET SDK regarding image optimization.
Here's the code: https://github.com/Kentico/delivery-sdk-net/pull/113/files
Scale
image.jpg?mode=scale&width=300
image.jpg?mode=scale&height=150
image.jpg?mode=fit&height=150&width=300
DPR
image.jpg?mode=scale&width=300&dpr=2.0
If a developer provides a parameter with invalid value or omits a parameter that is required for desired optimization, the Asset API will either ignore this parameter, or return the original asset without any optimizations.
Also, to keep our sanity, we will transform each image optimization parameter independently from others. Yes, this approach might sometimes produce surprising results. However, both Fastly and imgix are designed to handle a set of parameters that do not make sense and we are not making the situation worse.
Regarding requests to the Asset API, the idea is to go through all parameters, transform the supported ones and get rid of everything else.
To get a grasp of the image optimization You can experiment with two identical images:
- | - |
---|---|
x is not float | Nothing |
x < 0.0 | Nothing |
y is not float | Nothing |
y < 0.0 | Nothing |
w is not float | Nothing |
w <= 0.0 | Nothing |
h is not float | Nothing |
h <= 0.0 | Nothing |
h <= 0.0 | Nothing |
otherwise | crop={w},{h},x{x},y{y} |
If the rect
parameter is malformed, just ignore it.
- | - |
---|---|
x is not float | set x as 0.5 |
y is not float | set y as 0.5 |
z is not float | Nothing |
z <= 1.0 | Nothing |
1 / z < 1.0 | Nothing |
otherwise | crop={1 / z},{1 / z},offset-x{(x * z - 0.5) / (z - 1)},offset-y{(y * z - 0.5) / (z - 1) * 100} |
Both offset-x and offset-y must be clamped into range from 0 to 100.
imgix supports crop by both rectangle and focal point. Unfortunately, it is not so easy to calculate Fastly parameters. Therefore, let's declare the rect
parameter more important. So, if both crop by rectangle and focal point are specified, choose the first.
- | - |
---|---|
x = gif | format=gif |
x = png | format=png |
x = png8 | format=png8 |
x = jpg | format=jpg |
x = pjpg | format=pjpg |
x = webp | format=webp |
otherwise | Nothing |
- | - |
---|---|
x = 1 | format=webpll |
x = true | format=webpll |
x = 0 | format=webply |
x = false | format=webply |
otherwise | format=webp |
- | - |
---|---|
x is not float | Nothing |
otherwise | quality={x}\ |
- | - |
---|---|
x = format | auto=webp |
otherwise | Nothing |
Local variables and related functions will be required to transform parameters.
In coming weeks, the Delivery API will start supporting authenticated access.
In the first version of this feature, content will be secured using an API key. The developer will be able to turn the authenticated access on and off for the whole project. There will be one authentication key for the project, not multiple ones (for various user roles, for example).
Implement support for submitting the key in the form of the "Authorization" request header. The key should be sent via the Bearer scheme (with a "Bearer "
prefix).
We'll provide more information once they become available. https://kenticocloud.com/roadmap#secured-delivery-api
Add support for response defined here
As part of the DeliveryItemListingResponse object, the Pagination.NextPageUrl property provides a reference to getting the next page data.
The Delivery client (the "items" method) should be able to get the next page data, either using the NextPageUrl, or something more appropriate.
Add a capability of dealing with transient network outages via the following retry policy:
While working with the SDK, I found tedious to create translators for field names.
I would like to propose the following approach to resolve property names: Use Typescript Decorators to set the codename at the property level
export class Article extends ContentItem {
@codeName('teaser_image')
public teaserImage: Fields.AssetsField;
public title: Fields.TextField;
public summary: Fields.TextField;
constructor() {
super()
}
}
@codeName(ContentTypes.Article.fields.teaserImage)
I have started working on this here
It is currently working as is and would require some refactoring - I don't really like having to path the instance in the decorator.
What I did was to:
I believe the last one could be moved to the ContentItem class itself and therefore, we wouldn't to override propertyResolver method anymore.
Please, let me know what do you think.
Thanks.
RichTextField contained property links
in previous versions.
In the sample site for react code relied on that property. I have made a pull request with the workaround.
Consider implementing the property back (if so please raise the issue to revert the commit kontent-ai/sample-app-react@3cb71d2)
The get()
method of the SingleItemQuery<...>
and MultipleItemQuery<...>
returns an Observable<...>
.
I mean, ... how many times is the subscribed callback intended to be called?
I suppose the request is resolved once. That, I think, leaves Promise as a more suitable option especially in the light or the recently introduced async/await which is perfectly backwards compatible with Promises. Because they transpile to Promises basically.
Listing taxonomy groups supports pagination. We need to reflect that in the SDK.
{
"taxonomies": [
{
"system": {
"id": "f30c7f72-e9ab-8832-2a57-62944a038809",
"name": "Personas",
"codename": "personas",
"last_modified": "2016-10-20T13:24:00.3200182Z"
},
"terms": [
{
"name": "Coffee expert",
"codename": "coffee_expert",
"terms": [
{
"name": "Barista",
"codename": "barista",
"terms": []
},
{
"name": "Cafe owner",
"codename": "cafe_owner",
"terms": []
}
]
},
{
"name": "Coffee enthusiast",
"codename": "coffee_enthusiast",
"terms": [
{
"name": "Coffee lover",
"codename": "coffee_lover",
"terms": []
},
{
"name": "Coffee blogger",
"codename": "coffee_blogger",
"terms": []
}
]
}
]
},
{
"system": {
"id": "d351400e-0290-87b2-1413-6c411d8ae5a4",
"name": "Processing type",
"codename": "processing_type",
"last_modified": "2017-09-04T12:50:20.7857817Z"
},
"terms": [
{
"name": "Wet (Washed)",
"codename": "wet__washed_",
"terms": []
},
{
"name": "Dry (Natural)",
"codename": "dry__natural_",
"terms": []
},
{
"name": "Semi-dry",
"codename": "semi_dry",
"terms": []
}
]
},
{
"system": {
"id": "79b1c5b6-30bc-d076-a236-d9ec9f1ff01b",
"name": "Product status",
"codename": "product_status",
"last_modified": "2016-09-15T10:53:25.2233101Z"
},
"terms": [
{
"name": "On sale",
"codename": "on_sale",
"terms": []
},
{
"name": "Bestseller",
"codename": "bestseller",
"terms": []
}
]
}
],
"pagination": {
"skip": 0,
"limit": 3,
"count": 3,
"next_page": ""
}
}
I am working on a REST API developed with Nodejs and Express. Requirement is to read data from Kentico Cloud, execute some treatment on it and then returned the processed data.
I have setup a simple node server with express to deliver the content. I have set up my models as per the
KenticoCloudSampleJavascriptApp.
When executing the following code:
var config = new kc.DeliveryClientConfig(projectId, typeResolvers);
var deliveryClient = new kc.DeliveryClient(config);
deliveryClient.item('home')
.depthParameter(3)
.get()
.subscribe(response => res.json(response));
This exception is thrown:
Error: XMLHttpRequest is not supported by your browser
at getXMLHttpRequest (D:\_\sample-tool\node_modules\rxjs\observable\dom\AjaxObs
ervable.js:45:19)
at Object.createXHR (D:\_\sample-tool\node_modules\rxjs\observable\dom\AjaxObse
rvable.js:93:71)
at Object.tryCatcher (D:\_\sample-tool\node_modules\rxjs\util\tryCatch.js:6:31)
at AjaxSubscriber.send (D:\_\sample-tool\node_modules\rxjs\observable\dom\AjaxO
bservable.js:191:50)
at new AjaxSubscriber (D:\_\sample-tool\node_modules\rxjs\observable\dom\AjaxOb
servable.js:180:14)
at AjaxObservable._subscribe (D:\_\sample-tool\node_modules\rxjs\observable\dom
\AjaxObservable.js:115:16)
at AjaxObservable.Observable._trySubscribe (D:\_\sample-tool\node_modules\rxjs\
Observable.js:171:25)
at AjaxObservable.Observable.subscribe (D:\_\sample-tool\node_modules\rxjs\Obse
rvable.js:159:65)
at MapOperator.call (D:\_\sample-tool\node_modules\rxjs\operator\map.js:54:23)
at Observable.subscribe (D:\_\sample-tool\node_modules\rxjs\Observable.js:156:2
2)
The dependencies of the SDK require the code to work on a browser. It would be great to have the ability to work on a nodejs app.
And release 2 packages on npm -> Core & Delivery so that we can easily add new packages in future for Personalization, Content management...
Link objects in rich text field were part of the modular content response in the past, but now it has been replaced with something like this:
"body_copy": {
"type": "rich_text",
"name": "Body Copy",
"images": {},
"links": {
"80c7074b-3da1-4e1d-882b-c5716ebb4d25": {
"codename": "kenya_gakuyuni_aa",
"type": "coffee",
"url_slug": "kenya-gakuyuni-aa"
},
"0c9a11bb-6fc3-409c-b3cb-f0b797e15489": {
"codename": "brazil_natural_barra_grande",
"type": "coffee",
"url_slug": "brazil-natural-barra-grande"
}
},
IContentItem
should not have:
public elements: any;
But instead if should contain a collection of all mapped fields so that they can be easily looped through.
Create another SDK package, that allows using Content Management API in javascript.
Implementation should be as similar as possible with already implemented .net conent management sdk.
High-level feature set Implementation could be split:
Additional resources:
I have used delivery client to load content type definition.
I have needed to get all possible options from the multiple choice field.
I have used the code defined in:
https://github.com/Enngage/KenticoCloudDeliveryTypeScriptSDK#working-with-content-types
Response does not contain possible options to the multi choice field:
There is also no raw response that could be used to get the option values.
Note it would be also good to extend type calling by specifik what elements to load, but it does not block me :-)
https://developer.kenticocloud.com/v1/reference#view-a-content-type-element
We should organize imports (use e.g. TypeScript Hero) plugin
We are seeing a 'Critical dependency' warning being logged in console when building the app (i.e. react, angular..). We should resolve this in some way or use different html parser that works in all environments (node.js, browser...)
Issue raised with parse5 with no resolution so far
There is a new endpoint for retrieving taxonomy groups:
Docu: https://developer.kenticocloud.com/v1/reference#list-taxonomy-groups
.NET SDK: kontent-ai/delivery-sdk-net#72
Hi, as the title says, after migration to 4.2. webpack can't resolve kentico-cloud-delivery. Version 4.1 works properly.
As title suggest, we might want to enable querying for items of 'dynamic' types which do not have any class bound to it.
In trying to use this I got seriously annoyed by having to map all the properties from something like body_copy
to bodyCopy
manually for each type. I implemented a helper method to do this, and thought maybe this should be incorporated into the SDK... Thoughts? Here's my implementation: https://gist.github.com/ChristopherJennings/3086c7225f6b391ecca9feb6bf3affc4
@Enngage please agree with our documentation team that the link leading to the generator utility gets changed in the official docu. Ideally, create an issue in the CTC backlog.
We are trying to use the Kentico Typescript SDK in an Angular application.
Angular version: 5.2.0
Typescript version: 2.5.3
Kentico version: 2.3.3
The SDK works fine in local development mode and a normal Angular build. However if you try to run an AOT build it fails with a module reference error. I am not certain but this could be due to how the module is defined.
You can find a reproduction at this repo https://github.com/dewang/kentico-test.git. This is an absolutely basic app created using Angular CLI, with the addition of referencing the Kentico SDK.
Running ng build --aot
fails with the following error
ERROR in ./src/app/app.module.ngfactory.js
Module not found: Error: Can't resolve 'kentico-cloud-delivery-typescript-sdk/definitions/client/delivery-client' in '/home/code/src/kentico-test/src/app'
resolve 'kentico-cloud-delivery-typescript-sdk/definitions/client/delivery-client' in '/home/code/src/kentico-test/src/app'
Parsed request is a module
using description file: /home/code/src/kentico-test/package.json (relative path: ./src/app)
Field 'browser' doesn't contain a valid alias configuration
after using description file: /home/code/src/kentico-test/package.json (relative path: ./src/app)
resolve as module
/home/code/src/kentico-test/src/app/node_modules doesn't exist or is not a directory
/home/code/src/kentico-test/src/node_modules doesn't exist or is not a directory
/home/code/src/node_modules doesn't exist or is not a directory
/home/dewang/code/akoni/node_modules doesn't exist or is not a directory
/home/dewang/code/node_modules doesn't exist or is not a directory
/home/dewang/node_modules doesn't exist or is not a directory
/home/node_modules doesn't exist or is not a directory
/node_modules doesn't exist or is not a directory
looking for modules in /home/code/src/kentico-test/node_modules
using description file: /home/code/src/kentico-test/package.json (relative path: ./node_modules)
Field 'browser' doesn't contain a valid alias configuration
after using description file: /home/code/src/kentico-test/package.json (relative path: ./node_modules)
using description file: /home/code/src/kentico-test/node_modules/kentico-cloud-delivery-typescript-sdk/package.json (relative path: ./definitions/client/delivery-client)
no extension
Field 'browser' doesn't contain a valid alias configuration
/home/code/src/kentico-test/node_modules/kentico-cloud-delivery-typescript-sdk/definitions/client/delivery-client doesn't exist
.ts
Field 'browser' doesn't contain a valid alias configuration
/home/code/src/kentico-test/node_modules/kentico-cloud-delivery-typescript-sdk/definitions/client/delivery-client.ts doesn't exist
.js
Field 'browser' doesn't contain a valid alias configuration
/home/code/src/kentico-test/node_modules/kentico-cloud-delivery-typescript-sdk/definitions/client/delivery-client.js doesn't exist
as directory
/home/code/src/kentico-test/node_modules/kentico-cloud-delivery-typescript-sdk/definitions/client/delivery-client doesn't exist
We get a slightly different error in our actual app which does not use Angular CLI, but uses a custom Webpack 3 build.
This dependency was not found:
* kentico-cloud-delivery-typescript-sdk/definitions/client/delivery-client in ./src/app/app.module.ngfactory.js, ./src/app/modules/home/home.component.ngfactory.js and 1 other
However the base issue is that it cannot resolve the referenced classes from the module.
Seems like the type of field in Types response is string
. It should be mapped to FieldType
enum instead
I get the following error when trying to build an Angular 6 project which contains the delivery sdk.
ERROR in ./node_modules/kentico-cloud-delivery/node_modules/parse5/lib/parser/parser_stream.js
Module not found: Error: Can't resolve 'stream' in '/Users/martya/…/node_modules/parse5/lib/parser'
ERROR in ./node_modules/kentico-cloud-delivery/node_modules/parse5/lib/sax/index.js
Module not found: Error: Can't resolve 'stream' in '/Users/martya/…/node_modules/kentico-cloud-delivery/node_modules/parse5/lib/sax'
ERROR in ./node_modules/kentico-cloud-delivery/node_modules/parse5/lib/sax/dev_null_stream.js
Module not found: Error: Can't resolve 'stream' in '/Users/martya/…/node_modules/kentico-cloud-delivery/node_modules/parse5/lib/sax'
ERROR in ./node_modules/kentico-cloud-delivery/node_modules/parse5/lib/serializer/serializer_stream.js
Module not found: Error: Can't resolve 'stream' in '/Users/martya/…/node_modules/kentico-cloud-delivery/node_modules/parse5/lib/serializer'
In my research into the issue I noticed that @Enngage has lodged a ticket about this on the official angular project. It seems like it's an underlying issue with Angular, however it's worth lodging an issue here so other's can see what's going on.
The only workaround which I've found is to install the stream package separately via npm npm install stream
. This solves the issue for now but it would good if there's a better way.
Hi,
I want to get data from kentico cloud en filter it by a category with a ContainsFilter.
If i check the URL in the console.log than i get this URL:
https://deliver.kenticocloud.com/3e6bfb89-fc83-01fb-256c-7d3da2d9bd64/items?system.type=update&elements.updates[contains]=&depth=999
The tag 'marketing' is missing..
Validate possibilities for an automatic generation for changelog.md.
Mind that this is a monorep
repository. Provide the best practice to apply discovered approach for all the repositories (at least all our SDKs).
Am I missing something, or is there no way to specify how links in rich text fields will be resolved? I imagine it would be very similar to how modular content is resolved, but looking for a
tags with data-item-id
attributes and no href
attribute value.
It would be nice to have a base abstract service that users can easily inherit and have type service ready to be used without additional coding.
When I use the code from javascript penultimate code snippets from documentation:
https://developer.kenticocloud.com/docs/get-titles-and-images-of-5-latest-articles
const KenticoCloud = require('kentico-cloud-delivery-typescript-sdk');
class Article extends KenticoCloud.ContentItem {
constructor() {
super();
}
}
const config = new KenticoCloud.DeliveryClientConfig('975bf280-fd91-488c-994c-2f04416e5ee3',
[ new KenticoCloud.TypeResolver('article', () => new Article())
]);
const deliveryClient = new KenticoCloud.DeliveryClient(config);
deliveryClient.items()
.type('article')
.orderParameter('elements.post_date', KenticoCloud.SortOrder.desc)
.limitParameter(5)
.get()
.subscribe(response => console.log(response));
I got en error (thce the same):
dist/services/query.service.js:49 Error: Cannot map fields because item is not defined
at FieldMapService.mapFields (dist/services/field-map.service.js:32)
at dist/services/field-map.service.js:117
at Array.forEach (<anonymous>)
at FieldMapService.mapRichTextField (dist/services/field-map.service.js:115)
at FieldMapService.mapField (dist/services/field-map.service.js:93)
at dist/services/field-map.service.js:69
at Array.forEach (<anonymous>)
at FieldMapService.mapFields (dist/services/field-map.service.js:54)
at dist/services/field-map.service.js:182
at Array.forEach (<anonymous>)
It is because loaded article is using modular content in the field body_copy and the data for modular content are not in the returned data (default value of the depth parameter is 1).
Error is not clear about what really happens - I was force to debug the sdk to find the real cause. I am pretty OK with the error (maybe warning), but the message must me more specific.
Are we OK, that the code snippet in documentations leads to error, or we should add i.e. .depthParameter(2)
to the query specification to prevent the error?
I think it would be great if there was an indication of the project being buildable and of the % of code covered by automatic tests.
Would you consider setting up CI (e.g. Travis) + export code coverage (to codeclimate/codecov/coveralls..)
I came across several how-tos for TypeScript (most of them are mentioning istanbul and mocha), so it should be doable.
If you need some inspiration regarding yml files, look at the Kentico repos, e.g.:
Motivation:
We'd like to start sending a header for identifying SDKs + their versions with each request from all SDKs. The header would be then tracked by App Insights and should provide us with information valuable for multiple departments in Kentico. App Insights already gather information about the user agent, but that is not always usable or present (there are some screenshots below).
In the future, the tracking should help us:
Specification:
Send the following header with each request to the Kentico Cloud Delivery API.
Examples:
X-KC-SDKID: nuget.org;KenticoCloud.Delivery;4.12.0
X-KC-SDKID: packagist.org;kentico-cloud/delivery-sdk-php;0.9.1
X-KC-SDKID: maven.org;com.kenticocloud:delivery-sdk-java;1.0.5
X-KC-SDKID: npmjs.com;kentico-cloud-delivery-typescript-sdk;2.2.2
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.