[DISCUSSION] More options for the JavaScript SDK

I will be making some updates to the JavaScript SDK to attempt to increase its compatibility with other common web technologies. The current plan is to update the code generator templates to output code using ES6 standards, including ES6 module syntax, and then use rollup.js to publish the module in various transpiled versions (e.g. iife/self-executing function, commonJS, AMD, UMD).

I'm looking for feedback from the JavaScript community to see:

  • what JavaScript technologies you use (node, react, angular, etc.)
  • if you use the JS SDK today, do you have issues with it that you'd like to see addressed?
  • if you don't use it, what's stopping you?
  • Do you require ES5 compatible packages? Or can you use ES6?
2 Likes

I would really like to see multiple transpiled versions available for use depending on the targeted environment for the application (CommonJS for Node, AMD for the browser, etc). Something like that would make using the SDK a little nicer inside a framework like Ember, which provides its own AMD/RequireJS compliant library to load modules.

(As it stands currently, the SDK overwrites require on pages using Ember)

1 Like

I would also love to see multiple output formats!

In my own projects, I have bundled the distribution as follows. I have tested this distribution mechanism in a few tooling environments, but would love to hear if there are other formats or package.json fields that other toolchains use.

src/

  • src code using es6 modules and reasonably supported (Phase 3/4) features of JS

dist/

  • main.js
    • Transpiled, unminified, common.js module
    • mapped to main property in package.json
  • .js and .min.js
    • Transpiled UMD module
    • Includes any necessary polyfills to support minimum browser requirements
    • minified file includes hash in file name for caching and cache busting
    • src map included for minified files
    • mapped to browser property in package.json
  • main.mjs
    • transpiled but unminifed es6 module
    • useful for importing into es6 projects but without the need to transpile the src in the consuming project
    • mapped to jsnext:main in package.json
1 Like

Oooh - love this topic! Must confess I mentioned these in a recent post, but this is where they belong:

  • Would be great if the JS SDK worked inside the Web Workers that support XMLHttpRequest (Dedicated/Shared) to facilitate using a single WebSocket for an entire app, no matter then number of open tabs. Issues preventing use include authentication and XMLHttpRequest (I think due to it being neither a window nor nodejs).

  • Would love to see the web Push API supported so we could use Service Workers to surface "notifications" to which we have subscribed.

This sounds great (especially ES6 module option). I use Node, Webpack + Vue/React.

Would be nice to have hooks to request/response in the client for custom logging options.

For the work we do, we are pretty much exclusively using Node.

@kripette Can you expand on your needs for this? I'm thinking that these two options should cover most use cases already, but would like to hear if you have use cases this doesn't cover.

  1. The client.setDebugLog(func, int) function takes a function reference as the first parameter. Typically, you'd pass in console.log to have debug messages written to the console. However, you could just pass in your own function here and handle the debug traces in whatever way you like.
  2. The client.setReturnExtendedResponses(bool) function allows you to enable getting extended information back about the response. That code in ApiClient.js looks like this:
var data = (this.returnExtended === true || error) ? {
	status: response.status,
	statusText: response.statusText,
	headers: response.headers,
	body: response.body,
	text: response.text,
	error: error
} : response.body ? response.body : response.text;

Check out the new thread where you can give this a try:

I actually don't remember the specific use case I was thinking of when I wrote that. I agree with you, those options should be enough.

1 Like