Giter Club home page Giter Club logo

Comments (11)

Domitnator avatar Domitnator commented on July 3, 2024

Hi @Enngage ,

Funny, I actually wanted to contact you next week about some issues I have with implementing the kentico-js-sdk in a Nuxt environment. So i am glad you reached out to me.

I started this repo because i work a lot with Kentico(Cloud) and i am a great fan of Nuxtjs ánd to prevent to repetitive task of setting up the KenticoCloudDeliveryTypeScriptSDK.

Yesterday I found the issue which I was running into ( #3 ), the error is somewhat misleading but it is the rxjs which is causing that problem as Nuxt supports only promises (in it's default workflow). So client side calls can now be done!

I'm still having problems however getting the server-call to work. I keep getting the error:

"XMLHttpRequest is not supported by your browser"

image

Next week i will digg into it a bit more. But i am sure it has something to do with rxjs as well.

Nice to hear that you are refactoring the SDK. As for me, it would be great if rxjs would be optional (or an extension). I think for most of the projects promisses are sufficient enough.

Kind Regards,

Alfred

from kentico-kontent-nuxt-module.

Enngage avatar Enngage commented on July 3, 2024

Lucky coincidence :) I think I might able to point you to right direction with points you mentioned:

  1. The whole SDK is built on top of rxjs which I believe is superior to Promises so I don't think this is gonna change, but from a consumer point of view, it should't make a difference because Observable can be easily converted to a Promise (see rxjs docs) so you would be able to do something like:
let promise = deliveryClient.items().get().toPromise()

I'm in a middle of refactoring to rxjs 6 so the syntax will change a bit, but the general idea will be the same.

  1. The problem you have with XMLHttpRequest is because this class is implemented by browsers (Firefox, Google, Opera ...), but does not have any implementation in Node.js. There are other HTTP clients for node.js, but they work quite differently so any code that needs to make HTTP requests need to use different libraries based on the environment. Previously, I had support for both node.js and browser in the same SDK, but that turned out to be a bad idea beacuse bundling such libraries (i.e. via webpack for production) will fail because you can't for example bundle node.js code for use in browser - browser doesn't know about the classes and will throw exceptions (and vice versa)

Thats why I separated the code into KenticoCloudDeliveryNodeSDK. This library depends on the main one and only implements HTTP service, but its not up to date yet (I will bump this up with the release of the new version).

Though, I'm not sure why you downgraded the library as the above was not changed in v3, only the build process was.

from kentico-kontent-nuxt-module.

Domitnator avatar Domitnator commented on July 3, 2024
  1. Yes, the toPromise method works fine! So yesterday i updated the readme.md and i also upgraded the kentico-cloud-delivery-typescript-sdk package to version 3.1.0 again.

  2. I also did a quick test to see if i could do a server-side-call with the kentico-cloud-delivery-node-sdk in my nuxt test application and that works too! So in theory i could add another global plugin ($deliveryNodeClient for instance) but then the user has to be aware of using $deliveryNodeClient server-side and $deliveryClient client-side. I guess this can be confusing at first and is error-prone. Take Axios for instance. It is always $axios to do a http-call, no matter if you are client or server side.

I have to think about this some more. Maybe i can come up with another solution, i know there are ways to detect if the call is done server or client side within nuxt so maybe that could help me out (by using a factory for instance).

from kentico-kontent-nuxt-module.

Enngage avatar Enngage commented on July 3, 2024

Awesome :) I totally forgot you can get promise just by calling getPromise method that I've prepared in the past:

let promise = deliveryClient.items().getPromise()

In v4 I've changed this so you either call getObservable or getPromise.

I actually didn't know about Axios. I've been researching http clients and finally decided to go with xhr in v4 (as a substite for rxdom). I think I'll have to rethink this because the Axios looks really good and my tests seems to be working with it perfectly fine.

One thing that I'll have to test is how it bundles up with WebPack and if there are any dynamic includes or anything that would break AOT builds.

It would be awesome to have the library working both in node and browser and this could solve one part of the issue, the other is HTML parser. There currently isn't any node.js/browser parser apart from Parse5 which I wan't to get rid of..

Anyway - maybe wait with the server side NUXT client a bit.

from kentico-kontent-nuxt-module.

Enngage avatar Enngage commented on July 3, 2024

Turns out the Axios is pretty good and I'll be using that for the library. Seems like I will deprecate the node client afterall.

If you want to test it, try installing beta version 4.0.0-beta.5 which should now work in both browser & node. Note that there are some API changes, which should be fixed in docs - https://github.com/Enngage/KenticoCloudDeliveryTypeScriptSDK/tree/major-version-node-js-support

from kentico-kontent-nuxt-module.

Domitnator avatar Domitnator commented on July 3, 2024

@Enngage : Cool, thanks for the update! Axios FTW!

I have little time this week but hopefully I find some time to check it out. I'll keep you posted!

from kentico-kontent-nuxt-module.

Domitnator avatar Domitnator commented on July 3, 2024

I just did a quick test to see if it works but i am getting an error:

I am running this piece of code:

this.$deliveryClient
    .items()
    .type('page')
    .getPromise()
    .then(response => console.log('DeliveryClient Response', response));

But that is giving me this error:

image

image

Do you have any clue what is going wrong?

from kentico-kontent-nuxt-module.

Enngage avatar Enngage commented on July 3, 2024

from kentico-kontent-nuxt-module.

Domitnator avatar Domitnator commented on July 3, 2024

Great, it works now!! I actually got a warning for installing rxjs but ignored it because i was in a hurry.

I will release a new version this afternoon so we can do some more testing internally! But this sure looks promising!

Any roadmap for releasing this (major-version-node-js-support) branch/version as a production version?

from kentico-kontent-nuxt-module.

Enngage avatar Enngage commented on July 3, 2024

from kentico-kontent-nuxt-module.

Domitnator avatar Domitnator commented on July 3, 2024

Closed this issue because the new Kentico Cloud Delivery SDK is implemented!

from kentico-kontent-nuxt-module.

Related Issues (18)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.