UNPKG

@bzbs/react-providers

Version:

A collection of React Context Provider for Buzzebees apps

1 lines 251 kB
{"version":3,"sources":["../src/stores/address.store.ts","../src/stores/buzzebeess-app.store.ts","../src/stores/alert.store.ts","../src/stores/analytics.store.ts","../src/stores/auth.store.ts","../src/utils/analytics.ts","../src/utils/string_utils.ts","../src/constant.tsx","../src/utils/purchase_utils.ts","../src/utils/locale.ts","../src/stores/locale.store.ts","../src/stores/user.store.ts","../src/service/bzbs_service.ts","../src/stores/campaign-detail.store.ts","../src/utils/campaign_utils.ts","../src/stores/campaigns.store.ts","../src/stores/favorite-campaigns.store.ts","../src/stores/cart.store.ts","../src/stores/categories.store.ts","../src/stores/confirm.store.ts","../src/stores/consent.store.ts","../src/stores/coupon.store.ts","../src/stores/dashboard.store.ts","../src/stores/loading-indicator.store.ts","../src/stores/maintenance.store.ts","../src/stores/notification.store.ts","../src/stores/point-log.store.ts","../src/stores/popup.store.ts","../src/stores/purchase.store.ts","../src/stores/registration.store.ts","../src/stores/zipcode.store.ts"],"sourcesContent":["import { Address, ServiceResponse } from '@bzbs/react-api-client';\nimport { create } from 'zustand';\nimport { useBuzzebeesAppStore } from './buzzebeess-app.store';\n\nexport type AddressState = {\n addresses: Address[];\n taxAddresses: Address[];\n selectedAddress: Address | null;\n selectedTaxAddress: Address | null;\n isLoading: boolean;\n error: ServiceResponse<unknown> | null;\n};\n\nexport type AddressActions = {\n setSelectedAddress: (address: Address | null) => void;\n fetchAddresses: () => Promise<ServiceResponse<Address[]>>;\n addAddress: (address: AddressFormData) => Promise<ServiceResponse<Address>>;\n editAddress: (address: AddressFormData) => Promise<ServiceResponse<Address>>;\n deleteAddress: (rowKey: string) => Promise<ServiceResponse<unknown>>;\n setSelectedTaxAddress: (address: Address | null) => void;\n fetchTaxAddresses: () => Promise<ServiceResponse<Address[]>>;\n addTaxAddress: (address: AddressFormData) => Promise<ServiceResponse<Address>>;\n editTaxAddress: (address: AddressFormData) => Promise<ServiceResponse<Address>>;\n deleteTaxAddress: (rowKey: string) => Promise<ServiceResponse<unknown>>;\n clear: () => void;\n};\n\nexport type AddressStore = AddressState & AddressActions;\n\nexport type PersonType = 'individual' | 'company';\n\nexport type AddressFormData = {\n addressName?: string;\n firstName?: string;\n lastName?: string;\n address?: string;\n zipcode?: string;\n provinceCode?: string;\n provinceName?: string;\n districtCode?: string;\n districtName?: string;\n subDistrictCode?: string;\n subDistrictName?: string;\n contactNumber?: string;\n email?: string;\n remark?: string;\n countryCode?: string;\n countryName?: string;\n isDefault?: boolean;\n rowKey?: string;\n // Tax address specific fields\n taxId?: string;\n personType?: PersonType;\n companyName?: string;\n};\n\nexport const useAddressStore = create<AddressStore>((set, get) => ({\n addresses: [],\n taxAddresses: [],\n selectedAddress: null,\n selectedTaxAddress: null,\n isLoading: false,\n error: null,\n\n setSelectedAddress: (address: Address | null) => set({ selectedAddress: address }),\n\n fetchAddresses: async () => {\n const bzbsService = useBuzzebeesAppStore.getState().bzbsService;\n\n if (!bzbsService) {\n return { type: 'client-error', message: 'Service not configured' };\n }\n\n set({ isLoading: true });\n const response = await bzbsService.addressApi.userAddresses();\n set({ isLoading: false });\n\n if (response.type === 'success') {\n set({\n addresses: response.model,\n error: null,\n });\n } else {\n set({ error: response });\n }\n\n return response;\n },\n\n addAddress: async (addressForm: AddressFormData) => {\n const bzbsService = useBuzzebeesAppStore.getState().bzbsService;\n\n if (!bzbsService) {\n return { type: 'client-error', message: 'Service not configured' };\n }\n\n set({ isLoading: true });\n const response = await bzbsService.addressApi.updateAddress({\n ...addressForm,\n rowKey: '',\n });\n set({ isLoading: false });\n\n if (response.type === 'success') {\n get().fetchAddresses();\n set({ error: null });\n } else {\n set({ error: response });\n }\n\n return response;\n },\n\n editAddress: async (addressForm: AddressFormData) => {\n const bzbsService = useBuzzebeesAppStore.getState().bzbsService;\n\n if (!bzbsService) {\n return { type: 'client-error', message: 'Service not configured' };\n }\n\n set({ isLoading: true });\n const response = await bzbsService.addressApi.updateAddress({\n ...addressForm,\n });\n set({ isLoading: false });\n\n if (response.type === 'success') {\n get().fetchAddresses();\n set({ error: null });\n } else {\n set({ error: response });\n }\n\n return response;\n },\n\n deleteAddress: async (rowKey: string) => {\n const bzbsService = useBuzzebeesAppStore.getState().bzbsService;\n\n if (!bzbsService) {\n return { type: 'client-error', message: 'Service not configured' };\n }\n\n set({ isLoading: true });\n const response = await bzbsService.addressApi.deleteAddress({ rowKey });\n set({ isLoading: false });\n\n if (response.type === 'success') {\n get().fetchAddresses();\n set({ error: null });\n } else {\n set({ error: response });\n }\n\n return response;\n },\n\n setSelectedTaxAddress: (address: Address | null) => set({ selectedTaxAddress: address }),\n\n fetchTaxAddresses: async () => {\n const bzbsService = useBuzzebeesAppStore.getState().bzbsService;\n\n if (!bzbsService) {\n return { type: 'client-error', message: 'Service not configured' };\n }\n\n set({ isLoading: true });\n const response = await bzbsService.addressApi.userTaxAddresses();\n set({ isLoading: false });\n\n if (response.type === 'success') {\n set({\n taxAddresses: response.model,\n error: null,\n });\n } else {\n set({ error: response });\n }\n\n return response;\n },\n\n addTaxAddress: async (addressForm: AddressFormData) => {\n const bzbsService = useBuzzebeesAppStore.getState().bzbsService;\n\n if (!bzbsService) {\n return { type: 'client-error', message: 'Service not configured' };\n }\n\n set({ isLoading: true });\n const response = await bzbsService.addressApi.updateTaxAddress({\n ...addressForm,\n rowKey: '',\n });\n set({ isLoading: false });\n\n if (response.type === 'success') {\n get().fetchTaxAddresses();\n set({ error: null });\n } else {\n set({ error: response });\n }\n\n return response;\n },\n\n editTaxAddress: async (addressForm: AddressFormData) => {\n const bzbsService = useBuzzebeesAppStore.getState().bzbsService;\n\n if (!bzbsService) {\n return { type: 'client-error', message: 'Service not configured' };\n }\n\n set({ isLoading: true });\n const response = await bzbsService.addressApi.updateTaxAddress({\n ...addressForm,\n rowKey: addressForm.rowKey || '',\n });\n set({ isLoading: false });\n\n if (response.type === 'success') {\n get().fetchTaxAddresses();\n set({ error: null });\n } else {\n set({ error: response });\n }\n\n return response;\n },\n\n deleteTaxAddress: async (rowKey: string) => {\n const bzbsService = useBuzzebeesAppStore.getState().bzbsService;\n\n if (!bzbsService) {\n return { type: 'client-error', message: 'Service not configured' };\n }\n\n set({ isLoading: true });\n const response = await bzbsService.addressApi.deleteTaxAddress({ rowKey });\n set({ isLoading: false });\n\n if (response.type === 'success') {\n get().fetchTaxAddresses();\n set({ error: null });\n } else {\n set({ error: response });\n }\n\n return response;\n },\n\n clear: () => {\n set({\n addresses: [],\n taxAddresses: [],\n selectedAddress: null,\n selectedTaxAddress: null,\n isLoading: false,\n error: null,\n });\n },\n}));\n","import { BzbsService } from '@bzbs/react-api-client';\nimport { create } from 'zustand';\n\nexport type AuthTokenType = 'jwt' | 'auth_token';\n\ntype getTokenFunction = () => Promise<string | null>;\ntype setTokenFunction = (token: string) => void;\ntype removeTokenFunction = () => void;\n\nexport type TokenFunctions = {\n getToken: getTokenFunction;\n setToken: setTokenFunction;\n removeToken: removeTokenFunction;\n};\n\nexport type BuzzebeesAppState = {\n appId: string;\n appName: string;\n bzbsService: BzbsService | null;\n uuid: string;\n macAddress: string;\n clientVersion: string;\n os: string;\n platform: string;\n fcmToken: string;\n deviceNotificationEnabled: boolean;\n urls: {\n webCallback: string;\n cart: string;\n };\n tokenFunctions: TokenFunctions | null;\n tokenType: AuthTokenType;\n config: {\n defaultDashboardConfig: string;\n defaultDashboardMode: 'main' | 'sub';\n defaultMenuConfig: string;\n defaultCampaignConfig: string;\n supportPointUnits: string[];\n };\n};\n\nexport type BuzzebeesAppActions = {\n setAppId: (appId: string) => void;\n setAppName: (appName: string) => void;\n setBzbsService: (service: BzbsService) => void;\n setUuid: (uuid: string) => void;\n setMacAddress: (macAddress: string) => void;\n setClientVersion: (clientVersion: string) => void;\n setOs: (os: string) => void;\n setPlatform: (platform: string) => void;\n setFcmToken: (fcmToken: string) => void;\n setDeviceNotificationEnabled: (deviceNotificationEnabled: boolean) => void;\n setUrls: (urls: { webCallback: string; cart: string }) => void;\n setTokenType: (tokenType: AuthTokenType) => void;\n setTokenFunctions: (tokenFunctions: TokenFunctions) => void;\n configure: (config: {\n appId: string;\n appName: string;\n bzbsService: BzbsService;\n uuid: string;\n macAddress: string;\n clientVersion: string;\n os: string;\n platform: string;\n fcmToken: string;\n deviceNotificationEnabled: boolean;\n urls: { webCallback: string; cart: string };\n tokenFunctions: TokenFunctions;\n tokenType: AuthTokenType;\n defaultDashboardConfig: string;\n defaultDashboardMode: 'main' | 'sub';\n defaultMenuConfig: string;\n defaultCampaignConfig: string;\n supportPointUnits: string[];\n }) => void;\n};\n\nexport type BuzzebeesAppStore = BuzzebeesAppState & BuzzebeesAppActions;\n\nexport const useBuzzebeesAppStore = create<BuzzebeesAppStore>((set) => ({\n appId: '',\n appName: '',\n bzbsService: null,\n uuid: '',\n macAddress: '',\n clientVersion: '',\n os: '',\n platform: '',\n fcmToken: '',\n deviceNotificationEnabled: false,\n urls: {\n webCallback: '',\n cart: '',\n },\n tokenFunctions: null,\n tokenType: 'jwt',\n config: {\n defaultDashboardConfig: '',\n defaultDashboardMode: 'main',\n defaultMenuConfig: '',\n defaultCampaignConfig: '',\n supportPointUnits: [],\n },\n setAppId: (appId: string) => set({ appId }),\n setAppName: (appName: string) => set({ appName }),\n setBzbsService: (service: BzbsService) => set({ bzbsService: service }),\n setUuid: (uuid: string) => set({ uuid }),\n setMacAddress: (macAddress: string) => set({ macAddress }),\n setClientVersion: (clientVersion: string) => set({ clientVersion }),\n setOs: (os: string) => set({ os }),\n setPlatform: (platform: string) => set({ platform }),\n setFcmToken: (fcmToken: string) => set({ fcmToken }),\n setDeviceNotificationEnabled: (deviceNotificationEnabled: boolean) => set({ deviceNotificationEnabled }),\n setUrls: (urls: { webCallback: string; cart: string }) => set({ urls }),\n setTokenFunctions: (tokenFunctions: TokenFunctions) => set({ tokenFunctions }),\n setTokenType: (tokenType: AuthTokenType) => set({ tokenType }),\n configure: (config: {\n appId: string;\n appName: string;\n bzbsService: BzbsService;\n uuid: string;\n macAddress: string;\n clientVersion: string;\n os: string;\n platform: string;\n fcmToken: string;\n deviceNotificationEnabled: boolean;\n urls: { webCallback: string; cart: string };\n tokenFunctions: TokenFunctions;\n tokenType: AuthTokenType;\n defaultDashboardConfig: string;\n defaultDashboardMode: 'main' | 'sub';\n defaultMenuConfig: string;\n defaultCampaignConfig: string;\n supportPointUnits: string[];\n }) => {\n set({\n appId: config.appId,\n appName: config.appName,\n bzbsService: config.bzbsService,\n uuid: config.uuid,\n macAddress: config.macAddress,\n clientVersion: config.clientVersion,\n os: config.os,\n platform: config.platform,\n fcmToken: config.fcmToken,\n deviceNotificationEnabled: config.deviceNotificationEnabled,\n urls: config.urls,\n tokenFunctions: config.tokenFunctions,\n tokenType: config.tokenType,\n config: {\n defaultDashboardConfig: config.defaultDashboardConfig,\n defaultDashboardMode: config.defaultDashboardMode,\n defaultMenuConfig: config.defaultMenuConfig,\n defaultCampaignConfig: config.defaultCampaignConfig,\n supportPointUnits: config.supportPointUnits,\n },\n });\n },\n}));\n","import { create } from 'zustand';\n\nexport type AlertRequest = {\n title: string;\n content: string;\n closeText?: string;\n onClose: () => void;\n};\n\nexport type AlertState = {\n isOpen: boolean;\n alertRequest: AlertRequest;\n};\n\nexport type AlertActions = {\n openAlert: (request: AlertRequest) => void;\n closeAlert: () => void;\n};\n\nexport type AlertStore = AlertState & AlertActions;\n\nexport const useAlertStore = create<AlertStore>((set, get) => ({\n isOpen: false,\n alertRequest: {\n title: '',\n content: '',\n onClose: () => {},\n },\n\n openAlert: (request: AlertRequest) => {\n set({ alertRequest: request, isOpen: true });\n },\n\n closeAlert: () => {\n const { alertRequest } = get();\n alertRequest.onClose();\n set({ isOpen: false });\n },\n}));\n","import type { UserInfo } from 'matomo-tracker-react-native';\nimport MatomoTracker from 'matomo-tracker-react-native';\nimport { create } from 'zustand';\n\nexport type AnalyticsEventParams = {\n action: string;\n name?: string;\n category?: string;\n value?: number;\n campaign?: string;\n userInfo?: UserInfo;\n};\n\nexport type AnalyticsPageViewParams = {\n name: string;\n url?: string;\n userInfo?: UserInfo;\n};\n\nexport type AnalyticsState = {\n isInitialized: boolean;\n isEnabled: boolean;\n siteId?: number;\n urlBase?: string;\n trackerUrl?: string;\n userId?: string;\n disabled?: boolean;\n log?: boolean;\n matomoInstance?: MatomoTracker;\n presetUserInfo?: UserInfo;\n};\n\nexport type AnalyticsActions = {\n initialize: (config: {\n siteId: number;\n urlBase: string;\n trackerUrl?: string;\n userId?: string;\n disabled?: boolean;\n log?: boolean;\n }) => void;\n setEnabled: (enabled: boolean) => void;\n setPresetUserInfo: (userInfo: UserInfo) => void;\n clearPresetUserInfo: () => void;\n trackAppStart: (userInfo?: UserInfo) => Promise<void>;\n trackEvent: (params: AnalyticsEventParams) => Promise<void>;\n trackScreenView: (params: AnalyticsPageViewParams) => Promise<void>;\n trackAction: (params: AnalyticsPageViewParams) => Promise<void>;\n trackSiteSearch: (params: {\n keyword: string;\n category?: string;\n count?: number;\n userInfo?: UserInfo;\n }) => Promise<void>;\n trackLink: (params: { link: string; userInfo?: UserInfo }) => Promise<void>;\n trackDownload: (params: { download: string; userInfo?: UserInfo }) => Promise<void>;\n setUserId: (userId: string | null) => void;\n setCustomDimension: (id: number, value: string) => void;\n reset: () => void;\n};\n\nexport type AnalyticsStore = AnalyticsState & AnalyticsActions;\n\nexport const useAnalyticsStore = create<AnalyticsStore>((set, get) => ({\n isInitialized: false,\n isEnabled: true,\n siteId: undefined,\n urlBase: undefined,\n trackerUrl: undefined,\n userId: undefined,\n disabled: false,\n log: false,\n matomoInstance: undefined,\n presetUserInfo: undefined,\n\n initialize: (config) => {\n try {\n // Create Matomo tracker instance\n const matomoInstance = new MatomoTracker({\n urlBase: config.urlBase,\n siteId: config.siteId,\n trackerUrl: config.trackerUrl,\n userId: config.userId,\n disabled: config.disabled || false,\n log: config.log || false,\n });\n\n set({\n siteId: config.siteId,\n urlBase: config.urlBase,\n trackerUrl: config.trackerUrl,\n userId: config.userId,\n disabled: config.disabled || false,\n log: config.log || false,\n matomoInstance,\n isInitialized: true,\n });\n\n console.log('Analytics: Matomo tracker initialized', config);\n } catch (error) {\n console.error('Analytics: Failed to initialize Matomo tracker', error);\n set({\n siteId: config.siteId,\n urlBase: config.urlBase,\n trackerUrl: config.trackerUrl,\n userId: config.userId,\n disabled: config.disabled || false,\n log: config.log || false,\n isInitialized: false,\n });\n }\n },\n\n setEnabled: (enabled: boolean) => {\n set({ isEnabled: enabled });\n },\n\n setPresetUserInfo: (userInfo: UserInfo) => {\n set({ presetUserInfo: userInfo });\n },\n\n clearPresetUserInfo: () => {\n set({ presetUserInfo: undefined });\n },\n\n trackAppStart: async (userInfo?: UserInfo) => {\n const state = get();\n if (!state.isInitialized || !state.isEnabled || !state.matomoInstance || state.disabled) {\n console.debug('Analytics: Track App Start skipped - not initialized, disabled, or tracking disabled');\n return;\n }\n\n try {\n // Merge preset userInfo with provided userInfo\n const mergedUserInfo = { ...state.presetUserInfo, ...userInfo };\n\n await state.matomoInstance.trackAppStart({\n userInfo: Object.keys(mergedUserInfo).length > 0 ? mergedUserInfo : undefined,\n });\n\n if (state.log) {\n console.debug('Analytics: App start tracked successfully', { userInfo: mergedUserInfo });\n }\n } catch (error) {\n console.error('Analytics: Failed to track app start', error);\n }\n },\n\n trackEvent: async (params: AnalyticsEventParams) => {\n const state = get();\n if (!state.isInitialized || !state.isEnabled || !state.matomoInstance || state.disabled) {\n console.debug('Analytics: Track Event skipped - not initialized, disabled, or tracking disabled', params);\n return;\n }\n\n try {\n // Merge preset userInfo with provided userInfo\n const mergedUserInfo = { ...state.presetUserInfo, ...params.userInfo };\n\n await state.matomoInstance.trackEvent({\n category: params.category || 'User Action',\n action: params.action,\n name: params.name,\n value: params.value,\n campaign: params.campaign,\n userInfo: Object.keys(mergedUserInfo).length > 0 ? mergedUserInfo : undefined,\n });\n\n if (state.log) {\n console.debug('Analytics: Event tracked successfully', params);\n }\n } catch (error) {\n console.error('Analytics: Failed to track event', error, params);\n }\n },\n\n trackScreenView: async (params: AnalyticsPageViewParams) => {\n const state = get();\n if (!state.isInitialized || !state.isEnabled || !state.matomoInstance || state.disabled) {\n console.debug('Analytics: Track Screen View skipped - not initialized, disabled, or tracking disabled', params);\n return;\n }\n\n try {\n // Merge preset userInfo with provided userInfo\n const mergedUserInfo = { ...state.presetUserInfo, ...params.userInfo };\n\n await state.matomoInstance.trackScreenView({\n name: params.name,\n userInfo: Object.keys(mergedUserInfo).length > 0 ? mergedUserInfo : undefined,\n });\n\n if (state.log) {\n console.debug('Analytics: Screen view tracked successfully', params);\n }\n } catch (error) {\n console.error('Analytics: Failed to track screen view', error, params);\n }\n },\n\n trackAction: async (params: AnalyticsPageViewParams) => {\n const state = get();\n if (!state.isInitialized || !state.isEnabled || !state.matomoInstance || state.disabled) {\n console.debug('Analytics: Track Action skipped - not initialized, disabled, or tracking disabled', params);\n return;\n }\n\n try {\n // Merge preset userInfo with provided userInfo\n const mergedUserInfo = { ...state.presetUserInfo, ...params.userInfo };\n\n await state.matomoInstance.trackAction({\n name: params.name,\n userInfo: Object.keys(mergedUserInfo).length > 0 ? mergedUserInfo : undefined,\n });\n\n if (state.log) {\n console.debug('Analytics: Action tracked successfully', params);\n }\n } catch (error) {\n console.error('Analytics: Failed to track action', error, params);\n }\n },\n\n trackSiteSearch: async (params: { keyword: string; category?: string; count?: number; userInfo?: UserInfo }) => {\n const state = get();\n if (!state.isInitialized || !state.isEnabled || !state.matomoInstance || state.disabled) {\n console.debug('Analytics: Track Site Search skipped - not initialized, disabled, or tracking disabled', params);\n return;\n }\n\n try {\n // Merge preset userInfo with provided userInfo\n const mergedUserInfo = { ...state.presetUserInfo, ...params.userInfo };\n\n await state.matomoInstance.trackSiteSearch({\n keyword: params.keyword,\n category: params.category,\n count: params.count,\n userInfo: Object.keys(mergedUserInfo).length > 0 ? mergedUserInfo : undefined,\n });\n\n if (state.log) {\n console.debug('Analytics: Site search tracked successfully', params);\n }\n } catch (error) {\n console.error('Analytics: Failed to track site search', error, params);\n }\n },\n\n trackLink: async (params: { link: string; userInfo?: UserInfo }) => {\n const state = get();\n if (!state.isInitialized || !state.isEnabled || !state.matomoInstance || state.disabled) {\n console.debug('Analytics: Track Link skipped - not initialized, disabled, or tracking disabled', params);\n return;\n }\n\n try {\n // Merge preset userInfo with provided userInfo\n const mergedUserInfo = { ...state.presetUserInfo, ...params.userInfo };\n\n await state.matomoInstance.trackLink({\n link: params.link,\n userInfo: Object.keys(mergedUserInfo).length > 0 ? mergedUserInfo : undefined,\n });\n\n if (state.log) {\n console.debug('Analytics: Link tracked successfully', params);\n }\n } catch (error) {\n console.error('Analytics: Failed to track link', error, params);\n }\n },\n\n trackDownload: async (params: { download: string; userInfo?: UserInfo }) => {\n const state = get();\n if (!state.isInitialized || !state.isEnabled || !state.matomoInstance || state.disabled) {\n console.debug('Analytics: Track Download skipped - not initialized, disabled, or tracking disabled', params);\n return;\n }\n\n try {\n // Merge preset userInfo with provided userInfo\n const mergedUserInfo = { ...state.presetUserInfo, ...params.userInfo };\n\n await state.matomoInstance.trackDownload({\n download: params.download,\n userInfo: Object.keys(mergedUserInfo).length > 0 ? mergedUserInfo : undefined,\n });\n\n if (state.log) {\n console.debug('Analytics: Download tracked successfully', params);\n }\n } catch (error) {\n console.error('Analytics: Failed to track download', error, params);\n }\n },\n\n setUserId: (userId: string | null) => {\n const state = get();\n\n // Update both the userId state and the preset userInfo\n if (userId) {\n const updatedUserInfo = {\n ...state.presetUserInfo,\n uid: userId,\n };\n set({\n userId: userId,\n presetUserInfo: updatedUserInfo,\n });\n } else {\n // Remove uid from preset userInfo if userId is null\n const currentUserInfo = state.presetUserInfo || {};\n if (currentUserInfo.uid) {\n const updatedUserInfo = { ...currentUserInfo };\n delete updatedUserInfo.uid;\n\n set({\n userId: undefined,\n presetUserInfo: Object.keys(updatedUserInfo).length > 0 ? updatedUserInfo : undefined,\n });\n } else {\n set({ userId: undefined });\n }\n }\n\n if (state.log) {\n console.debug('Analytics: User ID updated in preset userInfo', userId);\n }\n },\n\n setCustomDimension: (id: number, value: string) => {\n const state = get();\n if (!state.presetUserInfo) {\n set({ presetUserInfo: { [`dimension${id}`]: value } });\n } else {\n set({\n presetUserInfo: {\n ...state.presetUserInfo,\n [`dimension${id}`]: value,\n },\n });\n }\n\n if (state.log) {\n console.debug('Analytics: Custom dimension set in preset userInfo', { id, value });\n }\n },\n\n reset: () => {\n set({\n isInitialized: false,\n isEnabled: true,\n siteId: undefined,\n urlBase: undefined,\n trackerUrl: undefined,\n userId: undefined,\n disabled: false,\n log: false,\n matomoInstance: undefined,\n presetUserInfo: undefined,\n });\n\n console.debug('Analytics: Store reset successfully');\n },\n}));\n","import {\n Account,\n AppleToken,\n ConfirmOtpResponse,\n ErrorResponse,\n ForgetPasswordResponse,\n LoginResponse,\n OtpResponse,\n ResumeResponse,\n ServiceResponse,\n StatusResponse,\n ValidateOtpResponse,\n Version,\n} from '@bzbs/react-api-client';\nimport { create } from 'zustand';\nimport { trackCommonEvents } from '../utils';\nimport { useAnalyticsStore } from './analytics.store';\nimport { useBuzzebeesAppStore } from './buzzebeess-app.store';\nimport { useLocaleStore } from './locale.store';\nimport { useUserStore } from './user.store';\n\nexport type GoogleLoginData = {\n type: 'google';\n idToken: string;\n};\n\nexport type FacebookLoginData = {\n type: 'facebook';\n accessToken: string;\n};\n\nexport type AppleLoginData = {\n type: 'apple';\n idToken: string;\n refreshToken: string;\n};\n\nexport type LineLoginData = {\n type: 'line';\n idToken: string;\n lineAccessToken: string;\n authorizationCode: string;\n};\n\nexport type ThirdPartyLoginData = GoogleLoginData | FacebookLoginData | AppleLoginData | LineLoginData;\n\nexport type AuthState = {\n isInitialized: boolean;\n versionData: Version | null;\n rawVersionData: unknown | null;\n data: LoginResponse | ResumeResponse | null;\n thirdPartyLoginData?: ThirdPartyLoginData;\n isLoading: boolean;\n isLoadingToken: boolean;\n error: ErrorResponse | null;\n token: string | null;\n isLoggedIn: boolean;\n isDeviceLoggedIn: boolean;\n};\n\nexport type AuthActions = {\n setIsLoading: (isLoading: boolean) => void;\n setIsLoadingToken: (isLoadingToken: boolean) => void;\n setError: (error: ErrorResponse | null) => void;\n setThirdPartyLoginData: (thirdPartyLoginData: ThirdPartyLoginData) => void;\n checkLoggedIn: () => Promise<void>;\n loginWithUsernamePassword: (username: string, password: string) => Promise<ServiceResponse<LoginResponse>>;\n loginWithGoogle: (token: string) => Promise<ServiceResponse<LoginResponse>>;\n loginWithFacebook: (token: string) => Promise<ServiceResponse<LoginResponse>>;\n loginWithApple: (token: string, refreshToken: string) => Promise<ServiceResponse<LoginResponse>>;\n loginWithLine: (\n idToken: string,\n lineAccessToken: string,\n authorizationCode: string\n ) => Promise<ServiceResponse<LoginResponse>>;\n loginWithUUID: () => Promise<ServiceResponse<LoginResponse>>;\n loginWithOtp: (otp: string, refCode: string, contact: string) => Promise<ServiceResponse<LoginResponse>>;\n connectThirdParty: (thirdPartyLoginData: ThirdPartyLoginData) => Promise<ServiceResponse<LoginResponse>>;\n disconnectThirdParty: (thirdParties: {\n facebook?: boolean;\n google?: boolean;\n apple?: boolean;\n line?: boolean;\n }) => Promise<ServiceResponse<Account>>;\n logout: () => Promise<ServiceResponse<unknown>>;\n appleToken: (authorizationCode: string, idToken: string) => Promise<ServiceResponse<AppleToken>>;\n forgetPassword: (\n contact: string,\n type: 'email' | 'contact_number'\n ) => Promise<ServiceResponse<ForgetPasswordResponse>>;\n resetPassword: (\n contact: string,\n otp: string,\n refCode: string,\n password: string\n ) => Promise<ServiceResponse<StatusResponse>>;\n sendOtp: (contact: string, channel: string) => Promise<ServiceResponse<OtpResponse>>;\n validateOtp: (\n otp: string,\n refCode: string,\n contact: string,\n channel: string,\n type: 'email' | 'contact_number'\n ) => Promise<ServiceResponse<ValidateOtpResponse>>;\n confirmOtp: (otp: string, refCode: string, contact: string) => Promise<ServiceResponse<ConfirmOtpResponse>>;\n resume: (clientVersion: string) => Promise<ServiceResponse<ResumeResponse>>;\n version: (clientVersion: string) => Promise<ServiceResponse<Version>>;\n clear: () => void;\n};\n\nexport type AuthStore = AuthState & AuthActions;\n\ntype LoginHandlerParams = {\n loginFn: () => Promise<ServiceResponse<LoginResponse>>;\n};\n\nexport const useAuthStore = create<AuthStore>((set, get) => {\n // Private helper function to handle common login logic\n const handleLogin = async ({ loginFn }: LoginHandlerParams): Promise<ServiceResponse<LoginResponse>> => {\n const { bzbsService, tokenFunctions, tokenType } = useBuzzebeesAppStore.getState();\n\n if (!bzbsService || !tokenFunctions) {\n return { type: 'client-error', message: 'Service or auth persistence not configured' };\n }\n\n set({ isLoading: true, error: null });\n const response = await loginFn();\n set({ isLoading: false });\n\n if (response.type === 'success') {\n const token = tokenType === 'jwt' ? response.model.jwt : response.model.token;\n tokenFunctions.setToken(token);\n\n set({\n data: response.model,\n token: response.model.token,\n isLoggedIn: true,\n isDeviceLoggedIn: response.model.account.deviceId != null && response.model.account.deviceId !== '',\n error: null,\n });\n useAnalyticsStore.getState().setUserId(response.model.userId);\n useAnalyticsStore.getState().setCustomDimension(1, useBuzzebeesAppStore.getState().clientVersion);\n useAnalyticsStore.getState().setCustomDimension(2, useBuzzebeesAppStore.getState().appId);\n\n const userResponse = await useUserStore.getState().fetchUser();\n if (userResponse.type === 'success') {\n useAnalyticsStore.getState().setCustomDimension(3, userResponse.model.Contact_Number ?? '');\n useAnalyticsStore.getState().setCustomDimension(4, userResponse.model.Email ?? '');\n }\n\n trackCommonEvents.loginSuccess();\n } else {\n set({ error: response });\n }\n\n return response;\n };\n\n return {\n isInitialized: false,\n versionData: null,\n rawVersionData: null,\n data: null,\n thirdPartyLoginData: undefined,\n isLoading: false,\n isLoadingToken: false,\n error: null,\n token: null,\n isLoggedIn: false,\n isDeviceLoggedIn: false,\n\n setIsLoading: (isLoading: boolean) => set({ isLoading }),\n setIsLoadingToken: (isLoadingToken: boolean) => set({ isLoadingToken }),\n setError: (error: ErrorResponse | null) => set({ error }),\n setThirdPartyLoginData: (thirdPartyLoginData: ThirdPartyLoginData) => set({ thirdPartyLoginData }),\n\n checkLoggedIn: async () => {\n const { tokenFunctions } = useBuzzebeesAppStore.getState();\n if (!tokenFunctions) {\n set({ isLoggedIn: false, isInitialized: true });\n return;\n }\n\n try {\n set({ isLoadingToken: true });\n const token = await tokenFunctions.getToken();\n if (token) {\n set({ isLoggedIn: true, token });\n } else {\n set({ isLoggedIn: false, token: null });\n }\n } catch (error) {\n set({ isLoggedIn: false, token: null });\n } finally {\n set({ isLoadingToken: false, isInitialized: true });\n }\n },\n\n loginWithUsernamePassword: async (username: string, password: string) => {\n const { appId, uuid, os, platform, deviceNotificationEnabled, clientVersion, fcmToken, macAddress } =\n useBuzzebeesAppStore.getState();\n\n const localeId = useLocaleStore.getState().localeId;\n const bzbsService = useBuzzebeesAppStore.getState().bzbsService;\n\n if (!bzbsService) {\n return { type: 'client-error', message: 'Service not configured' };\n }\n\n return handleLogin({\n loginFn: () =>\n bzbsService.authApi.usernamePasswordLogin({\n username,\n password,\n appId,\n uuid,\n deviceToken: fcmToken,\n clientVersion,\n os,\n platform,\n deviceLocale: localeId.toString(),\n deviceNotificationEnabled,\n macAddress,\n }),\n });\n },\n\n loginWithGoogle: async (token: string) => {\n const { appId, uuid, os, platform, deviceNotificationEnabled, clientVersion, fcmToken, macAddress } =\n useBuzzebeesAppStore.getState();\n const localeId = useLocaleStore.getState().localeId;\n const bzbsService = useBuzzebeesAppStore.getState().bzbsService;\n\n set({ thirdPartyLoginData: { type: 'google', idToken: token } });\n\n if (!bzbsService) {\n return { type: 'client-error', message: 'Service not configured' };\n }\n\n return handleLogin({\n loginFn: () =>\n bzbsService.authApi.googleLogin({\n idToken: token,\n appId,\n uuid,\n deviceToken: fcmToken,\n clientVersion,\n os,\n platform,\n deviceLocale: localeId.toString(),\n deviceNotificationEnabled,\n macAddress,\n }),\n });\n },\n\n loginWithFacebook: async (token: string) => {\n const { appId, uuid, os, platform, deviceNotificationEnabled, clientVersion, fcmToken, macAddress } =\n useBuzzebeesAppStore.getState();\n const localeId = useLocaleStore.getState().localeId;\n const bzbsService = useBuzzebeesAppStore.getState().bzbsService;\n\n set({ thirdPartyLoginData: { type: 'facebook', accessToken: token } });\n\n if (!bzbsService) {\n return { type: 'client-error', message: 'Service not configured' };\n }\n\n return handleLogin({\n loginFn: () =>\n bzbsService.authApi.facebookLogin({\n accessToken: token,\n appId,\n uuid,\n deviceToken: fcmToken,\n clientVersion,\n os,\n platform,\n deviceLocale: localeId.toString(),\n deviceNotificationEnabled,\n macAddress,\n }),\n });\n },\n\n loginWithApple: async (token: string, refreshToken: string) => {\n const { appId, uuid, os, platform, deviceNotificationEnabled, clientVersion, fcmToken, macAddress } =\n useBuzzebeesAppStore.getState();\n const localeId = useLocaleStore.getState().localeId;\n const bzbsService = useBuzzebeesAppStore.getState().bzbsService;\n\n set({ thirdPartyLoginData: { type: 'apple', idToken: token, refreshToken } });\n\n if (!bzbsService) {\n return { type: 'client-error', message: 'Service not configured' };\n }\n\n return handleLogin({\n loginFn: () =>\n bzbsService.authApi.appleLogin({\n idToken: token,\n refreshToken,\n appId,\n uuid,\n deviceToken: fcmToken,\n clientVersion,\n os,\n platform,\n deviceLocale: localeId.toString(),\n deviceNotificationEnabled,\n macAddress,\n }),\n });\n },\n\n loginWithLine: async (idToken: string, lineAccessToken: string, authorizationCode: string) => {\n const { appId, uuid, os, platform, deviceNotificationEnabled, clientVersion, fcmToken, macAddress } =\n useBuzzebeesAppStore.getState();\n const localeId = useLocaleStore.getState().localeId;\n const bzbsService = useBuzzebeesAppStore.getState().bzbsService;\n\n set({ thirdPartyLoginData: { type: 'line', idToken, lineAccessToken, authorizationCode } });\n\n if (!bzbsService) {\n return { type: 'client-error', message: 'Service not configured' };\n }\n\n return handleLogin({\n loginFn: () =>\n bzbsService.authApi.lineLogin({\n idToken,\n lineAccessToken,\n authorizationCode,\n appId,\n uuid,\n deviceToken: fcmToken,\n clientVersion,\n os,\n platform,\n deviceLocale: localeId.toString(),\n deviceNotificationEnabled,\n macAddress,\n }),\n });\n },\n\n loginWithUUID: async () => {\n const { appId, uuid, os, platform, deviceNotificationEnabled, clientVersion, fcmToken, macAddress } =\n useBuzzebeesAppStore.getState();\n const localeId = useLocaleStore.getState().localeId;\n const bzbsService = useBuzzebeesAppStore.getState().bzbsService;\n\n if (!bzbsService) {\n return { type: 'client-error', message: 'Service not configured' };\n }\n\n return handleLogin({\n loginFn: () =>\n bzbsService.authApi.deviceLogin({\n appId,\n uuid,\n deviceToken: fcmToken,\n clientVersion,\n os,\n platform,\n deviceLocale: localeId.toString(),\n deviceNotificationEnabled,\n macAddress,\n }),\n });\n },\n\n loginWithOtp: async (otp: string, refCode: string, contact: string) => {\n const { appId, os, platform, deviceNotificationEnabled, clientVersion, fcmToken, macAddress } =\n useBuzzebeesAppStore.getState();\n const localeId = useLocaleStore.getState().localeId;\n const bzbsService = useBuzzebeesAppStore.getState().bzbsService;\n\n if (!bzbsService) {\n return { type: 'client-error', message: 'Service not configured' };\n }\n\n return handleLogin({\n loginFn: () =>\n bzbsService.authApi.deviceLogin({\n appId,\n uuid: contact,\n deviceToken: fcmToken,\n clientVersion,\n os,\n platform,\n deviceLocale: localeId.toString(),\n deviceNotificationEnabled,\n macAddress,\n otp,\n refcode: refCode,\n contact_number: contact,\n }),\n });\n },\n\n connectThirdParty: async (thirdPartyLoginData: ThirdPartyLoginData) => {\n const { appId, uuid, os, platform, deviceNotificationEnabled, clientVersion, fcmToken, macAddress } =\n useBuzzebeesAppStore.getState();\n const localeId = useLocaleStore.getState().localeId;\n const bzbsService = useBuzzebeesAppStore.getState().bzbsService;\n\n if (!bzbsService) {\n return { type: 'client-error', message: 'Service not configured' };\n }\n\n let response: ServiceResponse<LoginResponse>;\n\n switch (thirdPartyLoginData.type) {\n case 'google':\n response = await handleLogin({\n loginFn: () =>\n bzbsService.authApi.connectGoogle({\n idToken: thirdPartyLoginData.idToken,\n appId,\n uuid,\n deviceToken: fcmToken,\n clientVersion,\n os,\n platform,\n deviceLocale: localeId.toString(),\n deviceNotificationEnabled,\n macAddress,\n }),\n });\n break;\n case 'facebook':\n response = await handleLogin({\n loginFn: () =>\n bzbsService.authApi.connectFacebook({\n accessToken: thirdPartyLoginData.accessToken,\n appId,\n uuid,\n deviceToken: fcmToken,\n clientVersion,\n os,\n platform,\n deviceLocale: localeId.toString(),\n deviceNotificationEnabled,\n macAddress,\n }),\n });\n break;\n case 'apple':\n response = await handleLogin({\n loginFn: () =>\n bzbsService.authApi.connectApple({\n idToken: thirdPartyLoginData.idToken,\n refreshToken: thirdPartyLoginData.refreshToken,\n appId,\n uuid,\n deviceToken: fcmToken,\n clientVersion,\n os,\n platform,\n deviceLocale: localeId.toString(),\n deviceNotificationEnabled,\n macAddress,\n }),\n });\n break;\n case 'line':\n response = await handleLogin({\n loginFn: () =>\n bzbsService.authApi.connectLine({\n idToken: thirdPartyLoginData.idToken,\n lineAccessToken: thirdPartyLoginData.lineAccessToken,\n authorizationCode: thirdPartyLoginData.authorizationCode,\n appId,\n uuid,\n deviceToken: fcmToken,\n clientVersion,\n os,\n platform,\n deviceLocale: localeId.toString(),\n deviceNotificationEnabled,\n macAddress,\n }),\n });\n }\n\n if (response.type === 'success') {\n set({ thirdPartyLoginData: undefined });\n }\n\n return response;\n },\n\n disconnectThirdParty: async (thirdParties: {\n facebook?: boolean;\n google?: boolean;\n apple?: boolean;\n line?: boolean;\n }) => {\n const bzbsService = useBuzzebeesAppStore.getState().bzbsService;\n\n if (!bzbsService) {\n return { type: 'client-error', message: 'Service not configured' };\n }\n\n set({ isLoading: true });\n const response = await bzbsService.authApi.disconnect({\n facebook: thirdParties.facebook,\n google: thirdParties.google,\n apple: thirdParties.apple,\n line: thirdParties.line,\n });\n set({ isLoading: false });\n if (response.type === 'success') {\n useUserStore.setState({\n thirdPartyConnection: {\n facebook: response.model.facebookId != null && response.model.facebookId !== '',\n google: response.model.googleId != null && response.model.googleId !== '',\n apple: response.model.appleId != null && response.model.appleId !== '',\n line: response.model.lineUserId != null && response.model.lineUserId !== '',\n },\n });\n }\n\n return response;\n },\n\n logout: async () => {\n const uuid = useBuzzebeesAppStore.getState().uuid;\n const bzbsService = useBuzzebeesAppStore.getState().bzbsService;\n\n if (!bzbsService) {\n return { type: 'client-error', message: 'Service or auth persistence not configured' };\n }\n\n set({ isLoading: true });\n const response = await bzbsService.authApi.logout({ uuid });\n set({ isLoading: false });\n\n get().clear();\n\n return response;\n },\n\n appleToken: async (authorizationCode: string, idToken: string) => {\n const { appId, os, platform, clientVersion, macAddress } = useBuzzebeesAppStore.getState();\n const bzbsService = useBuzzebeesAppStore.getState().bzbsService;\n if (!bzbsService) {\n return { type: 'client-error', message: 'Service not configured' };\n }\n\n set({ isLoading: true });\n const response = await bzbsService.authApi.appleToken({\n authorizationCode,\n idToken,\n appId,\n os,\n platform,\n macAddress,\n clientVersion,\n });\n set({ isLoading: false });\n return response;\n },\n\n forgetPassword: async (contact: string, type: 'email' | 'contact_number') => {\n const bzbsService = useBuzzebeesAppStore.getState().bzbsService;\n\n if (!bzbsService) {\n return { type: 'client-error', message: 'Service not configured' };\n }\n\n set({ isLoading: true });\n const response = await bzbsService.authApi.forgetPassword({ contact, type });\n set({ isLoading: false });\n return response;\n },\n\n resetPassword: async (contact: string, otp: string, refCode: string, password: string) => {\n const bzbsService = useBuzzebeesAppStore.getState().bzbsService;\n\n if (!bzbsService) {\n return { type: 'client-error', message: 'Service not configured' };\n }\n\n set({ isLoading: true });\n const response = await bzbsService.authApi.resetPassword({\n contact,\n otp,\n refCode,\n newPassword: password,\n });\n set({ isLoading: false });\n return response;\n },\n\n sendOtp: async (contact: string, channel: string) => {\n const uuid = useBuzzebeesAppStore.getState().uuid;\n const appId = useBuzzebeesAppStore.getState().appId;\n const bzbsService = useBuzzebeesAppStore.getState().bzbsService;\n\n if (!bzbsService) {\n return { type: 'client-error', message: 'Service not configured' };\n }\n\n set({ isLoading: true });\n const response = await bzbsService.authApi.otp({\n uuid,\n appId,\n contactNumber: contact,\n channel,\n });\n set({ isLoading: false });\n return response;\n },\n\n validateOtp: async (\n otp: string,\n refCode: string,\n contact: string,\n channel: string,\n type: 'email' | 'contact_number'\n ) => {\n const appId = useBuzzebeesAppStore.getState().appId;\n const bzbsService = useBuzzebeesAppStore.getState().bzbsService;\n\n if (!bzbsService) {\n return { type: 'client-error', message: 'Service not configured' };\n }\n\n set({ isLoading: true });\n const response = await bzbsService.authApi.validateOtp({\n appId,\n otp,\n refCode,\n contactNumber: contact,\n use: false,\n channel,\n type,\n });\n set({ isLoading: false });\n return response;\n },\n\n confirmOtp: async (otp: string, refCode: string, contact: string) => {\n const bzbsService = useBuzzebeesAppStore.getState().bzbsService;\n\n if (!bzbsService) {\n return { type: 'client-error', message: 'Service not configured' };\n }\n\n set({ isLoading: true });\n const response = await bzbsService.authApi.confirmOtp({\n otp,\n refCode,\n contactNumber: contact,\n });\n set({ isLoading: false });\n return response;\n },\n\n resume: async (clientVersion: string) => {\n const { uuid, appId, os, platform, fcmToken, macAddress } = useBuzzebeesAppStore.getState();\n const { tokenFunctions, tokenType } = useBuzzebeesAppStore.getState();\n const bzbsService = useBuzzebeesAppStore.getState().bzbsService;\n\n if (!bzbsService || !tokenFunctions) {\n return { type: 'client-error', message: 'Service or auth persistence not configured' };\n }\n\n set({ isLoading: true });\n const response = await bzbsService.authApi.resume({\n uuid,\n deviceAppId: appId,\n os,\n platform,\n deviceNotificationEnabled: true,\n clientVersion,\n deviceToken: fcmToken,\n macAddress,\n });\n set({ isLoading: false });\n\n if (response.type === 'success') {\n const token = tokenType === 'jwt' ? response.model.jwt! : response.model.token!;\n tokenFunctions.setToken(token);\n set({\n data: response.model,\n error: null,\n });\n } else {\n set({ error: response });\n }\n\n return response;\n },\n\n version: async (clientVersion: string) => {\n const bzbsService = useBuzzebeesAppStore.getState().bzbsService;\n\n if (!bzbsService) {\n return { type: 'client-error', message: 'Service not configured' };\n }\n\n set({ isLoading: true });\n const response = await bzbsService.authApi.versionRaw(clientVersion);\n set({ isLoading: false });\n\n if (response.type === 'success') {\n set({ versionData: response.model, rawVersionData: response.model });\n }\n\n return response;\n },\n\n clear: () => {\n const { tokenFunctions } = useBuzzebeesAppStore.getState();\n tokenFunctions?.removeToken();\n set({\n data: null,\n thirdPartyLoginData: undefined,\n versionData: null,\n isLoading: false,\n error: null,\n token: null,\n isLoggedIn: false,\n isDeviceLoggedIn: false,\n });\n },\n };\n});\n","import type { UserInfo } from 'matomo-tracker-react-native';\nimport { useAnalyti