Skip to content

Commit 9d7a8ff

Browse files
authored
Merge branch 'dev' into chore/VCST-2553-maska-input
2 parents 586b9d2 + e4619b7 commit 9d7a8ff

File tree

75 files changed

+1059
-774
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+1059
-774
lines changed

backend-packages.json

Lines changed: 156 additions & 154 deletions
Large diffs are not rendered by default.

client-app/app-runner.ts

Lines changed: 59 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { createHead } from "@unhead/vue/client";
22
import { DefaultApolloClient } from "@vue/apollo-composable";
33
import { createApp, h, provide } from "vue";
4-
import { apolloClient, getStore } from "@/core/api/graphql";
4+
import { apolloClient, getPageContext } from "@/core/api/graphql";
5+
import { GetSlugInfoDocument } from "@/core/api/graphql/types";
56
import { useCurrency, useThemeContext, useNavigations, useWhiteLabeling } from "@/core/composables";
67
import { useHotjar } from "@/core/composables/useHotjar";
78
import { useLanguages } from "@/core/composables/useLanguages";
@@ -35,7 +36,7 @@ import { templateBlocks } from "@/shared/static-content";
3536
import { uiKit } from "@/ui-kit";
3637
import { getLocales as getUIKitLocales } from "@/ui-kit/utilities/getLocales";
3738
import App from "./App.vue";
38-
import type { StoreResponseType } from "./core/api/graphql/types";
39+
import type { PageContextResponseType } from "./core/api/graphql/types";
3940

