npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

cdsclient-lib

v0.0.2

Published

Api library for cloudisense react client

Downloads

149

Readme

Cloudisense API Library

About

This library provides a convenient way to access the Cloudisense backend services. It encapsulates communication mechanisms for Cloudisense's REST API and Real-time Communication API.

This library is intended for use with the Cloudisense frontend React project.


Usage

The following code snippet from a React-Redux project demonstrates how to establish a connection to the service from a client.

Main Authentication Function

    var password_hash = sha256.create();
    password_hash.update(password);
    password_hash.hex();

    var bodyFormData = new FormData();
    bodyFormData.append('username', username);
    bodyFormData.append('password', password_hash.hex());

    axios({
        method: "post",
        url: "http://localhost:8000/authorize",
        data: bodyFormData,
        headers: { "Content-Type": "multipart/form-data" },
    })
    .then((response) => {

        if (response.data) {
            if (response.data.status == "success" && response.data.code == 200) {
                if (rememberUser) {
                    localStorage.setItem(LAST_USER_KEY, username)
                } else {
                    localStorage.removeItem(LAST_USER_KEY)
                }

                const authData = response.data.data;
                localStorage.setItem(AUTH_DATA_KEY, JSON.stringify(authData))
                initializeSocketClient(dispatch, authData).then((client) => {
                    client.connectWithAuthData(authData).then(() => {
                        connection_ready_timeout = setTimeout(() => {
                            on_connection_state_complete(client, dispatch)
                        }, 2000);

                    }).catch((err) => {
                        console.log(err)
                        dispatch(authFail(err))
                    })
                })
                    .catch((error) => {
                        console.log("error initializing socket client")
                        dispatch(authFail("error initializing socket client"))
                    });
            }
            else {
                dispatch(authFail(response.data.data));
            }
        }
        else {
            dispatch(authFail("Unknown Error"));
        }
    })
    .catch((error) => {
        dispatch(authFail(error.message));
    });

The initializeSocketClient Function

const initializeSocketClient = (dispatch, data) => {

    return new Promise(function (resolve, reject) {

        const client = new cloudisenseApiClient({
            host: "localhost",
            port: 8000,
            reconnectOnFailure: false,
            authdata: plainToInstance(AuthData, data)
        });


        client.onTextNotification.subscribe((evt) => {
            switch (evt.type) {
                case EventType.DATANOTIFICATION:
                case EventType.NOTIFICATION:
                    dispatch(notificationReceived(evt))
                    break;
            }
        });


        client.onUIEvent.subscribe((evt) => {
            switch (evt.topic) {
                case TOPIC_UI_INITIALIZATION:
                    subscribe_to_ui_updates(client, dispatch)
                        .then((result) => {
                            dispatch(uiUpdatesSubscribeSuccess(result))
                            on_connection_state_complete(client, dispatch, evt.data);
                        })
                        .catch((err) => {
                            dispatch(uiUpdatesSubscribeFailed(err))
                        });
                    break;
            }
        });



        client.onClientStateUpdate.subscribe((stateObj) => {
            switch (stateObj.state) {
                case ClientStateType.CONNECTING:
                    console.debug("Connecting")
                    break;

                case ClientStateType.CONNECTED:
                    console.debug("Connected")
                    dispatch(connectSuccess())
                    break;

                case ClientStateType.CONNECTION_LOST:
                    dispatch(connectLoss("Connection lost"))
                    break;

                case ClientStateType.CONNECTION_TERMINATED:
                    console.debug("Disconnected")
                    dispatch(authLogout())
                    break;

                case ClientStateType.EVENT_RECEIVED:
                    console.debug("Event received")
                    break;

                case ClientStateType.CONNECTION_ERROR:
                    console.error("Connection error")
                    break;
            }

        });

        resolve(client);
    });
}

Build


  1. Simple compile - Generate output files
    npm run build
  1. Compile (Platform specific)

Linux

    npm run build_linux

Windows

    npm run build_win
  1. Distribute compiled files for linux to react client project

When building alongside Cloudisense main project folder

Linux

    TO DO

Windows

    TO DO
  1. NPM

The library is hosted on NPM @ https://www.npmjs.com/package/cdsclient-lib