@marvalt/wadapter 2.3.11 → 2.3.14
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/client/wordpress-client.d.ts +40 -0
- package/dist/client/wordpress-client.d.ts.map +1 -1
- package/dist/generators/wordpress/wordpress-generator.d.ts.map +1 -1
- package/dist/generators.cjs +130 -16
- package/dist/generators.cjs.map +1 -1
- package/dist/generators.esm.js +130 -16
- package/dist/generators.esm.js.map +1 -1
- package/dist/gravity-forms/gravity-forms-client.d.ts.map +1 -1
- package/dist/index.d.ts +40 -0
- package/dist/index.esm.js +95 -6
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +95 -6
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -58,6 +58,12 @@ class WordPressClient {
|
|
|
58
58
|
const credentials = btoa(`${this.config.username}:${this.config.password}`);
|
|
59
59
|
headers.Authorization = `Basic ${credentials}`;
|
|
60
60
|
}
|
|
61
|
+
// Add Cloudflare Access Service Token headers if provided (for CF Access protected APIs)
|
|
62
|
+
if (this.config.cfAccessClientId && this.config.cfAccessClientSecret) {
|
|
63
|
+
headers['CF-Access-Client-Id'] = this.config.cfAccessClientId;
|
|
64
|
+
headers['CF-Access-Client-Secret'] = this.config.cfAccessClientSecret;
|
|
65
|
+
console.log('🔐 Added CF Access Service Token headers to WordPress request');
|
|
66
|
+
}
|
|
61
67
|
}
|
|
62
68
|
console.log('🔍 WordPress API Request Debug:', {
|
|
63
69
|
url,
|
|
@@ -111,29 +117,102 @@ class WordPressClient {
|
|
|
111
117
|
return this.config.apiUrl || '';
|
|
112
118
|
}
|
|
113
119
|
}
|
|
120
|
+
/**
|
|
121
|
+
* Fetch posts with automatic pagination support
|
|
122
|
+
* @param params Query parameters including per_page for total items to fetch
|
|
123
|
+
* @returns All posts up to the limit, fetched across multiple pages if needed
|
|
124
|
+
*/
|
|
114
125
|
async getPosts(params = {}) {
|
|
115
|
-
return this.
|
|
126
|
+
return this.fetchPaginated('/wp/v2/posts', params);
|
|
116
127
|
}
|
|
117
128
|
async getPost(id) {
|
|
118
129
|
return this.makeRequest(`/wp/v2/posts/${id}`);
|
|
119
130
|
}
|
|
131
|
+
/**
|
|
132
|
+
* Fetch pages with automatic pagination support
|
|
133
|
+
* @param params Query parameters including per_page for total items to fetch
|
|
134
|
+
* @returns All pages up to the limit, fetched across multiple pages if needed
|
|
135
|
+
*/
|
|
120
136
|
async getPages(params = {}) {
|
|
121
|
-
return this.
|
|
137
|
+
return this.fetchPaginated('/wp/v2/pages', params);
|
|
122
138
|
}
|
|
123
139
|
async getPage(id) {
|
|
124
140
|
return this.makeRequest(`/wp/v2/pages/${id}`);
|
|
125
141
|
}
|
|
142
|
+
/**
|
|
143
|
+
* Fetch media with automatic pagination support
|
|
144
|
+
* @param params Query parameters including per_page for total items to fetch
|
|
145
|
+
* @returns All media items up to the limit, fetched across multiple pages if needed
|
|
146
|
+
*/
|
|
126
147
|
async getMedia(params = {}) {
|
|
127
|
-
return this.
|
|
148
|
+
return this.fetchPaginated('/wp/v2/media', params);
|
|
128
149
|
}
|
|
129
150
|
async getMediaItem(id) {
|
|
130
151
|
return this.makeRequest(`/wp/v2/media/${id}`);
|
|
131
152
|
}
|
|
153
|
+
/**
|
|
154
|
+
* Fetch categories with automatic pagination support
|
|
155
|
+
* @param params Query parameters including per_page for total items to fetch
|
|
156
|
+
* @returns All categories up to the limit, fetched across multiple pages if needed
|
|
157
|
+
*/
|
|
132
158
|
async getCategories(params = {}) {
|
|
133
|
-
return this.
|
|
159
|
+
return this.fetchPaginated('/wp/v2/categories', params);
|
|
134
160
|
}
|
|
161
|
+
/**
|
|
162
|
+
* Fetch tags with automatic pagination support
|
|
163
|
+
* @param params Query parameters including per_page for total items to fetch
|
|
164
|
+
* @returns All tags up to the limit, fetched across multiple pages if needed
|
|
165
|
+
*/
|
|
135
166
|
async getTags(params = {}) {
|
|
136
|
-
return this.
|
|
167
|
+
return this.fetchPaginated('/wp/v2/tags', params);
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Fetch data with automatic pagination
|
|
171
|
+
* Handles fetching all items up to the requested limit by making multiple API calls if needed
|
|
172
|
+
* @param endpoint The API endpoint to fetch from
|
|
173
|
+
* @param params Query parameters including per_page for total items to fetch
|
|
174
|
+
* @returns Array of all items fetched across all pages
|
|
175
|
+
*/
|
|
176
|
+
async fetchPaginated(endpoint, params = {}) {
|
|
177
|
+
const requestedTotal = params.per_page || 100;
|
|
178
|
+
const itemsPerPage = Math.min(requestedTotal, 100); // WordPress max is typically 100
|
|
179
|
+
const maxPages = Math.ceil(requestedTotal / itemsPerPage);
|
|
180
|
+
let allItems = [];
|
|
181
|
+
let currentPage = 1;
|
|
182
|
+
let hasMorePages = true;
|
|
183
|
+
console.log(`🔄 Fetching ${endpoint} with pagination: ${requestedTotal} items requested (${maxPages} pages of ${itemsPerPage})`);
|
|
184
|
+
while (hasMorePages && currentPage <= maxPages && allItems.length < requestedTotal) {
|
|
185
|
+
const pageParams = {
|
|
186
|
+
...params,
|
|
187
|
+
per_page: itemsPerPage,
|
|
188
|
+
page: currentPage,
|
|
189
|
+
};
|
|
190
|
+
console.log(`📄 Fetching page ${currentPage}/${maxPages} for ${endpoint}...`);
|
|
191
|
+
try {
|
|
192
|
+
const pageData = await this.makeRequest(endpoint, pageParams);
|
|
193
|
+
if (!pageData || pageData.length === 0) {
|
|
194
|
+
console.log(`✓ No more data on page ${currentPage}, stopping pagination`);
|
|
195
|
+
hasMorePages = false;
|
|
196
|
+
break;
|
|
197
|
+
}
|
|
198
|
+
allItems = allItems.concat(pageData);
|
|
199
|
+
console.log(`✓ Page ${currentPage}: fetched ${pageData.length} items (total: ${allItems.length})`);
|
|
200
|
+
// Stop if we got fewer items than requested per page (last page)
|
|
201
|
+
if (pageData.length < itemsPerPage) {
|
|
202
|
+
console.log(`✓ Reached last page (partial results)`);
|
|
203
|
+
hasMorePages = false;
|
|
204
|
+
}
|
|
205
|
+
currentPage++;
|
|
206
|
+
}
|
|
207
|
+
catch (error) {
|
|
208
|
+
console.error(`❌ Error fetching page ${currentPage}:`, error);
|
|
209
|
+
// Stop pagination on error but return what we have so far
|
|
210
|
+
hasMorePages = false;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
console.log(`✅ Pagination complete for ${endpoint}: ${allItems.length} total items fetched`);
|
|
214
|
+
// Trim to exact requested amount if we fetched more
|
|
215
|
+
return allItems.slice(0, requestedTotal);
|
|
137
216
|
}
|
|
138
217
|
// Gravity Forms endpoints
|
|
139
218
|
async getGravityForms() {
|
|
@@ -152,6 +231,15 @@ class WordPressClient {
|
|
|
152
231
|
async getStaticDataNonce() {
|
|
153
232
|
return this.makeRequest('/static-data/v1/nonce');
|
|
154
233
|
}
|
|
234
|
+
/**
|
|
235
|
+
* Fetch a custom post type with automatic pagination support
|
|
236
|
+
* @param postType The custom post type slug (e.g., 'chapter-member', 'events')
|
|
237
|
+
* @param params Query parameters including per_page for total items to fetch
|
|
238
|
+
* @returns All items of the custom post type up to the limit
|
|
239
|
+
*/
|
|
240
|
+
async getCustomPostType(postType, params = {}) {
|
|
241
|
+
return this.fetchPaginated(`/wp/v2/${postType}`, params);
|
|
242
|
+
}
|
|
155
243
|
async getAllData(params = {}) {
|
|
156
244
|
const [posts, pages, media, categories, tags] = await Promise.all([
|
|
157
245
|
this.getPosts(params),
|
|
@@ -296,10 +384,11 @@ class GravityFormsClient {
|
|
|
296
384
|
const credentials = btoa(`${this.config.username}:${this.config.password}`);
|
|
297
385
|
headers['Authorization'] = `Basic ${credentials}`;
|
|
298
386
|
}
|
|
299
|
-
// Add
|
|
387
|
+
// Add Cloudflare Access Service Token headers if provided (for CF Access protected APIs)
|
|
300
388
|
if (this.config.cfAccessClientId && this.config.cfAccessClientSecret) {
|
|
301
389
|
headers['CF-Access-Client-Id'] = this.config.cfAccessClientId;
|
|
302
390
|
headers['CF-Access-Client-Secret'] = this.config.cfAccessClientSecret;
|
|
391
|
+
console.log('🔐 Added CF Access Service Token headers to Gravity Forms request');
|
|
303
392
|
}
|
|
304
393
|
}
|
|
305
394
|
else {
|