4041
// eslint-disable-next-line no-restricted-exports
4142
export default async () => {
@@ -66,7 +67,7 @@ export default async () => {
6667

6768
app.use(authPlugin);
6869

69-
const { fetchUser, user, isAuthenticated } = useUser();
70+
const { setUser, user, isAuthenticated, savedUserId } = useUser();
7071
const { themeContext, addPresetToThemeContext, setThemeContext } = useThemeContext();
7172
const {
7273
currentLanguage,
@@ -76,11 +77,13 @@ export default async () => {
7677
fetchLocaleMessages,
7778
mergeLocalesMessages,
7879
resolveLocale,
80+
getUrlWithoutPossibleLocale,
81+
resolvePossibleLocale,
7982
} = useLanguages();
8083
const { currentCurrency } = useCurrency();
8184
const { init: initializeHotjar } = useHotjar();
8285
const { fetchCatalogMenu } = useNavigations();
83-
const { themePresetName, fetchWhiteLabelingSettings } = useWhiteLabeling();
86+
const { themePresetName, setWhiteLabelingSettings } = useWhiteLabeling();
8487

8588
const fallback = {
8689
locale: FALLBACK_LOCALE,
@@ -90,18 +93,41 @@ export default async () => {
9093
},
9194
};
9295

93-
const storePromise = getStore(
94-
IS_DEVELOPMENT ? extractHostname(import.meta.env.APP_BACKEND_URL as string) : window.location.hostname,
95-
) as Promise<StoreResponseType>;
96+
// get initialization query parameters
97+
const pathname = globalThis.location.pathname;
98+
const possibleCultureName = resolvePossibleLocale(pathname);
99+
const permalink = getPermalink(pathname, getUrlWithoutPossibleLocale);
96100

97-
const [store] = await Promise.all([storePromise, fetchUser(), fallback.setMessage()]);
101+
const domain = IS_DEVELOPMENT
102+
? extractHostname(import.meta.env.APP_BACKEND_URL as string)
103+
: globalThis.location.hostname;
104+
const userId = savedUserId.value;
105+
106+
const getPageContextPromise = getPageContext({
107+
domain: domain,
108+
userId: userId,
109+
permalink: permalink,
110+
cultureName: possibleCultureName,
111+
}) as Promise<PageContextResponseType>;
112+
113+
const [pageContext] = await Promise.all([getPageContextPromise, fallback.setMessage()]);
114+
115+
const store = pageContext.store;
116+
const userResult = pageContext.user;
117+
const whiteLabelingSetting = pageContext.whiteLabelingSettings;
98118

99119
if (!store) {
100120
alert("Related store not found. Please contact your site administrator.");
101-
throw new Error("Store not found. Check graphql request, GetStore query");
121+
throw new Error("Store not found. Check graphql request, PageContext query");
122+
}
123+
124+
if (!userResult) {
125+
alert("Error fetching user. Please contact your site administrator.");
126+
throw new Error("Error fetching user. Check graphql request, PageContext query");
102127
}
103128

104129
setThemeContext(store);
130+
setUser(userResult);
105131

106132
/**
107133
* Creating plugin instances
@@ -131,11 +157,28 @@ export default async () => {
131157
currencyCode: currentCurrency.value.code,
132158
});
133159

160+
// Seed Apollo cache with initial slugInfo from pageContext to avoid the first network call
161+
try {
162+
const baseVariables = {
163+
userId: user.value.id,
164+
storeId: themeContext.value.storeId,
165+
cultureName: currentLanguage.value.cultureName,
166+
} as const;
167+
168+
apolloClient.writeQuery({
169+
query: GetSlugInfoDocument,
170+
variables: { ...baseVariables, permalink },
171+
data: { slugInfo: pageContext.slugInfo },
172+
});
173+
} catch (e) {
174+
Logger.warn("Failed to seed slugInfo into Apollo cache", e as Error);
175+
}
176+
134177
/**
135178
* Other settings
136179
*/
137180

138-
await fetchWhiteLabelingSettings();
181+
setWhiteLabelingSettings(whiteLabelingSetting);
139182
addPresetToThemeContext(themePresetName.value ?? themeContext.value.defaultPresetName);
140183

141184
if (isAuthenticated.value || themeContext.value.storeSettings.anonymousUsersAllowed) {
@@ -207,3 +250,9 @@ export default async () => {
207250

208251
app.mount(appElement);
209252
};
253+
254+
function getPermalink(permalink: string, getUrlWithoutPossibleLocale: (fullPath: string) => string) {
255+
permalink = getUrlWithoutPossibleLocale(permalink);
256+
permalink = permalink === "/" ? "/" : permalink.replace(/^\/+/, "");
257+
return permalink;
258+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
fragment slugInfoResponseTypeFields on SlugInfoResponseType {
2+
entityInfo {
3+
id
4+
isActive
5+
languageCode
6+
objectId
7+
objectType
8+
semanticUrl
9+
metaDescription
10+
metaKeywords
11+
pageTitle
12+
outline
13+
}
14+
redirectUrl
15+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#import "./allCurrencyFields.graphql"
2+
#import "./allLanguageFields.graphql"
3+
4+
fragment storeResponseTypeFields on StoreResponseType {
5+
storeId
6+
storeName
7+
catalogId
8+
storeUrl
9+
defaultLanguage {
10+
...allLanguageFields
11+
}
12+
availableLanguages {
13+
...allLanguageFields
14+
}
15+
defaultCurrency {
16+
...allCurrencyFields
17+
}
18+
availableCurrencies {
19+
...allCurrencyFields
20+
}
21+
settings {
22+
authenticationTypes
23+
subscriptionEnabled
24+
taxCalculationEnabled
25+
anonymousUsersAllowed
26+
environmentName
27+
emailVerificationEnabled
28+
emailVerificationRequired
29+
createAnonymousOrderEnabled
30+
seoLinkType
31+
defaultSelectedForCheckout
32+
passwordRequirements {
33+
requireLowercase
34+
requireUppercase
35+
requireDigit
36+
requiredLength
37+
requiredUniqueChars
38+
requireNonAlphanumeric
39+
}
40+
modules {
41+
moduleId
42+
settings {
43+
name
44+
value
45+
}
46+
}
47+
}
48+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
fragment userTypeFields on UserType {
2+
id
3+
memberId
4+
userName
5+
email
6+
emailConfirmed
7+
photoUrl
8+
phoneNumber
9+
permissions
10+
isAdministrator
11+
passwordExpired
12+
passwordExpiryInDays
13+
forcePasswordChange
14+
lockedState
15+
contact {
16+
id
17+
firstName
18+
lastName
19+
fullName
20+
organizationId
21+
defaultLanguage
22+
currencyCode
23+
selectedAddressId
24+
organizations {
25+
items {
26+
id
27+
name
28+
}
29+
}
30+
}
31+
operator {
32+
userName
33+
contact {
34+
fullName
35+
}
36+
}
37+
roles {
38+
name
39+
}
40+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
fragment whiteLabelingFields on WhiteLabelingSettingsType {
2+
logoUrl
3+
secondaryLogoUrl
4+
themePresetName
5+
isOrganizationLogoUploaded
6+
favicons {
7+
rel
8+
type
9+
sizes
10+
href
11+
}
12+
footerLinks {
13+
title
14+
url
15+
priority
16+
childItems {
17+
title
18+
url
19+
priority
20+
}
21+
}
22+
}

client-app/core/api/graphql/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export * from "./fulfillmentCenters";
77
export * from "./orders";
88
export * from "./organization";
99
export * from "./page";
10+
export * from "./pageContext";
1011
export * from "./payment";
1112
export * from "./slugInfo";
1213
export * from "./store";
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from "./queries/getPageContext";
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#import "../../../fragments/storeFields.graphql"
2+
#import "../../../fragments/slugInfoFields.graphql"
3+
#import "../../../fragments/userFields.graphql"
4+
#import "../../../fragments/whiteLabelingFields.graphql"
5+
6+
query GetPageContext(
7+
$userId: String
8+
$organizationId: String
9+
$domain: String
10+
$storeId: String
11+
$permalink: String
12+
$cultureName: String
13+
) {
14+
pageContext(
15+
userId: $userId
16+
organizationId: $organizationId
17+
domain: $domain
18+
storeId: $storeId
19+
permalink: $permalink
20+
cultureName: $cultureName
21+
) {
22+
user {
23+
...userTypeFields
24+
}
25+
store {
26+
...storeResponseTypeFields
27+
}
28+
slugInfo {
29+
...slugInfoResponseTypeFields
30+
}
31+
whiteLabelingSettings {
32+
...whiteLabelingFields
33+
}
34+
}
35+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { GetPageContextDocument } from "@/core/api/graphql/types";
2+
import { graphqlClient } from "../../../client";
3+
import type { GetPageContextQueryVariables } from "@/core/api/graphql/types";
4+
5+
export async function getPageContext(payload: GetPageContextQueryVariables) {
6+
const { data } = await graphqlClient.query({
7+
query: GetPageContextDocument,
8+
variables: payload,
9+
});
10+
11+
return data.pageContext;
12+
}

0 commit comments

Comments
 (0)