Skip to content

Commit e3cbeae

Browse files
authored
feat: adding session log (#3279)
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Session validation now keeps locale, currency and sales channel in sync for a more consistent user experience. * Made localization settings retrieval available for integrations. * **Chores** * Added diagnostic trace logging to aid debugging. * Enabled production client-side source maps and inline source maps for the SDK build. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent 9115316 commit e3cbeae

2 files changed

Lines changed: 18 additions & 1 deletion

File tree

packages/core/src/sdk/localization/useLocalizationConfig.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ function getSettingsFromConfig(
8888
}
8989
}
9090

91-
function getSettings(params?: { url?: string | URL }) {
91+
export function getSettings(params?: { url?: string | URL }) {
9292
let url = params?.url ?? ''
9393
const defaultConfig = config.localization.locales[
9494
config.localization.defaultLocale

packages/core/src/sdk/session/index.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { cartStore } from '../cart'
1818
import { request } from '../graphql/request'
1919
import { createValidationStore, useStore } from '../useStore'
2020
import { getPostalCode } from '../userLocation/index'
21+
import { getSettings } from '../localization/useLocalizationConfig'
2122

2223
const SESSION_READY_KEY = 'faststore_session_ready'
2324

@@ -79,6 +80,22 @@ export const mutation = gql(`
7980
`)
8081

8182
export const validateSession = async (session: Session) => {
83+
const settings = getSettings()
84+
const newChanel = JSON.stringify({
85+
...(JSON.parse(session.channel ?? '{}') ?? {}),
86+
salesChannel: settings.salesChannel,
87+
})
88+
89+
if (
90+
newChanel !== session.channel ||
91+
settings.locale !== session.locale ||
92+
deepEqual(settings.currency, session.currency) === false
93+
) {
94+
session.locale = settings.locale
95+
session.currency = settings.currency
96+
session.channel = newChanel
97+
}
98+
8299
// If deliveryPromise is enabled and there is no postalCode in the session
83100
if (
84101
storeConfig.deliveryPromise?.enabled &&

0 commit comments

Comments
 (0)