Server IP : 104.21.38.3 / Your IP : 172.69.176.123 Web Server : Apache System : Linux krdc-ubuntu-s-2vcpu-4gb-amd-blr1-01.localdomain 5.15.0-142-generic #152-Ubuntu SMP Mon May 19 10:54:31 UTC 2025 x86_64 User : www ( 1000) PHP Version : 7.4.33 Disable Function : passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /www/wwwroot/savinassociates.com/wp-content/plugins/redux-framework/extendify-sdk/src/state/ |
Upload File : |
import { sample } from 'lodash' import create from 'zustand' import { persist } from 'zustand/middleware' import { User } from '@extendify/api/User' const storage = { getItem: async () => await User.getData(), setItem: async (_name, value) => await User.setData(value), removeItem: async () => await User.deleteData(), } const isGlobalLibraryEnabled = () => window.extendifyData.sitesettings === null || window.extendifyData?.sitesettings?.state?.enabled // Keep track of active tests as some might be active // but never rendered. const activeTests = { ['main-button-text2']: '0007', } export const useUserStore = create( persist( (set, get) => ({ _hasHydrated: false, firstLoadedOn: new Date().toISOString(), email: '', apiKey: '', uuid: '', sdkPartner: '', noticesDismissedAt: {}, modalNoticesDismissedAt: {}, imports: 0, // total imports over time runningImports: 0, // timed imports, resets to 0 every month allowedImports: 0, // Max imports the Extendify service allows freebieImports: 0, // Various free imports from actions (rewards) entryPoint: 'not-set', enabled: isGlobalLibraryEnabled(), canInstallPlugins: false, canActivatePlugins: false, participatingTestsGroups: {}, preferredOptions: { taxonomies: {}, type: '', search: '', }, incrementImports: () => { // If the user has freebie imports, use those first const freebieImports = Number(get().freebieImports) > 0 ? Number(get().freebieImports) - 1 : Number(get().freebieImports) // If they don't, then increment the running imports const runningImports = Number(get().runningImports) + +(freebieImports < 1) set({ imports: Number(get().imports) + 1, runningImports, freebieImports, }) }, giveFreebieImports: (amount) => { set({ freebieImports: get().freebieImports + amount }) }, totalAvailableImports: () => { return ( Number(get().allowedImports) + Number(get().freebieImports) ) }, testGroup(testKey, groupOptions) { if (!Object.keys(activeTests).includes(testKey)) return let groups = get().participatingTestsGroups // If the test is already in the group, don't add it again if (!groups[testKey]) { set({ participatingTestsGroups: Object.assign({}, groups, { [testKey]: sample(groupOptions), }), }) } groups = get().participatingTestsGroups return groups[testKey] }, activeTestGroups() { return Object.entries(get().participatingTestsGroups) .filter(([key]) => Object.keys(activeTests).includes(key)) .reduce((obj, [key, value]) => { obj[key] = value return obj }, {}) }, activeTestGroupsUtmValue() { const active = Object.entries(get().activeTestGroups()) .map(([key, value]) => { return `${activeTests[key]}=${value}` }, '') .join(':') return encodeURIComponent(active) }, hasAvailableImports: () => { return get().apiKey ? true : Number(get().runningImports) < Number(get().totalAvailableImports()) }, remainingImports: () => { const remaining = Number(get().totalAvailableImports()) - Number(get().runningImports) // If they have no allowed imports, this might be a first load // where it's just fetching templates (and/or their max allowed) if (!get().allowedImports) { return null } return remaining > 0 ? remaining : 0 }, updatePreferredSiteType: (value) => { get().updatePreferredOption('siteType', value) }, updatePreferredOption: (option, value) => { // If the option doesn't exist, assume it's a taxonomy if ( !Object.prototype.hasOwnProperty.call( get().preferredOptions, option, ) ) { value = Object.assign( {}, get().preferredOptions?.taxonomies ?? {}, { [option]: value }, ) option = 'taxonomies' } set({ preferredOptions: { ...Object.assign({}, get().preferredOptions, { [option]: value, }), }, }) }, // Will mark a modal or footer notice markNoticeSeen: (key, type) => { set({ [`${type}DismissedAt`]: { ...get()[`${type}DismissedAt`], [key]: new Date().toISOString(), }, }) }, }), { name: 'extendify-user', getStorage: () => storage, onRehydrateStorage: () => () => { useUserStore.setState({ _hasHydrated: true }) }, partialize: (state) => { delete state._hasHydrated return state }, }, ), )