Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

quiq-chat

Package Overview
Dependencies
Maintainers
1
Versions
152
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

quiq-chat - npm Package Compare versions

Comparing version 1.9.0 to 1.10.0

src/storage.js

101

build/quiq-chat.js

@@ -10,2 +10,4 @@ 'use strict';

var lodash = require('lodash');
var store = _interopDefault(require('store/dist/store.modern.min'));
var expirePlugin = _interopDefault(require('store/plugins/expire'));
var jsCookie = require('js-cookie');

@@ -134,27 +136,58 @@ var atmosphere = _interopDefault(require('atmosphere.js'));

//
var setQuiqChatContainerVisibleCookie = function setQuiqChatContainerVisibleCookie(visible) {
jsCookie.set('quiq-chat-container-visible', visible, { expires: 1 });
store.addPlugin(expirePlugin);
var expireInDays = function expireInDays(numberOfDays) {
return new Date().getTime() + numberOfDays * 1000 * 60 * 60 * 24;
};
var setQuiqUserTakenMeaningfulActionCookie = function setQuiqUserTakenMeaningfulActionCookie(visible) {
jsCookie.set('quiq-user-taken-meaningful-action', visible, { expires: 1 });
var setQuiqChatContainerVisible = function setQuiqChatContainerVisible(visible) {
store.set('quiq-chat-container-visible', visible, expireInDays(1));
};
var setQuiqUserTakenMeaningfulAction = function setQuiqUserTakenMeaningfulAction(visible) {
store.set('quiq-user-taken-meaningful-action', visible, expireInDays(1));
};
var setAccessToken = function setAccessToken(token) {
jsCookie.set('X-Quiq-Access-Token', token, { expires: 365 });
store.set('X-Quiq-Access-Token', token, expireInDays(365));
};
var getQuiqChatContainerVisibleCookie = function getQuiqChatContainerVisibleCookie() {
return jsCookie.get('quiq-chat-container-visible') === 'true';
var getQuiqChatContainerVisible = function getQuiqChatContainerVisible() {
return store.get('quiq-chat-container-visible') === true;
};
var getQuiqUserTakenMeaningfulActionCookie = function getQuiqUserTakenMeaningfulActionCookie() {
return jsCookie.get('quiq-user-taken-meaningful-action') === 'true';
var getQuiqUserTakenMeaningfulAction = function getQuiqUserTakenMeaningfulAction() {
return store.get('quiq-user-taken-meaningful-action') === true;
};
var getAccessToken = function getAccessToken() {
return jsCookie.get('X-Quiq-Access-Token');
return store.get('X-Quiq-Access-Token');
};
var cookiesEnabled = function cookiesEnabled() {
jsCookie.set('quiq-cookies-enabled', 'true', 1);
return jsCookie.get('quiq-cookies-enabled') === 'true';
var isStorageEnabled = function isStorageEnabled() {
return store.enabled;
};
var persistentStorageEnabled = void 0;
var isPersistentStorageEnabled = function isPersistentStorageEnabled() {
if (typeof persistentStorageEnabled !== 'undefined') return persistentStorageEnabled;
var cookiesEnabled = function cookiesEnabled() {
jsCookie.set('quiq-storage-test', 'true', 1);
var areCookiesEnabled = jsCookie.get('quiq-storage-test') === 'true';
jsCookie.remove('quiq-storage-test');
return areCookiesEnabled;
};
var localStorageEnabled = function localStorageEnabled() {
try {
localStorage.setItem('quiq-storage-test', 'enabled?');
localStorage.removeItem('quiq-storage-test');
} catch (e) {
return false;
}
return true;
};
persistentStorageEnabled = cookiesEnabled() || localStorageEnabled();
return persistentStorageEnabled;
};
//

@@ -269,10 +302,2 @@ var callbacks = {};

if (!timedOut && retryCount < 4) {
if (url.includes('/session/web/generate') && req.method && req.method.toUpperCase() === 'POST') {
if (callbacks.onError) {
callbacks.onError();
}
return reject();
}
if (callbacks.onRetryableError) {

@@ -283,3 +308,3 @@ callbacks.onRetryableError();

retryCount++;
return login().then(validateSession).then(request);
return request();
}

@@ -302,3 +327,3 @@

var version = "1.9.0";
var version = "1.10.0";

@@ -313,4 +338,4 @@ //

if (!cookiesEnabled()) {
return Promise.reject('Cookies are not enabled, aborting call');
if (!isStorageEnabled()) {
return Promise.reject('Store is not enabled, aborting call');
}

@@ -554,3 +579,3 @@

if (data && data.type && (data.type === 'Register' || data.type === 'Text')) {
setQuiqUserTakenMeaningfulActionCookie(true);
setQuiqUserTakenMeaningfulAction(true);

@@ -808,3 +833,3 @@ if (data.type === 'Register' && callbacks$1.onRegistration) {

this.joinChat = function () {
setQuiqChatContainerVisibleCookie(true);
setQuiqChatContainerVisible(true);

@@ -815,3 +840,3 @@ return joinChat$1();

this.leaveChat = function () {
setQuiqChatContainerVisibleCookie(false);
setQuiqChatContainerVisible(false);
return leaveChat$1();

@@ -821,4 +846,4 @@ };

this.sendMessage = function (text) {
setQuiqChatContainerVisibleCookie(true);
setQuiqUserTakenMeaningfulActionCookie(true);
setQuiqChatContainerVisible(true);
setQuiqUserTakenMeaningfulAction(true);
return addMessage$1(text);

@@ -832,4 +857,4 @@ };

this.sendRegistration = function (fields) {
setQuiqChatContainerVisibleCookie(true);
setQuiqUserTakenMeaningfulActionCookie(true);
setQuiqChatContainerVisible(true);
setQuiqUserTakenMeaningfulAction(true);
return sendRegistration$1(fields);

@@ -842,12 +867,16 @@ };

this.areCookiesEnabled = function () {
return cookiesEnabled();
this.isStorageEnabled = function () {
return isStorageEnabled();
};
this.isPersistentStorageEnabled = function () {
return isPersistentStorageEnabled();
};
this.isChatVisible = function () {
return getQuiqChatContainerVisibleCookie();
return getQuiqChatContainerVisible();
};
this.hasTakenMeaningfulAction = function () {
return getQuiqUserTakenMeaningfulActionCookie();
return getQuiqUserTakenMeaningfulAction();
};

@@ -854,0 +883,0 @@

{
"name": "quiq-chat",
"version": "1.9.0",
"version": "1.10.0",
"description": "Library to help with network requests to create a webchat client for Quiq Messaging",

@@ -24,6 +24,11 @@ "main": "build/quiq-chat.js",

"jest": {
"modulePaths": ["src", "node_modules"],
"modulePaths": [
"src",
"node_modules"
],
"rootDir": "src"
},
"keywords": ["quiq"],
"keywords": [
"quiq"
],
"author": "nate.norberg@goquiq.com",

@@ -36,2 +41,3 @@ "license": "MIT",

"lodash": "4.17.4",
"store": "2.0.12",
"ua-parser-js": "0.7.12"

@@ -38,0 +44,0 @@ },

@@ -187,10 +187,16 @@ # quiq-chat [![Build Status](https://travis-ci.org/Quiq/quiq-chat.svg?branch=master)](https://travis-ci.org/Quiq/quiq-chat) [![npm version](https://badge.fury.io/js/quiq-chat.svg)](https://badge.fury.io/js/quiq-chat) [![styled with prettier](https://img.shields.io/badge/styled_with-prettier-ff69b4.svg)](https://github.com/prettier/prettier)

#### areCookiesEnabled() => boolean
Utility method to determine if cookies are enabled on the client's browser. If cookies are not enabled, the
quiq-chat library will not function properly.
#### isStorageEnabled = () => boolean
Utility function to tell the client if quiq-chat has the capability to set its required data.
Note this will return true if quiq-chat is able to set its required data in any way,
whether persistent or not. This means the session may not persist through page flips.
If this is false, quiq-chat will block all API calls.
#### isPersistentStorageEnabled = () => boolean
Utility function to tell the client if quiq-chat has the capability to set its required data in a
persistent way. If this returns true, it means its safe to assume session data will
persist through page flips.
#### hasTakenMeaningfulAction() => boolean
Returns whether the end-user has performed a meaningful action, such as
submitting the Welcome Form, or sending a message to the agent. State persists through
page flips using `quiq-user-taken-meaningful-action` cookie.
submitting the Welcome Form, or sending a message to the agent.

@@ -200,4 +206,3 @@ #### isChatVisible() => boolean

For instance, if your user maximizes chat, but you never call joinChat, isChatVisible won't reflect this change.
State persists through page flips using `quiq-chat-container-visible` cookie. Can be used to re-open webchat on page
turns if the user had chat previously open. Defaults to false if user has taken no actions.
Can be used to re-open webchat on page turns if the user had chat previously open. Defaults to false if user has taken no actions.

@@ -204,0 +209,0 @@ ## Data types

// @flow
jest.mock('../apiCalls');
jest.mock('../websockets');
jest.mock('../cookies');
jest.mock('js-cookie');
jest.mock('../storage');
jest.mock('store');
import QuiqChatClient from '../QuiqChatClient';
import * as ApiCalls from '../apiCalls';
import * as cookies from '../cookies';
import * as storage from '../storage';
import {connectSocket, disconnectSocket} from '../websockets';
import {set} from 'js-cookie';
import {set} from 'store';

@@ -48,3 +48,3 @@ const initialConvo = {

let client: QuiqChatClient;
const mockCookies = (cookies: any);
const mockStore = (storage: any);

@@ -54,4 +54,4 @@ beforeEach(() => {

API.fetchWebsocketInfo.mockReturnValue({url: 'https://websocket.test'});
mockCookies.getQuiqChatContainerVisibleCookie.mockReturnValue(true);
mockCookies.getQuiqUserTakenMeaningfulActionCookie.mockReturnValue(true);
mockStore.getQuiqChatContainerVisible.mockReturnValue(true);
mockStore.getQuiqUserTakenMeaningfulAction.mockReturnValue(true);

@@ -375,9 +375,9 @@ client = new QuiqChatClient(host, contactPoint)

it('sets the quiq-chat-container-visible cookie to true', () => {
expect(mockCookies.setQuiqChatContainerVisibleCookie).toBeCalledWith(true);
it('sets the quiq-chat-container-visible value to true', () => {
expect(mockStore.setQuiqChatContainerVisible).toBeCalledWith(true);
});
});
describe('areCookiesEnabled', () => {
it('returns the value of the quiq-chat-container-visible cookie value', () => {
describe('isStorageEnabled', () => {
it('returns the value of the quiq-chat-container-visible', () => {
if (!client) {

@@ -387,4 +387,4 @@ throw new Error('Client undefined');

mockCookies.cookiesEnabled.mockReturnValueOnce(false);
expect(client.areCookiesEnabled()).toBe(false);
mockStore.isStorageEnabled.mockReturnValueOnce(false);
expect(client.isStorageEnabled()).toBe(false);
});

@@ -394,3 +394,3 @@ });

describe('isChatVisible', () => {
it('returns the value of the quiq-chat-container-visible cookie value', () => {
it('returns the value of the quiq-chat-container-visible value value', () => {
if (!client) {

@@ -400,3 +400,3 @@ throw new Error('Client undefined');

mockCookies.getQuiqChatContainerVisibleCookie.mockReturnValueOnce(false);
mockStore.getQuiqChatContainerVisible.mockReturnValueOnce(false);
expect(client.isChatVisible()).toBe(false);

@@ -413,3 +413,3 @@ });

it('returns the value of the quiq-user-taken-meaningful-action cookie value', () => {
it('returns the value of the quiq-user-taken-meaningful-action value value', () => {
if (!client) {

@@ -419,3 +419,3 @@ throw new Error('Client undefined');

mockCookies.getQuiqUserTakenMeaningfulActionCookie.mockReturnValueOnce(false);
mockStore.getQuiqUserTakenMeaningfulAction.mockReturnValueOnce(false);
expect(client.hasTakenMeaningfulAction()).toBe(false);

@@ -438,4 +438,4 @@ });

it('sets the quiq-chat-container-visible cookie to false', () => {
expect(mockCookies.setQuiqChatContainerVisibleCookie).toBeCalledWith(false);
it('sets the quiq-chat-container-visible value to false', () => {
expect(mockStore.setQuiqChatContainerVisible).toBeCalledWith(false);
});

@@ -452,4 +452,4 @@ });

expect(API.addMessage).toBeCalledWith('text');
expect(mockCookies.setQuiqChatContainerVisibleCookie).toBeCalledWith(true);
expect(mockCookies.setQuiqUserTakenMeaningfulActionCookie).toBeCalledWith(true);
expect(mockStore.setQuiqChatContainerVisible).toBeCalledWith(true);
expect(mockStore.setQuiqUserTakenMeaningfulAction).toBeCalledWith(true);
});

@@ -478,4 +478,4 @@ });

expect(API.sendRegistration).toBeCalledWith(data);
expect(mockCookies.setQuiqChatContainerVisibleCookie).toBeCalledWith(true);
expect(mockCookies.setQuiqUserTakenMeaningfulActionCookie).toBeCalledWith(true);
expect(mockStore.setQuiqChatContainerVisible).toBeCalledWith(true);
expect(mockStore.setQuiqUserTakenMeaningfulAction).toBeCalledWith(true);
});

@@ -482,0 +482,0 @@ });

// @flow
jest.mock('atmosphere.js');
jest.mock('../utils');
jest.mock('../cookies.js');
jest.mock('../storage.js');
import * as Websockets from '../websockets';
import * as Utils from '../utils';
import atmosphere from 'atmosphere.js';
import {setQuiqUserTakenMeaningfulActionCookie} from '../cookies';
import {setQuiqUserTakenMeaningfulAction} from '../storage';

@@ -90,3 +90,3 @@ describe('Websockets', () => {

describe('ChatMessage', () => {
it('sets cookie', () => {
it('sets storage', () => {
message.messageType = 'ChatMessage';

@@ -99,3 +99,3 @@ message.data = {

});
expect(setQuiqUserTakenMeaningfulActionCookie).toBeCalled();
expect(setQuiqUserTakenMeaningfulAction).toBeCalled();
});

@@ -111,3 +111,3 @@

});
expect(setQuiqUserTakenMeaningfulActionCookie).toBeCalled();
expect(setQuiqUserTakenMeaningfulAction).toBeCalled();
expect(callbacks.onRegistration).toBeCalled();

@@ -114,0 +114,0 @@ });

@@ -11,3 +11,3 @@ // @flow

import quiqFetch from './quiqFetch';
import {setAccessToken} from './cookies';
import {setAccessToken} from './storage';
import type {Conversation} from 'types';

@@ -14,0 +14,0 @@

@@ -11,3 +11,3 @@ // @flow

import type {QuiqChatCallbacks} from 'types';
import * as cookies from './cookies';
import * as storage from './storage';

@@ -67,3 +67,3 @@ const getConversation = async (): Promise<{events: Array<Event>, messages: Array<TextMessage>}> => {

/** Fluent client builder functions: these all return the client object **/
/** Fluent client builder functions: these all return the client object * */

@@ -169,6 +169,6 @@ onNewMessages = (callback: (messages: Array<TextMessage>) => void): QuiqChatClient => {

/** API wrappers: these return Promises around the API response **/
/** API wrappers: these return Promises around the API response * */
joinChat = () => {
cookies.setQuiqChatContainerVisibleCookie(true);
storage.setQuiqChatContainerVisible(true);

@@ -179,3 +179,3 @@ return API.joinChat();

leaveChat = () => {
cookies.setQuiqChatContainerVisibleCookie(false);
storage.setQuiqChatContainerVisible(false);
return API.leaveChat();

@@ -185,4 +185,4 @@ };

sendMessage = (text: string) => {
cookies.setQuiqChatContainerVisibleCookie(true);
cookies.setQuiqUserTakenMeaningfulActionCookie(true);
storage.setQuiqChatContainerVisible(true);
storage.setQuiqUserTakenMeaningfulAction(true);
return API.addMessage(text);

@@ -196,4 +196,4 @@ };

sendRegistration = (fields: {[string]: string}) => {
cookies.setQuiqChatContainerVisibleCookie(true);
cookies.setQuiqUserTakenMeaningfulActionCookie(true);
storage.setQuiqChatContainerVisible(true);
storage.setQuiqUserTakenMeaningfulAction(true);
return API.sendRegistration(fields);

@@ -206,5 +206,6 @@ };

areCookiesEnabled = () => cookies.cookiesEnabled();
isChatVisible = (): boolean => cookies.getQuiqChatContainerVisibleCookie();
hasTakenMeaningfulAction = (): boolean => cookies.getQuiqUserTakenMeaningfulActionCookie();
isStorageEnabled = () => storage.isStorageEnabled();
isPersistentStorageEnabled = () => storage.isPersistentStorageEnabled();
isChatVisible = (): boolean => storage.getQuiqChatContainerVisible();
hasTakenMeaningfulAction = (): boolean => storage.getQuiqUserTakenMeaningfulAction();

@@ -227,3 +228,3 @@ getLastUserEvent = async (cache: boolean = true): Promise<UserEventTypes | null> => {

/** Private Members **/
/** Private Members * */
_connectSocket = (wsInfo: {url: string}) => {

@@ -230,0 +231,0 @@ connectSocket({

// @flow
import stubbornFetch from './stubbornFetch';
import {checkRequiredSettings} from './globals';
import {cookiesEnabled} from './cookies';
import {isStorageEnabled} from './storage';
import {merge} from 'lodash';

@@ -21,4 +21,4 @@ import {version} from '../package.json';

) => {
if (!cookiesEnabled()) {
return Promise.reject('Cookies are not enabled, aborting call');
if (!isStorageEnabled()) {
return Promise.reject('Store is not enabled, aborting call');
}

@@ -25,0 +25,0 @@

@@ -7,3 +7,3 @@ // @flow

import {getBurned} from './globals';
import {getAccessToken} from './cookies';
import {getAccessToken} from './storage';
import type {ApiError, IsomorphicFetchNetworkError} from 'types';

@@ -126,14 +126,2 @@

if (!timedOut && retryCount < 4) {
if (
url.includes('/session/web/generate') &&
req.method &&
req.method.toUpperCase() === 'POST'
) {
if (callbacks.onError) {
callbacks.onError();
}
return reject();
}
if (callbacks.onRetryableError) {

@@ -144,3 +132,3 @@ callbacks.onRetryableError();

retryCount++;
return login().then(validateSession).then(request);
return request();
}

@@ -147,0 +135,0 @@

@@ -5,3 +5,3 @@ // @flow

import {isIE9, burnItDown} from './utils';
import * as cookies from './cookies';
import * as storage from './storage';
import type {

@@ -29,5 +29,5 @@ AtmosphereRequest,

};
if (cookies.getAccessToken()) {
if (storage.getAccessToken()) {
headers = {
'X-Quiq-Access-Token': cookies.getAccessToken(),
'X-Quiq-Access-Token': storage.getAccessToken(),
'X-Quiq-Line': '1',

@@ -119,3 +119,3 @@ };

if (data && data.type && (data.type === 'Register' || data.type === 'Text')) {
cookies.setQuiqUserTakenMeaningfulActionCookie(true);
storage.setQuiqUserTakenMeaningfulAction(true);

@@ -122,0 +122,0 @@ if (data.type === 'Register' && callbacks.onRegistration) {

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc