quiq-chat
Advanced tools
Comparing version 1.6.1 to 1.7.1
@@ -258,3 +258,3 @@ 'use strict'; | ||
var version = "1.6.1"; | ||
var version = "1.7.1"; | ||
@@ -502,4 +502,4 @@ // | ||
}; | ||
var setQuiqLauncherVisibleCookie = function setQuiqLauncherVisibleCookie(visible) { | ||
jsCookie.set('quiq-chat-launcher-visible', visible, { expires: 1 }); | ||
var setQuiqUserTakenMeaningfulActionCookie = function setQuiqUserTakenMeaningfulActionCookie(visible) { | ||
jsCookie.set('quiq-user-taken-meaningful-action', visible, { expires: 1 }); | ||
}; | ||
@@ -510,4 +510,4 @@ | ||
}; | ||
var getQuiqLauncherVisibleCookie = function getQuiqLauncherVisibleCookie() { | ||
return jsCookie.get('quiq-chat-launcher-visible') === 'true'; | ||
var getQuiqUserTakenMeaningfulActionCookie = function getQuiqUserTakenMeaningfulActionCookie() { | ||
return jsCookie.get('quiq-user-taken-meaningful-action') === 'true'; | ||
}; | ||
@@ -722,3 +722,3 @@ | ||
setQuiqChatContainerVisibleCookie(true); | ||
setQuiqLauncherVisibleCookie(true); | ||
setQuiqUserTakenMeaningfulActionCookie(true); | ||
return addMessage$1(text); | ||
@@ -733,3 +733,3 @@ }; | ||
setQuiqChatContainerVisibleCookie(true); | ||
setQuiqLauncherVisibleCookie(true); | ||
setQuiqUserTakenMeaningfulActionCookie(true); | ||
return sendRegistration$1(fields); | ||
@@ -746,59 +746,28 @@ }; | ||
this.hasActiveChat = _asyncToGenerator$1(regeneratorRuntime.mark(function _callee4() { | ||
return regeneratorRuntime.wrap(function _callee4$(_context4) { | ||
while (1) { | ||
switch (_context4.prev = _context4.next) { | ||
case 0: | ||
if (getQuiqLauncherVisibleCookie()) { | ||
_context4.next = 2; | ||
break; | ||
} | ||
this.hasTakenMeaningfulAction = function () { | ||
return getQuiqUserTakenMeaningfulActionCookie(); | ||
}; | ||
return _context4.abrupt('return', false); | ||
case 2: | ||
if (!(_this2.textMessages.length > 0)) { | ||
_context4.next = 4; | ||
break; | ||
} | ||
return _context4.abrupt('return', true); | ||
case 4: | ||
_context4.next = 6; | ||
return _this2.getMessages(); | ||
case 6: | ||
return _context4.abrupt('return', _this2.textMessages.length > 0); | ||
case 7: | ||
case 'end': | ||
return _context4.stop(); | ||
} | ||
} | ||
}, _callee4, _this2); | ||
})); | ||
this.getLastUserEvent = function () { | ||
var _ref7 = _asyncToGenerator$1(regeneratorRuntime.mark(function _callee5() { | ||
var _ref6 = _asyncToGenerator$1(regeneratorRuntime.mark(function _callee4() { | ||
var cache = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true; | ||
var _ref8, messages, events, lastStatusMessage; | ||
var _ref7, messages, events, lastStatusMessage; | ||
return regeneratorRuntime.wrap(function _callee5$(_context5) { | ||
return regeneratorRuntime.wrap(function _callee4$(_context4) { | ||
while (1) { | ||
switch (_context5.prev = _context5.next) { | ||
switch (_context4.prev = _context4.next) { | ||
case 0: | ||
if (!(!cache || !_this2.connected)) { | ||
_context5.next = 7; | ||
_context4.next = 7; | ||
break; | ||
} | ||
_context5.next = 3; | ||
_context4.next = 3; | ||
return getConversation(); | ||
case 3: | ||
_ref8 = _context5.sent; | ||
messages = _ref8.messages; | ||
events = _ref8.events; | ||
_ref7 = _context4.sent; | ||
messages = _ref7.messages; | ||
events = _ref7.events; | ||
@@ -811,14 +780,14 @@ _this2._processNewMessagesAndEvents(messages, events); | ||
})); | ||
return _context5.abrupt('return', lastStatusMessage ? lastStatusMessage.type : null); | ||
return _context4.abrupt('return', lastStatusMessage ? lastStatusMessage.type : null); | ||
case 9: | ||
case 'end': | ||
return _context5.stop(); | ||
return _context4.stop(); | ||
} | ||
} | ||
}, _callee5, _this2); | ||
}, _callee4, _this2); | ||
})); | ||
return function () { | ||
return _ref7.apply(this, arguments); | ||
return _ref6.apply(this, arguments); | ||
}; | ||
@@ -872,16 +841,16 @@ }(); | ||
this._handleConnectionEstablish = _asyncToGenerator$1(regeneratorRuntime.mark(function _callee6() { | ||
var _ref10, messages, events; | ||
this._handleConnectionEstablish = _asyncToGenerator$1(regeneratorRuntime.mark(function _callee5() { | ||
var _ref9, messages, events; | ||
return regeneratorRuntime.wrap(function _callee6$(_context6) { | ||
return regeneratorRuntime.wrap(function _callee5$(_context5) { | ||
while (1) { | ||
switch (_context6.prev = _context6.next) { | ||
switch (_context5.prev = _context5.next) { | ||
case 0: | ||
_context6.next = 2; | ||
_context5.next = 2; | ||
return getConversation(); | ||
case 2: | ||
_ref10 = _context6.sent; | ||
messages = _ref10.messages; | ||
events = _ref10.events; | ||
_ref9 = _context5.sent; | ||
messages = _ref9.messages; | ||
events = _ref9.events; | ||
@@ -899,6 +868,6 @@ | ||
case 'end': | ||
return _context6.stop(); | ||
return _context5.stop(); | ||
} | ||
} | ||
}, _callee6, _this2); | ||
}, _callee5, _this2); | ||
})); | ||
@@ -905,0 +874,0 @@ |
{ | ||
"name": "quiq-chat", | ||
"version": "1.6.1", | ||
"version": "1.7.1", | ||
"description": "Library to help with network requests to create a webchat client for Quiq Messaging", | ||
@@ -5,0 +5,0 @@ "main": "build/quiq-chat.js", |
@@ -181,6 +181,6 @@ # 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) | ||
#### hasActiveChat() => boolean | ||
Returns whether the end-user has performed a meaningful action that triggers a conversation, such as | ||
#### 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-chat-launcher-visible` cookie. | ||
page flips using `quiq-user-taken-meaningful-action` cookie. | ||
@@ -187,0 +187,0 @@ #### isChatVisible() => boolean |
@@ -50,3 +50,3 @@ // @flow | ||
mockCookies.getQuiqChatContainerVisibleCookie.mockReturnValue(true); | ||
mockCookies.getQuiqLauncherVisibleCookie.mockReturnValue(true); | ||
mockCookies.getQuiqUserTakenMeaningfulActionCookie.mockReturnValue(true); | ||
@@ -261,3 +261,3 @@ client = new QuiqChatClient(host, contactPoint) | ||
describe('hasActiveChat', () => { | ||
describe('hasTakenMeaningfulAction', () => { | ||
beforeEach(() => { | ||
@@ -269,39 +269,10 @@ if (!client) { | ||
describe('when launcher is not visible', () => { | ||
it('returns false', async () => { | ||
if (!client) { | ||
throw new Error('Client undefined'); | ||
} | ||
it('returns the value of the quiq-user-taken-meaningful-action cookie value', () => { | ||
if (!client) { | ||
throw new Error('Client undefined'); | ||
} | ||
mockCookies.getQuiqLauncherVisibleCookie.mockReturnValue(false); | ||
const res = await client.hasActiveChat(); | ||
expect(res).toBe(false); | ||
}); | ||
mockCookies.getQuiqUserTakenMeaningfulActionCookie.mockReturnValueOnce(false); | ||
expect(client.hasTakenMeaningfulAction()).toBe(false); | ||
}); | ||
describe('when there are no messages', () => { | ||
it('returns false', async () => { | ||
if (!client) { | ||
throw new Error('Client undefined'); | ||
} | ||
mockCookies.getQuiqLauncherVisibleCookie.mockReturnValue(false); | ||
API.fetchConversation.mockReturnValue([]); | ||
const res = await client.hasActiveChat(); | ||
expect(res).toBe(false); | ||
}); | ||
}); | ||
describe('when there are messages', () => { | ||
it('returns true', async () => { | ||
if (!client) { | ||
throw new Error('Client undefined'); | ||
} | ||
mockCookies.getQuiqLauncherVisibleCookie.mockReturnValue(true); | ||
API.fetchConversation.mockReturnValue(initialConvo); | ||
const res = await client.hasActiveChat(); | ||
expect(res).toBe(true); | ||
}); | ||
}); | ||
}); | ||
@@ -336,3 +307,3 @@ | ||
expect(mockCookies.setQuiqChatContainerVisibleCookie).toBeCalledWith(true); | ||
expect(mockCookies.setQuiqLauncherVisibleCookie).toBeCalledWith(true); | ||
expect(mockCookies.setQuiqUserTakenMeaningfulActionCookie).toBeCalledWith(true); | ||
}); | ||
@@ -362,3 +333,3 @@ }); | ||
expect(mockCookies.setQuiqChatContainerVisibleCookie).toBeCalledWith(true); | ||
expect(mockCookies.setQuiqLauncherVisibleCookie).toBeCalledWith(true); | ||
expect(mockCookies.setQuiqUserTakenMeaningfulActionCookie).toBeCalledWith(true); | ||
}); | ||
@@ -365,0 +336,0 @@ }); |
@@ -7,4 +7,4 @@ // @flow | ||
}; | ||
export const setQuiqLauncherVisibleCookie = (visible: boolean) => { | ||
set('quiq-chat-launcher-visible', visible, {expires: 1}); | ||
export const setQuiqUserTakenMeaningfulActionCookie = (visible: boolean) => { | ||
set('quiq-user-taken-meaningful-action', visible, {expires: 1}); | ||
}; | ||
@@ -14,2 +14,3 @@ | ||
get('quiq-chat-container-visible') === 'true'; | ||
export const getQuiqLauncherVisibleCookie = () => get('quiq-chat-launcher-visible') === 'true'; | ||
export const getQuiqUserTakenMeaningfulActionCookie = () => | ||
get('quiq-user-taken-meaningful-action') === 'true'; |
@@ -166,3 +166,3 @@ // @flow | ||
cookies.setQuiqChatContainerVisibleCookie(true); | ||
cookies.setQuiqLauncherVisibleCookie(true); | ||
cookies.setQuiqUserTakenMeaningfulActionCookie(true); | ||
return API.addMessage(text); | ||
@@ -177,3 +177,3 @@ }; | ||
cookies.setQuiqChatContainerVisibleCookie(true); | ||
cookies.setQuiqLauncherVisibleCookie(true); | ||
cookies.setQuiqUserTakenMeaningfulActionCookie(true); | ||
return API.sendRegistration(fields); | ||
@@ -186,16 +186,5 @@ }; | ||
isChatVisible = (): boolean => { | ||
return cookies.getQuiqChatContainerVisibleCookie(); | ||
}; | ||
isChatVisible = (): boolean => cookies.getQuiqChatContainerVisibleCookie(); | ||
hasTakenMeaningfulAction = (): boolean => cookies.getQuiqUserTakenMeaningfulActionCookie(); | ||
hasActiveChat = async () => { | ||
if (!cookies.getQuiqLauncherVisibleCookie()) return false; | ||
if (this.textMessages.length > 0) return true; | ||
await this.getMessages(); | ||
return this.textMessages.length > 0; | ||
}; | ||
getLastUserEvent = async (cache: boolean = true): Promise<UserEventTypes | null> => { | ||
@@ -202,0 +191,0 @@ if (!cache || !this.connected) { |
@@ -73,3 +73,4 @@ // @flow | ||
checkForAgents: () => Promise<{available: boolean}>, | ||
hasActiveChat: () => boolean, | ||
isChatVisible: () => boolean, | ||
hasTakenMeaningfulAction: () => boolean, | ||
}; | ||
@@ -76,0 +77,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
553250
8040