@treely/strapi-slices 5.11.3 → 5.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/ContextProvider/ContextProvider.d.ts +1 -2
- package/dist/constants/strapi.d.ts +1 -0
- package/dist/index.d.ts +6 -3
- package/dist/integrations/strapi/getAllSlugsFromStrapi.d.ts +10 -0
- package/dist/integrations/strapi/getStaticPathsFromStrapi.d.ts +1 -0
- package/dist/integrations/strapi/getStaticPropsFromStrapi.d.ts +1 -0
- package/dist/integrations/strapi/getStrapiCollectionType.d.ts +10 -0
- package/dist/integrations/strapi/getStrapiSingleType.d.ts +8 -0
- package/dist/models/Locale.d.ts +3 -1
- package/dist/models/LocalizedEntity.d.ts +7 -0
- package/dist/models/strapi/StrapiGlobal.d.ts +2 -0
- package/dist/strapi-slices.cjs.development.js +197 -27
- package/dist/strapi-slices.cjs.development.js.map +1 -1
- package/dist/strapi-slices.cjs.production.min.js +1 -1
- package/dist/strapi-slices.cjs.production.min.js.map +1 -1
- package/dist/strapi-slices.esm.js +197 -30
- package/dist/strapi-slices.esm.js.map +1 -1
- package/dist/utils/getMessages.d.ts +142 -0
- package/package.json +1 -1
- package/src/components/ContextProvider/ContextProvider.tsx +3 -5
- package/src/components/MinimalProviders/MinimalProviders.tsx +2 -8
- package/src/constants/strapi.ts +2 -0
- package/src/index.tsx +8 -2
- package/src/integrations/strapi/getAllSlugsFromStrapi.test.ts +33 -0
- package/src/integrations/strapi/getAllSlugsFromStrapi.ts +50 -0
- package/src/integrations/strapi/getPortfolioProjects.test.ts +24 -0
- package/src/integrations/strapi/getPortfolioProjects.ts +25 -5
- package/src/integrations/strapi/getStaticPathsFromStrapi.ts +1 -0
- package/src/integrations/strapi/getStaticPropsFromStrapi.ts +1 -0
- package/src/integrations/strapi/getStrapiCollectionType.test.ts +65 -0
- package/src/integrations/strapi/getStrapiCollectionType.ts +61 -0
- package/src/integrations/strapi/getStrapiSingleType.test.ts +53 -0
- package/src/integrations/strapi/getStrapiSingleType.ts +50 -0
- package/src/models/Locale.ts +3 -1
- package/src/models/LocalizedEntity.ts +9 -0
- package/src/models/strapi/StrapiGlobal.ts +2 -0
- package/src/test/strapiMocks/minimalGlobalData.ts +1 -0
- package/src/utils/getMessages.ts +18 -0
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { AxiosResponse } from 'axios';
|
|
2
|
+
import strapiClient from './strapiClient';
|
|
3
|
+
import {
|
|
4
|
+
STRAPI_DEFAULT_PAGE_SIZE,
|
|
5
|
+
STRAPI_FALLBACK_LOCALE,
|
|
6
|
+
} from '../../constants/strapi';
|
|
7
|
+
import IStrapiData from '../../models/strapi/IStrapiData';
|
|
8
|
+
import IStrapiResponse from '../../models/strapi/IStrapiResponse';
|
|
9
|
+
|
|
10
|
+
interface Options {
|
|
11
|
+
locale?: string;
|
|
12
|
+
preview?: boolean;
|
|
13
|
+
filters?: Record<string, any>;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const getStrapiSingleType = async <T>(
|
|
17
|
+
path: string,
|
|
18
|
+
{ locale = 'en', preview = false, filters = {} }: Options
|
|
19
|
+
): Promise<IStrapiData<T>> => {
|
|
20
|
+
const params: Record<string, any> = {
|
|
21
|
+
populate: 'deep,6',
|
|
22
|
+
locale,
|
|
23
|
+
'pagination[pageSize]': STRAPI_DEFAULT_PAGE_SIZE,
|
|
24
|
+
filters,
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
if (preview) {
|
|
28
|
+
params.publicationState = 'preview';
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
let response: AxiosResponse<IStrapiResponse<IStrapiData<T>>>;
|
|
32
|
+
|
|
33
|
+
try {
|
|
34
|
+
response = await strapiClient.get(path, { params });
|
|
35
|
+
return response.data.data;
|
|
36
|
+
} catch (error: any) {
|
|
37
|
+
if (error.isAxiosError && error.response?.status === 404) {
|
|
38
|
+
// Retry request with fallback locale
|
|
39
|
+
response = await strapiClient.get(path, {
|
|
40
|
+
params: { ...params, locale: STRAPI_FALLBACK_LOCALE },
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
return response.data.data;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
throw error;
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
export default getStrapiSingleType;
|
package/src/models/Locale.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import Locale from '../Locale';
|
|
1
2
|
import IStrapi from './IStrapi';
|
|
2
3
|
import IStrapiData from './IStrapiData';
|
|
3
4
|
import StrapiBanner from './StrapiBanner';
|
|
@@ -9,6 +10,7 @@ import StrapiNavMenu from './StrapiNavMenu';
|
|
|
9
10
|
import StrapiTopBanner from './StrapiTopBanner';
|
|
10
11
|
|
|
11
12
|
interface StrapiGlobal {
|
|
13
|
+
locale: Locale;
|
|
12
14
|
metadata: StrapiMetadata;
|
|
13
15
|
favicon: IStrapi<IStrapiData<StrapiMedia>>;
|
|
14
16
|
metaTitleSuffix: string;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { STRAPI_FALLBACK_LOCALE } from '../constants/strapi';
|
|
2
|
+
import rootMessagesDe from '../rootMessages.de';
|
|
3
|
+
import rootMessagesEn from '../rootMessages.en';
|
|
4
|
+
|
|
5
|
+
const messages = {
|
|
6
|
+
en: rootMessagesEn,
|
|
7
|
+
de: rootMessagesDe,
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
const getMessages = (locale: string) => {
|
|
11
|
+
const messagesLocale = Object.keys(messages).includes(`${locale}`)
|
|
12
|
+
? (locale as keyof typeof messages)
|
|
13
|
+
: STRAPI_FALLBACK_LOCALE;
|
|
14
|
+
|
|
15
|
+
return messages[messagesLocale];
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export default getMessages;
|