Skip to content

Commit

Permalink
cookies.js extensions functions added
Browse files Browse the repository at this point in the history
  • Loading branch information
lanesCSO committed Mar 13, 2024
1 parent 574588b commit dbe8b1f
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/js/api.constant.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*******************************************************************************
API - Constant
*******************************************************************************/
const C_API_VERSION = "4.3.1";
const C_API_VERSION = "5.0.0";

/*******************************************************************************
API - Constant - URI
Expand Down
2 changes: 1 addition & 1 deletion src/js/api.constant.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 6 additions & 7 deletions src/js/api.library.js
Original file line number Diff line number Diff line change
Expand Up @@ -918,9 +918,8 @@ api.cookie.session.confirmExtension = function () { };
api.cookie.session.start = function (pLength, pLogoutEnpoint, pLogoutMethod) {
// Get unix timestamp to deal with numbers rather than dates
var timestamp = Math.round(new Date().getTime() / 1000);

// Set the Session Cookie
Cookies.set(
Cookies.setJSON(
C_API_COOKIE_SESSION,
$.extend(true, {}, api.cookie.session.data,
{
Expand All @@ -940,13 +939,13 @@ api.cookie.session.start = function (pLength, pLogoutEnpoint, pLogoutMethod) {
*/
api.cookie.session.extend = function () {
// Get the session cookie if any
var data = Cookies.get(C_API_COOKIE_SESSION);
var data = Cookies.getJSON(C_API_COOKIE_SESSION);

if (data) {
// Get unix timestamp to deal with numbers rather than dates
var timestamp = Math.round(new Date().getTime() / 1000);
// Extend Session Cookie
Cookies.set(
Cookies.setJSON(
C_API_COOKIE_SESSION,
$.extend(true, {}, data,
{
Expand All @@ -963,7 +962,7 @@ api.cookie.session.extend = function () {
api.cookie.session.end = function (logoutEndpoint, logoutMethod) {
logoutEndpoint = logoutEndpoint || null;
logoutMethod = logoutMethod || null;
var session = Cookies.get(C_API_COOKIE_SESSION);
var session = Cookies.getJSON(C_API_COOKIE_SESSION);
// Run the Logout API
api.ajax.jsonrpc.request(
logoutEndpoint || session.logoutEndpoint,
Expand Down Expand Up @@ -993,7 +992,7 @@ api.cookie.session.endCallbak = function (data) {
*/
api.cookie.session.intervalRoutine = function () {
// Get the session cookie if any
var data = Cookies.get(C_API_COOKIE_SESSION);
var data = Cookies.getJSON(C_API_COOKIE_SESSION);
if (!data || $.active) {
// If no session cookie or any running Ajax, then do nothing
return;
Expand All @@ -1010,4 +1009,4 @@ api.cookie.session.intervalRoutine = function () {
} else {
// The session is valid, do nothing
}
};
};
2 changes: 1 addition & 1 deletion src/js/api.library.min.js

Large diffs are not rendered by default.

19 changes: 19 additions & 0 deletions src/js/api.plugin.cookie.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*******************************************************************************
Application - Plugin - Cookies.js https://github.com/js-cookie/js-cookie
*******************************************************************************/

Cookies.setJSON = function (cookieName, data, cookieOptions) {
Cookies.set(cookieName, JSON.stringify(data), cookieOptions);
}


Cookies.getJSON = function (cookieName) {
var cookieValue = Cookies.get(cookieName);
debugger
if (cookieValue) {
return JSON.parse(cookieValue)
}
else {
return cookieValue
}
}
1 change: 1 addition & 0 deletions src/js/api.plugin.cookie.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit dbe8b1f

Please sign in to comment.