Skip to content

Commit 201dbb5

Browse files
authored
Merge branch 'main' into alive-dev
2 parents d8e77c5 + 5643102 commit 201dbb5

File tree

5 files changed

+109
-48
lines changed

5 files changed

+109
-48
lines changed

wp-react-lib/.changeset/honest-pumas-look.md

Lines changed: 0 additions & 5 deletions
This file was deleted.

wp-react-lib/CHANGELOG.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,52 @@
11
# @devgateway/wp-react-lib
22

3+
## 0.6.0
4+
5+
### Minor Changes
6+
7+
- 6c19194: Removing data attributes from components container,and some other small fixes
8+
9+
## 0.5.1
10+
11+
### Patch Changes
12+
13+
- 62fca36: fix wp search endpoint
14+
15+
## 0.5.0
16+
17+
### Minor Changes
18+
19+
This release introduces a minor version update to the @devgateway/wp-react-lib package, primarily focused on improving API endpoint handling for server-side rendering (SSR) scenarios. The main enhancement is the support for dynamic base URLs, allowing the library to better adapt to different SSR contexts.
20+
21+
API improvements:
22+
23+
- Updated API endpoint handling to support dynamic base URLs for SSR contexts, increasing flexibility for server-side rendering environments.
24+
- e5b7db3: update API endpoint handling to support dynamic base URLs for SSR contexts
25+
26+
## 0.4.8
27+
28+
### Patch Changes
29+
30+
- a949690: Remove sub-imports to remain with the main import
31+
32+
## 0.4.7
33+
34+
### Patch Changes
35+
36+
- 7174745: fix env variables imports
37+
38+
## 0.4.6
39+
40+
### Patch Changes
41+
42+
- 2e20f93: Standardize dependencies for consitency
43+
44+
## 0.4.5
45+
46+
### Patch Changes
47+
48+
- 8bf45ce: Upgrade dependencies to fix CVEs
49+
350
## 0.4.4
451

552
### Patch Changes

