|
|
@@ -12,14 +12,10 @@ import {
|
|
|
CURRENT_CHANNEL,
|
|
|
} from "@/utils/constants";
|
|
|
import {
|
|
|
- GET_FOOTER,
|
|
|
PAGE_BY_URL_KEY,
|
|
|
} from "@/graphql";
|
|
|
import { SUBSCRIBE_TO_NEWSLETTER } from "@/graphql/theme/mutations";
|
|
|
-import { cachedGraphQLRequest } from "@/utils/hooks/useCache";
|
|
|
import type {
|
|
|
- GetFooterResponse,
|
|
|
- ThemeCustomizationResult,
|
|
|
PageData,
|
|
|
} from "@/types/theme/theme-customization";
|
|
|
import type {FetchGraphqlResult} from "@/types/graphqlFetch/type";
|
|
|
@@ -128,12 +124,6 @@ export async function restApiFetch<T>({
|
|
|
revalidate?: number;
|
|
|
takeAuthorization?: boolean;
|
|
|
}): Promise<{ status: number; body: ExtractRestFulData<T> } | never> {
|
|
|
- try {
|
|
|
- const apiUrl = api.startsWith("http") ? api : `${REST_API_URL}${api}`;
|
|
|
- const url = new URL(apiUrl);
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
const headerRes = await getBaseHeader();
|
|
|
const baseHeaders: Record<string, string> = {...headerRes};
|
|
|
|
|
|
@@ -143,7 +133,9 @@ export async function restApiFetch<T>({
|
|
|
baseHeaders.Authorization = `Bearer ${tokenRes.token}`;
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+ try {
|
|
|
+ const apiUrl = api.startsWith("http") ? api : `${REST_API_URL}${api}`;
|
|
|
+ const url = new URL(apiUrl);
|
|
|
|
|
|
if (headers) {
|
|
|
if (headers instanceof Headers) {
|
|
|
@@ -213,19 +205,16 @@ export async function serverGraphqlFetch<
|
|
|
revalidate?: number;
|
|
|
takeAuthorization?: boolean;
|
|
|
}): Promise<FetchGraphqlResult<TData>> {
|
|
|
- try {
|
|
|
- const queryString = typeof query === "string" ? query : print(query);
|
|
|
-
|
|
|
-
|
|
|
- const headerRes = await getBaseHeader();
|
|
|
- const baseHeaders: Record<string, string> = {...headerRes};
|
|
|
-
|
|
|
- if(takeAuthorization) {
|
|
|
+ const headerRes = await getBaseHeader();
|
|
|
+ const baseHeaders: Record<string, string> = {...headerRes};
|
|
|
+ if(takeAuthorization) {
|
|
|
const tokenRes = await getAuthorizationToken();
|
|
|
if (tokenRes.token) {
|
|
|
baseHeaders['Authorization'] = `Bearer ${tokenRes.token}`;
|
|
|
}
|
|
|
- }
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ const queryString = typeof query === "string" ? query : print(query);
|
|
|
|
|
|
if (headers) {
|
|
|
if (headers instanceof Headers) {
|
|
|
@@ -291,11 +280,6 @@ export async function bagistoFetch<T>({
|
|
|
takeAuthorization?: boolean;
|
|
|
revalidate?: number;
|
|
|
}): Promise<{ status: number; body: ExtractGraphqlData<T> } | never> {
|
|
|
- try {
|
|
|
- const queryString =
|
|
|
- typeof query === "string" ? query : print(query);
|
|
|
-
|
|
|
-
|
|
|
const headerRes = await getBaseHeader();
|
|
|
const baseHeaders: Record<string, string> = {...headerRes};
|
|
|
|
|
|
@@ -306,9 +290,9 @@ export async function bagistoFetch<T>({
|
|
|
}
|
|
|
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+ try {
|
|
|
+ const queryString =
|
|
|
+ typeof query === "string" ? query : print(query);
|
|
|
|
|
|
if (headers) {
|
|
|
if (headers instanceof Headers) {
|
|
|
@@ -366,31 +350,6 @@ export async function subscribeUser(
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-export async function getThemeCustomization(): Promise<ThemeCustomizationResult> {
|
|
|
- try {
|
|
|
- const [{data: footerRes}, {data:servicesRes}] = await Promise.all([
|
|
|
- cachedGraphQLRequest<GetFooterResponse>("static", GET_FOOTER, {
|
|
|
- type: "footer_links",
|
|
|
- }),
|
|
|
- cachedGraphQLRequest<GetFooterResponse>("static", GET_FOOTER, {
|
|
|
- type: "services_content",
|
|
|
- }),
|
|
|
- ]);
|
|
|
-
|
|
|
- return {
|
|
|
- footer_links: footerRes,
|
|
|
- services_content: servicesRes,
|
|
|
- };
|
|
|
- } catch (err) {
|
|
|
- console.error("ThemeCustomization Error:", err);
|
|
|
- }
|
|
|
-
|
|
|
- return {
|
|
|
- footer_links: null,
|
|
|
- services_content: null,
|
|
|
- };
|
|
|
-}
|
|
|
-
|
|
|
|
|
|
export async function getPage(input: { urlKey: string }): Promise<PageData[]> {
|
|
|
const res = await bagistoFetch<{
|