wp-react-lib/package.json

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,32 +12,31 @@
1212
"types": "dist/types/index.d.ts",
1313
"license": "MIT",
1414
"dependencies": {
15-
"immutable": "^4.3.7",
15+
"immutable": "^5.1.3",
1616
"react": "^18.3.1",
1717
"react-dom": "^18.3.1",
18-
"react-intl": "^6.8.0",
19-
"react-redux": "^9.1.2",
18+
"react-intl": "^7.1.14",
19+
"react-redux": "^9.2.0",
2020
"semantic-ui-react": "^3.0.0-beta.2"
2121
},
2222
"devDependencies": {
23-
"@changesets/cli": "^2.29.4",
23+
"@changesets/cli": "^2.29.7",
2424
"@types/node": "^22.15.19",
2525
"@types/react": "18.3.11",
2626
"@types/react-dom": "18.3.1",
2727
"@vitejs/plugin-react": "^4.4.1",
2828
"rollup-plugin-preserve-directives": "^0.4.0",
29-
"typescript": "^5.8.3",
30-
"vite": "^6.3.5",
29+
"typescript": "^5.9.3",
30+
"vite": "^6.3.6",
3131
"vite-plugin-dts": "^4.5.4",
32-
"vite-tsconfig-paths": "^5.1.4",
33-
"watch": "^1.0.2"
32+
"vite-tsconfig-paths": "^5.1.4"
3433
},
3534
"peerDependencies": {
36-
"immutable": "^4.3.7",
35+
"immutable": "^5.1.3",
3736
"react": "^18.3.1",
3837
"react-dom": "^18.3.1",
39-
"react-intl": "^6.8.0",
40-
"react-redux": "^9.1.2",
38+
"react-intl": "^7.1.14",
39+
"react-redux": "^9.2.0",
4140
"semantic-ui-react": "^3.0.0-beta.2"
4241
},
4342
"scripts": {

wp-react-lib/src/api/index.ts

Lines changed: 51 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
11
import type { PageResponse } from "../post-type"
22
import type { DgSettings, Media } from "../types"
33

4-
const API_ROOT = process.env.VITE_REACT_APP_WP_API ?? '/wp/wp-json'
5-
const URL_MENU = API_ROOT + '/menus/v1/menus/'
4+
// @ts-ignore Types not available
5+
const API_ROOT = import.meta.env.VITE_REACT_APP_WP_API ?? process.env.VITE_REACT_APP_WP_API ?? '/wp/wp-json'
6+
// const URL_MENU = API_ROOT + '/menus/v1/menus/'
67

7-
const URL_API_BASE = API_ROOT + '/wp/v2/'
8+
// const URL_API_BASE = API_ROOT + '/wp/v2/'
89

9-
const URL_PAGE = API_ROOT + '/wp/v2/pages'
10+
// const URL_PAGE = API_ROOT + '/wp/v2/pages'
11+
// // @ts-ignore
12+
// const URL_SEARCH = API_ROOT + (import.meta.env.VITE_REACT_APP_WP_SEARCH_END_POINT ?? process.env.VITE_REACT_APP_WP_SEARCH_END_POINT ?? '/wp/v2/search')
1013

11-
const URL_SEARCH = API_ROOT + (process.env.VITE_REACT_APP_WP_SEARCH_END_POINT ?? '/wp/v2/search')
14+
// const URL_MEDIA = API_ROOT + '/wp/v2/media'
1215

13-
const URL_MEDIA = API_ROOT + '/wp/v2/media'
16+
// const URL_SETTINGS = API_ROOT + '/dg/v1/settings';
1417

15-
const URL_SETTINGS = API_ROOT + '/dg/v1/settings';
18+
// const URL_CATEGORIES = API_ROOT + '/wp/v2/categories'
1619

17-
const URL_CATEGORIES = API_ROOT + '/wp/v2/categories'
18-
19-
const URL_YEAR_RANGE = API_ROOT + '/util-api/v1/year-range'
20+
// const URL_YEAR_RANGE = API_ROOT + '/util-api/v1/year-range'
2021

2122

2223
export const post = (url: string, params: Record<string, unknown>, isBlob?: boolean) => {
@@ -59,6 +60,7 @@ export const post = (url: string, params: Record<string, unknown>, isBlob?: bool
5960
})
6061
}
6162
export const get = (url: string, _params: Record<string, unknown> = {}) => {
63+
console.log("get", url);
6264
return new Promise((resolve, reject) => {
6365

6466
fetch(url, {credentials: 'include'})
@@ -91,25 +93,29 @@ export const queryParams = (params: Record<string, any>) => {
9193
}
9294

9395

94-
export const getTaxonomy = (name: string, locale: string) => {
95-
return get(URL_API_BASE + "" + name + '?lang=' + locale + '&per_page=100')
96+
export const getTaxonomy = (name: string, locale: string, apiBaseUrl: string = API_ROOT + '/wp/v2/') => {
97+
const apiUrl = apiBaseUrl + "/wp/v2/"
98+
return get(apiUrl + "" + name + '?lang=' + locale + '&per_page=100')
9699

97100
}
98101

99102
//TODO:make a unique getPost method
100103
export const getPostsByTypeAndTaxonomy = (
101-
{type, category, value, locale, page = 1, perPage = 1}:
102-
{type: string, category: string, value: string, locale: string, page?: number, perPage?: number}) => {
103-
return get(URL_API_BASE + type + "?_embed&" + category + '=' + value + '&lang=' + locale + '&per_page=' + perPage + '&page=' + page)
104+
{type, category, value, locale, page = 1, perPage = 1, apiBaseUrl}:
105+
{type: string, category: string, value: string, locale: string, page?: number, perPage?: number, apiBaseUrl?: string}) => {
106+
const apiUrl = apiBaseUrl ? apiBaseUrl + "/wp/v2/" : API_ROOT + '/wp/v2/';
107+
return get(apiUrl + type + "?_embed&" + category + '=' + value + '&lang=' + locale + '&per_page=' + perPage + '&page=' + page)
104108
}
105109

106110

107-
export const getSettings=(locale: string,changeUUID?: string) : Promise<DgSettings> =>{
108-
return get(URL_SETTINGS+'?cacheBust='+((Math.random() + 1).toString(36).substring(7))+'&lang='+locale+(changeUUID?'&customize_changeset_uuid='+changeUUID:'')) as Promise<DgSettings>
111+
export const getSettings=(locale: string,changeUUID?: string, apiBaseUrl?: string) : Promise<DgSettings> =>{
112+
const apiUrl = apiBaseUrl ? apiBaseUrl + "/dg/v1/settings" : API_ROOT + '/dg/v1/settings';
113+
return get(apiUrl+'?cacheBust='+((Math.random() + 1).toString(36).substring(7))+'&lang='+locale+(changeUUID?'&customize_changeset_uuid='+changeUUID:'')) as Promise<DgSettings>
109114
}
110115

111-
export const getMenu = (name: string, locale: string) => {
112-
return get(URL_MENU + name + '?lang=' + locale)
116+
export const getMenu = (name: string, locale: string, apiBaseUrl?: string) => {
117+
const apiUrl = apiBaseUrl ? apiBaseUrl + "/menus/v1/menus/" : API_ROOT + '/menus/v1/menus/';
118+
return get(apiUrl + name + '?lang=' + locale)
113119
}
114120

115121
export const getPosts = ({
@@ -125,7 +131,8 @@ export const getPosts = ({
125131
previewNonce,
126132
previewId,
127133
search,
128-
after
134+
after,
135+
apiBaseUrl
129136
}: {
130137
slug?: string;
131138
type?: string;
@@ -140,9 +147,11 @@ export const getPosts = ({
140147
previewId?: string;
141148
search?: string;
142149
after?: Date;
150+
apiBaseUrl?: string;
143151
}) => {
144152

145-
let url = URL_API_BASE + (type ?? 'posts')
153+
let url = apiBaseUrl ? apiBaseUrl + "/wp/v2/" : API_ROOT + '/wp/v2/';
154+
url += (type ?? 'posts')
146155

147156
if (previewId) {
148157
url += '/' + previewId + '/revisions'
@@ -190,7 +199,8 @@ export const getPages = ({
190199
previewNonce,
191200
previewId,
192201
search,
193-
noCache
202+
noCache,
203+
apiBaseUrl
194204
}: {
195205
before?: Date;
196206
perPage?: number;
@@ -203,8 +213,9 @@ export const getPages = ({
203213
previewId?: string;
204214
search?: string;
205215
noCache?: boolean;
216+
apiBaseUrl?: string;
206217
}) => {
207-
let url = URL_PAGE
218+
let url = apiBaseUrl ? apiBaseUrl + "/wp/v2/pages" : API_ROOT + '/wp/v2/pages'
208219

209220
if (previewId) {
210221
url += '/' + previewId + '/revisions'
@@ -224,6 +235,7 @@ export const getPages = ({
224235
+ (search ? '&search=' + search : '')
225236
+ (noCache ? '&cacheBust='+((Math.random() + 1).toString(36).substring(7)) : '')
226237
}
238+
console.log("url==>", url);
227239
return get(url) as Promise<PageResponse>
228240
}
229241

@@ -234,8 +246,10 @@ export const search = (
234246
search?: string,
235247
type?: string,
236248
subtype?: string,
237-
locale?: string) => {
238-
let url = URL_SEARCH + '?lang=' + locale
249+
locale?: string,
250+
apiBaseUrl?: string) => {
251+
let url = apiBaseUrl ? apiBaseUrl + "/dg/v1/search" : API_ROOT + '/dg/v1/search';
252+
url += '?lang=' + locale
239253
+ (context ? "&context=" + context : '')
240254
+ (perPage ? '&per_page=' + perPage : '')
241255
+ (page ? '&page=' + page : '')
@@ -246,8 +260,9 @@ export const search = (
246260
return get(url)
247261
}
248262

249-
export const getMedia = (slug: string, locale: string) : Promise<Media> => {
250-
return get(URL_MEDIA + '/' + slug + '?lang=' + locale) as Promise<Media>;
263+
export const getMedia = (slug: string, locale: string, apiBaseUrl?: string) : Promise<Media> => {
264+
const apiUrl = apiBaseUrl ? apiBaseUrl + "/wp/v2/media" : API_ROOT + '/wp/v2/media';
265+
return get(apiUrl + '/' + slug + '?lang=' + locale) as Promise<Media>;
251266
}
252267

253268
export const getCategories = ({
@@ -263,7 +278,8 @@ export const getCategories = ({
263278
parent,
264279
post,
265280
slug,
266-
locale
281+
locale,
282+
apiBaseUrl
267283
}: {
268284
context?: string;
269285
page?: number;
@@ -278,8 +294,10 @@ export const getCategories = ({
278294
post?: string;
279295
slug?: string;
280296
locale?: string;
297+
apiBaseUrl?: string;
281298
})=> {
282-
let url = URL_CATEGORIES + '?lang=' + locale
299+
const apiUrl = apiBaseUrl ? apiBaseUrl + "/wp/v2/categories" : API_ROOT + '/wp/v2/categories';
300+
let url = apiUrl + '?lang=' + locale
283301
+ (context ? '&context=' + context : '')
284302
+ (page ? '&page=' + page : '')
285303
+ (perPage ? '&per_page=' + perPage : '')
@@ -295,6 +313,8 @@ export const getCategories = ({
295313
return get(url)
296314
}
297315

298-
export const getYearRange = () => {
299-
return get(URL_YEAR_RANGE)
316+
export const getYearRange = (apiBaseUrl?: string) => {
317+
const apiUrl = apiBaseUrl ? apiBaseUrl + "/util-api/v1/year-range" : API_ROOT + '/util-api/v1/year-range';
318+
319+
return get(apiUrl)
300320
}

wp-react-lib/vite.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export default defineConfig({
2222
copyPublicDir: false,
2323
lib: {
2424
entry: resolve(__dirname, 'src/index.js'),
25-
name: '@devgateway/dvz-ui'
25+
name: '@devgateway/wp-react-lib'
2626
},
2727
commonjsOptions: {
2828
transformMixedEsModules: true,

0 commit comments

Comments
 (0)