wp-content-exporter 0.1.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/LICENSE +21 -0
- package/README.md +561 -0
- package/dist/auth.d.ts +42 -0
- package/dist/auth.d.ts.map +1 -0
- package/dist/auth.js +42 -0
- package/dist/auth.js.map +1 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +142 -0
- package/dist/cli.js.map +1 -0
- package/dist/csv.d.ts +21 -0
- package/dist/csv.d.ts.map +1 -0
- package/dist/csv.js +57 -0
- package/dist/csv.js.map +1 -0
- package/dist/fetch.d.ts +21 -0
- package/dist/fetch.d.ts.map +1 -0
- package/dist/fetch.js +45 -0
- package/dist/fetch.js.map +1 -0
- package/dist/index.d.ts +53 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +64 -0
- package/dist/index.js.map +1 -0
- package/dist/src/auth.d.ts +42 -0
- package/dist/src/auth.d.ts.map +1 -0
- package/dist/src/auth.js +42 -0
- package/dist/src/auth.js.map +1 -0
- package/dist/src/csv.d.ts +21 -0
- package/dist/src/csv.d.ts.map +1 -0
- package/dist/src/csv.js +57 -0
- package/dist/src/csv.js.map +1 -0
- package/dist/src/fetch.d.ts +21 -0
- package/dist/src/fetch.d.ts.map +1 -0
- package/dist/src/fetch.js +45 -0
- package/dist/src/fetch.js.map +1 -0
- package/dist/src/index.d.ts +53 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +64 -0
- package/dist/src/index.js.map +1 -0
- package/dist/tests/test.d.ts +2 -0
- package/dist/tests/test.d.ts.map +1 -0
- package/dist/tests/test.js +271 -0
- package/dist/tests/test.js.map +1 -0
- package/package.json +65 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 wp-content-exporter contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,561 @@
|
|
|
1
|
+
# wp-content-exporter
|
|
2
|
+
|
|
3
|
+
Export WordPress CMS data to CSV format, perfect for headless CMS setups and Framer integration.
|
|
4
|
+
|
|
5
|
+
Automatically handles WordPress REST API pagination, supports multiple authentication methods, and flattens nested JSON fields to create clean, spreadsheet-friendly CSV output.
|
|
6
|
+
|
|
7
|
+
## Features
|
|
8
|
+
|
|
9
|
+
- 📦 **Simple API** - One function call to export WordPress content
|
|
10
|
+
- 🔐 **Multiple Auth Methods** - Basic auth, Bearer tokens, or custom headers
|
|
11
|
+
- 📄 **Nested Field Support** - Flatten ACF fields and nested objects using dot notation
|
|
12
|
+
- 🔄 **Auto Pagination** - Automatically handles WordPress REST API pagination
|
|
13
|
+
- 📊 **CSV Export** - Clean CSV generation with json2csv
|
|
14
|
+
- 🎯 **TypeScript** - Full type safety with strict TypeScript support
|
|
15
|
+
- 🚀 **ESM** - Native ES modules support (Node 18+)
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npm install wp-content-exporter
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Quick Start
|
|
24
|
+
|
|
25
|
+
### Get CSV as String
|
|
26
|
+
```typescript
|
|
27
|
+
import { exportToCSV } from "wp-content-exporter"
|
|
28
|
+
|
|
29
|
+
const csv = await exportToCSV({
|
|
30
|
+
endpoint: "https://example.com",
|
|
31
|
+
postType: "posts",
|
|
32
|
+
fields: ["title.rendered", "slug", "date"]
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
console.log(csv)
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### Save Directly to File
|
|
39
|
+
```typescript
|
|
40
|
+
import { exportToCSV } from "wp-content-exporter"
|
|
41
|
+
|
|
42
|
+
await exportToCSV({
|
|
43
|
+
endpoint: "https://example.com",
|
|
44
|
+
postType: "posts",
|
|
45
|
+
fields: ["title.rendered", "slug", "date"],
|
|
46
|
+
outputFile: "./posts.csv" // ← Saves automatically
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
console.log("✓ Saved to posts.csv")
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Usage
|
|
53
|
+
|
|
54
|
+
### Basic Export (No Authentication)
|
|
55
|
+
|
|
56
|
+
```typescript
|
|
57
|
+
import { exportToCSV } from "wp-content-exporter"
|
|
58
|
+
|
|
59
|
+
const csv = await exportToCSV({
|
|
60
|
+
endpoint: "https://example.wordpress.com",
|
|
61
|
+
postType: "posts",
|
|
62
|
+
fields: ["title.rendered", "slug"]
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
console.log(csv)
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### Save to File (Recommended for Large Exports)
|
|
69
|
+
|
|
70
|
+
```typescript
|
|
71
|
+
// Simply add outputFile option
|
|
72
|
+
await exportToCSV({
|
|
73
|
+
endpoint: "https://example.wordpress.com",
|
|
74
|
+
postType: "posts",
|
|
75
|
+
fields: ["title.rendered", "slug"],
|
|
76
|
+
outputFile: "./posts.csv" // ← CSV saves directly
|
|
77
|
+
})
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### With Basic Authentication
|
|
81
|
+
|
|
82
|
+
```typescript
|
|
83
|
+
const csv = await exportToCSV({
|
|
84
|
+
endpoint: "https://example.com",
|
|
85
|
+
postType: "posts",
|
|
86
|
+
fields: ["title.rendered", "content.rendered"],
|
|
87
|
+
auth: {
|
|
88
|
+
type: "basic",
|
|
89
|
+
username: "admin",
|
|
90
|
+
password: "application-password" // Use app password, not your login password
|
|
91
|
+
}
|
|
92
|
+
})
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### With Bearer Token
|
|
96
|
+
|
|
97
|
+
```typescript
|
|
98
|
+
const csv = await exportToCSV({
|
|
99
|
+
endpoint: "https://example.com",
|
|
100
|
+
postType: "posts",
|
|
101
|
+
fields: ["title.rendered", "slug"],
|
|
102
|
+
auth: {
|
|
103
|
+
type: "bearer",
|
|
104
|
+
token: "your-jwt-token-here"
|
|
105
|
+
}
|
|
106
|
+
})
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### With Custom Headers
|
|
110
|
+
|
|
111
|
+
```typescript
|
|
112
|
+
const csv = await exportToCSV({
|
|
113
|
+
endpoint: "https://example.com",
|
|
114
|
+
postType: "posts",
|
|
115
|
+
fields: ["title.rendered", "slug"],
|
|
116
|
+
auth: {
|
|
117
|
+
type: "headers",
|
|
118
|
+
headers: {
|
|
119
|
+
"Authorization": "Bearer xyz",
|
|
120
|
+
"X-Custom-Header": "value"
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
})
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
### Nested Fields and ACF
|
|
127
|
+
|
|
128
|
+
```typescript
|
|
129
|
+
const csv = await exportToCSV({
|
|
130
|
+
endpoint: "https://example.com",
|
|
131
|
+
postType: "posts",
|
|
132
|
+
fields: [
|
|
133
|
+
"title.rendered",
|
|
134
|
+
"acf.price",
|
|
135
|
+
"acf.product.name",
|
|
136
|
+
"meta.custom_field",
|
|
137
|
+
"author"
|
|
138
|
+
]
|
|
139
|
+
})
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
### Pagination Control
|
|
143
|
+
|
|
144
|
+
```typescript
|
|
145
|
+
const csv = await exportToCSV({
|
|
146
|
+
endpoint: "https://example.com",
|
|
147
|
+
postType: "posts",
|
|
148
|
+
fields: ["title.rendered", "slug"],
|
|
149
|
+
perPage: 50 // Default is 100, max 100
|
|
150
|
+
})
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
### Custom Post Types
|
|
154
|
+
|
|
155
|
+
```typescript
|
|
156
|
+
const csv = await exportToCSV({
|
|
157
|
+
endpoint: "https://example.com",
|
|
158
|
+
postType: "custom-post-type", // or "pages"
|
|
159
|
+
fields: ["title.rendered", "slug"]
|
|
160
|
+
})
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
## API Reference
|
|
164
|
+
|
|
165
|
+
### `exportToCSV(options: ExportOptions): Promise<string>`
|
|
166
|
+
|
|
167
|
+
Main function to export WordPress content to CSV.
|
|
168
|
+
|
|
169
|
+
#### Parameters
|
|
170
|
+
|
|
171
|
+
- **endpoint** (string, required): Your WordPress site URL
|
|
172
|
+
- Example: `"https://example.com"`
|
|
173
|
+
- Must be accessible and have WordPress REST API enabled
|
|
174
|
+
|
|
175
|
+
- **postType** (string, required): Type of content to export
|
|
176
|
+
- Default types: `"posts"`, `"pages"`
|
|
177
|
+
- Custom post types: Use your custom post type slug
|
|
178
|
+
|
|
179
|
+
- **fields** (string[], required): Fields to include in the CSV
|
|
180
|
+
- Supports dot notation for nested fields
|
|
181
|
+
- Example: `["title.rendered", "acf.price"]`
|
|
182
|
+
|
|
183
|
+
- **auth** (AuthConfig, optional): Authentication configuration
|
|
184
|
+
- Options: `"none"` (default), `"basic"`, `"bearer"`, `"headers"`
|
|
185
|
+
|
|
186
|
+
- **perPage** (number, optional): Items per API request (default: `100`, max: `100`)
|
|
187
|
+
|
|
188
|
+
- **outputFile** (string, optional): File path to save CSV
|
|
189
|
+
- If provided, CSV is written to file and returned
|
|
190
|
+
- If omitted, CSV is only returned as string
|
|
191
|
+
- Useful for large exports
|
|
192
|
+
|
|
193
|
+
#### Returns
|
|
194
|
+
|
|
195
|
+
- `Promise<string>`: CSV-formatted string with headers and data rows
|
|
196
|
+
|
|
197
|
+
#### Throws
|
|
198
|
+
|
|
199
|
+
- `Error` if endpoint is invalid
|
|
200
|
+
- `Error` if postType is missing
|
|
201
|
+
- `Error` if no fields provided
|
|
202
|
+
- `Error` if API request fails
|
|
203
|
+
- `Error` if authentication fails
|
|
204
|
+
|
|
205
|
+
### `AuthConfig` Type
|
|
206
|
+
|
|
207
|
+
```typescript
|
|
208
|
+
type AuthConfig =
|
|
209
|
+
| { type: "none" }
|
|
210
|
+
| { type: "basic"; username: string; password: string }
|
|
211
|
+
| { type: "bearer"; token: string }
|
|
212
|
+
| { type: "headers"; headers: Record<string, string> }
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
## Authentication Guide
|
|
216
|
+
|
|
217
|
+
### No Authentication
|
|
218
|
+
For public WordPress sites without private content:
|
|
219
|
+
```typescript
|
|
220
|
+
// No auth needed, just omit the `auth` parameter
|
|
221
|
+
const csv = await exportToCSV({
|
|
222
|
+
endpoint: "https://example.com",
|
|
223
|
+
postType: "posts",
|
|
224
|
+
fields: ["title.rendered", "slug"]
|
|
225
|
+
})
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
### Basic Auth (Username + Application Password)
|
|
229
|
+
1. Generate an Application Password in WordPress:
|
|
230
|
+
- Go to Users → Your Profile → Application Passwords
|
|
231
|
+
- Create a new password (WordPress 5.6+)
|
|
232
|
+
|
|
233
|
+
2. Use it in your code:
|
|
234
|
+
```typescript
|
|
235
|
+
const csv = await exportToCSV({
|
|
236
|
+
endpoint: "https://example.com",
|
|
237
|
+
postType: "posts",
|
|
238
|
+
fields: ["title.rendered"],
|
|
239
|
+
auth: {
|
|
240
|
+
type: "basic",
|
|
241
|
+
username: "your-username",
|
|
242
|
+
password: "xxxx xxxx xxxx xxxx" // Your app password
|
|
243
|
+
}
|
|
244
|
+
})
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
### Bearer Token (JWT)
|
|
248
|
+
For sites using JWT authentication plugins:
|
|
249
|
+
```typescript
|
|
250
|
+
const csv = await exportToCSV({
|
|
251
|
+
endpoint: "https://example.com",
|
|
252
|
+
postType: "posts",
|
|
253
|
+
fields: ["title.rendered"],
|
|
254
|
+
auth: {
|
|
255
|
+
type: "bearer",
|
|
256
|
+
token: "eyJhbGciOiJIUzI1NiIs..."
|
|
257
|
+
}
|
|
258
|
+
})
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
### Custom Headers
|
|
262
|
+
For custom authentication schemes:
|
|
263
|
+
```typescript
|
|
264
|
+
const csv = await exportToCSV({
|
|
265
|
+
endpoint: "https://example.com",
|
|
266
|
+
postType: "posts",
|
|
267
|
+
fields: ["title.rendered"],
|
|
268
|
+
auth: {
|
|
269
|
+
type: "headers",
|
|
270
|
+
headers: {
|
|
271
|
+
"X-API-Key": "your-api-key",
|
|
272
|
+
"Authorization": "Custom your-custom-auth"
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
})
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
## Examples
|
|
279
|
+
|
|
280
|
+
### Export Posts to File
|
|
281
|
+
|
|
282
|
+
```typescript
|
|
283
|
+
import { exportToCSV } from "wp-content-exporter"
|
|
284
|
+
|
|
285
|
+
async function exportPosts() {
|
|
286
|
+
// Simple: just specify outputFile
|
|
287
|
+
await exportToCSV({
|
|
288
|
+
endpoint: "https://example.com",
|
|
289
|
+
postType: "posts",
|
|
290
|
+
fields: [
|
|
291
|
+
"id",
|
|
292
|
+
"title.rendered",
|
|
293
|
+
"slug",
|
|
294
|
+
"date",
|
|
295
|
+
"excerpt.rendered"
|
|
296
|
+
],
|
|
297
|
+
outputFile: "./posts.csv"
|
|
298
|
+
})
|
|
299
|
+
|
|
300
|
+
console.log("✓ Exported to posts.csv")
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
exportPosts().catch(console.error)
|
|
304
|
+
```
|
|
305
|
+
|
|
306
|
+
### Export with Error Handling
|
|
307
|
+
|
|
308
|
+
```typescript
|
|
309
|
+
async function exportSafely() {
|
|
310
|
+
try {
|
|
311
|
+
const csv = await exportToCSV({
|
|
312
|
+
endpoint: "https://example.com",
|
|
313
|
+
postType: "posts",
|
|
314
|
+
fields: ["title.rendered", "slug"],
|
|
315
|
+
auth: {
|
|
316
|
+
type: "basic",
|
|
317
|
+
username: "admin",
|
|
318
|
+
password: process.env.WP_PASSWORD
|
|
319
|
+
},
|
|
320
|
+
outputFile: "./posts.csv"
|
|
321
|
+
})
|
|
322
|
+
|
|
323
|
+
const rowCount = csv.split('\n').length - 1
|
|
324
|
+
console.log(`✓ Exported ${rowCount} rows to posts.csv`)
|
|
325
|
+
} catch (error) {
|
|
326
|
+
console.error("❌ Export failed:", error instanceof Error ? error.message : error)
|
|
327
|
+
process.exit(1)
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
```
|
|
331
|
+
|
|
332
|
+
### Batch Export Multiple Post Types
|
|
333
|
+
|
|
334
|
+
```typescript
|
|
335
|
+
async function exportAll() {
|
|
336
|
+
const postTypes = ["posts", "pages", "products"]
|
|
337
|
+
|
|
338
|
+
for (const postType of postTypes) {
|
|
339
|
+
await exportToCSV({
|
|
340
|
+
endpoint: "https://example.com",
|
|
341
|
+
postType,
|
|
342
|
+
fields: ["title.rendered", "slug", "date"],
|
|
343
|
+
outputFile: `./${postType}.csv`
|
|
344
|
+
})
|
|
345
|
+
|
|
346
|
+
console.log(`✓ Exported ${postType}`)
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
```
|
|
350
|
+
|
|
351
|
+
## Common Field Names
|
|
352
|
+
|
|
353
|
+
### Standard WordPress Fields
|
|
354
|
+
- `id` - Post ID
|
|
355
|
+
- `title.rendered` - Post title
|
|
356
|
+
- `content.rendered` - Post content
|
|
357
|
+
- `excerpt.rendered` - Post excerpt
|
|
358
|
+
- `slug` - URL slug
|
|
359
|
+
- `date` - Publication date
|
|
360
|
+
- `status` - Post status (publish, draft, etc)
|
|
361
|
+
- `author` - Author ID
|
|
362
|
+
- `featured_media` - Featured image ID
|
|
363
|
+
|
|
364
|
+
### ACF Fields
|
|
365
|
+
- `acf.{field_name}` - Simple ACF fields
|
|
366
|
+
- `acf.{group}.{field}` - Grouped ACF fields
|
|
367
|
+
- `meta.{field_name}` - Custom meta fields
|
|
368
|
+
|
|
369
|
+
## Requirements
|
|
370
|
+
|
|
371
|
+
- **Node.js**: 18.0.0 or higher
|
|
372
|
+
- **npm**: 9.0.0 or higher (or yarn/pnpm equivalents)
|
|
373
|
+
|
|
374
|
+
## TypeScript Support
|
|
375
|
+
|
|
376
|
+
This package includes full TypeScript definitions. Type checking is strict by default:
|
|
377
|
+
|
|
378
|
+
```typescript
|
|
379
|
+
import { exportToCSV, AuthConfig } from "wp-content-exporter"
|
|
380
|
+
|
|
381
|
+
// Type-safe configuration
|
|
382
|
+
const options: ExportOptions = {
|
|
383
|
+
endpoint: "https://example.com",
|
|
384
|
+
postType: "posts",
|
|
385
|
+
fields: ["title.rendered"],
|
|
386
|
+
auth: {
|
|
387
|
+
type: "basic",
|
|
388
|
+
username: "admin",
|
|
389
|
+
password: "password"
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
const csv: string = await exportToCSV(options)
|
|
394
|
+
```
|
|
395
|
+
|
|
396
|
+
## Performance Tips
|
|
397
|
+
|
|
398
|
+
1. **Pagination**: Large exports use pagination automatically. Adjust `perPage` for optimal speed:
|
|
399
|
+
```typescript
|
|
400
|
+
// For large datasets
|
|
401
|
+
perPage: 100 // Maximum allowed by WordPress
|
|
402
|
+
```
|
|
403
|
+
|
|
404
|
+
2. **Field Selection**: Only export fields you need:
|
|
405
|
+
```typescript
|
|
406
|
+
// ✓ Good - minimal fields
|
|
407
|
+
fields: ["title.rendered", "slug"]
|
|
408
|
+
|
|
409
|
+
// ✗ Bad - includes unnecessary data
|
|
410
|
+
fields: ["title", "content", "excerpt", "author", "meta", "acf"]
|
|
411
|
+
```
|
|
412
|
+
|
|
413
|
+
3. **Batch Exports**: For multiple post types, call sequentially:
|
|
414
|
+
```typescript
|
|
415
|
+
const posts = await exportToCSV({ /* posts */ })
|
|
416
|
+
const pages = await exportToCSV({ /* pages */ })
|
|
417
|
+
```
|
|
418
|
+
|
|
419
|
+
## Error Handling
|
|
420
|
+
|
|
421
|
+
The package throws descriptive errors:
|
|
422
|
+
|
|
423
|
+
```typescript
|
|
424
|
+
try {
|
|
425
|
+
const csv = await exportToCSV({
|
|
426
|
+
endpoint: "invalid-url",
|
|
427
|
+
postType: "posts",
|
|
428
|
+
fields: ["title"]
|
|
429
|
+
})
|
|
430
|
+
} catch (error) {
|
|
431
|
+
if (error instanceof Error) {
|
|
432
|
+
console.error(error.message)
|
|
433
|
+
// "Failed to fetch from invalid-url/wp-json/wp/v2/posts: ..."
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
```
|
|
437
|
+
|
|
438
|
+
Common errors:
|
|
439
|
+
- **"Endpoint is required"** - Missing endpoint URL
|
|
440
|
+
- **"WordPress REST API error: 401"** - Authentication failed
|
|
441
|
+
- **"WordPress REST API error: 403"** - Access denied
|
|
442
|
+
- **"WordPress REST API error: 404"** - Post type not found
|
|
443
|
+
- **"Failed to fetch"** - Network or endpoint unavailable
|
|
444
|
+
|
|
445
|
+
## Development
|
|
446
|
+
|
|
447
|
+
### Setup
|
|
448
|
+
|
|
449
|
+
```bash
|
|
450
|
+
git clone https://github.com/yourusername/wp-content-exporter.git
|
|
451
|
+
cd wp-content-exporter
|
|
452
|
+
npm install
|
|
453
|
+
```
|
|
454
|
+
|
|
455
|
+
### Build
|
|
456
|
+
|
|
457
|
+
```bash
|
|
458
|
+
npm run build
|
|
459
|
+
```
|
|
460
|
+
|
|
461
|
+
### Type Check
|
|
462
|
+
|
|
463
|
+
```bash
|
|
464
|
+
npm run type-check
|
|
465
|
+
```
|
|
466
|
+
|
|
467
|
+
### Run Tests
|
|
468
|
+
|
|
469
|
+
```bash
|
|
470
|
+
npm test
|
|
471
|
+
```
|
|
472
|
+
|
|
473
|
+
### Run Dev Mode
|
|
474
|
+
|
|
475
|
+
```bash
|
|
476
|
+
npm run dev
|
|
477
|
+
```
|
|
478
|
+
|
|
479
|
+
## Publishing
|
|
480
|
+
|
|
481
|
+
This package uses [Changesets](https://github.com/changesets/changesets) for version management and publishing.
|
|
482
|
+
|
|
483
|
+
### Create a Changeset
|
|
484
|
+
|
|
485
|
+
```bash
|
|
486
|
+
npm run changeset
|
|
487
|
+
```
|
|
488
|
+
|
|
489
|
+
This will prompt you to:
|
|
490
|
+
1. Select the package
|
|
491
|
+
2. Choose version bump type (patch, minor, major)
|
|
492
|
+
3. Add a description of changes
|
|
493
|
+
|
|
494
|
+
The changeset is saved in `.changeset/` folder.
|
|
495
|
+
|
|
496
|
+
### Version Update
|
|
497
|
+
|
|
498
|
+
```bash
|
|
499
|
+
npm run version
|
|
500
|
+
```
|
|
501
|
+
|
|
502
|
+
This:
|
|
503
|
+
- Updates `package.json` version
|
|
504
|
+
- Updates `CHANGELOG.md`
|
|
505
|
+
- Creates git tags
|
|
506
|
+
|
|
507
|
+
### Publish to npm
|
|
508
|
+
|
|
509
|
+
```bash
|
|
510
|
+
npm run publish-package
|
|
511
|
+
```
|
|
512
|
+
|
|
513
|
+
Or manually:
|
|
514
|
+
|
|
515
|
+
```bash
|
|
516
|
+
npm publish
|
|
517
|
+
```
|
|
518
|
+
|
|
519
|
+
### Full Publish Workflow
|
|
520
|
+
|
|
521
|
+
```bash
|
|
522
|
+
# 1. Make changes and commit
|
|
523
|
+
git add .
|
|
524
|
+
git commit -m "feat: add new feature"
|
|
525
|
+
|
|
526
|
+
# 2. Create changeset
|
|
527
|
+
npm run changeset
|
|
528
|
+
|
|
529
|
+
# 3. Update version and changelog
|
|
530
|
+
npm run version
|
|
531
|
+
|
|
532
|
+
# 4. Publish to npm
|
|
533
|
+
npm run publish-package
|
|
534
|
+
|
|
535
|
+
# 5. Push to GitHub
|
|
536
|
+
git push origin main --tags
|
|
537
|
+
```
|
|
538
|
+
|
|
539
|
+
## License
|
|
540
|
+
|
|
541
|
+
MIT
|
|
542
|
+
|
|
543
|
+
## Contributing
|
|
544
|
+
|
|
545
|
+
Contributions welcome! Please:
|
|
546
|
+
|
|
547
|
+
1. Fork the repository
|
|
548
|
+
2. Create a feature branch
|
|
549
|
+
3. Make your changes
|
|
550
|
+
4. Add tests if applicable
|
|
551
|
+
5. Submit a pull request
|
|
552
|
+
|
|
553
|
+
## Support
|
|
554
|
+
|
|
555
|
+
- 📖 [Documentation](https://github.com/yourusername/wp-content-exporter)
|
|
556
|
+
- 🐛 [Report Issues](https://github.com/yourusername/wp-content-exporter/issues)
|
|
557
|
+
- 💬 [Discussions](https://github.com/yourusername/wp-content-exporter/discussions)
|
|
558
|
+
|
|
559
|
+
## Changelog
|
|
560
|
+
|
|
561
|
+
See [CHANGELOG.md](./CHANGELOG.md) for version history and changes.
|
package/dist/auth.d.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Authentication configuration options for WordPress REST API
|
|
3
|
+
*
|
|
4
|
+
* @typedef {Object} AuthConfig
|
|
5
|
+
* @property {string} type - Authentication type: "none", "basic", "bearer", or "headers"
|
|
6
|
+
*/
|
|
7
|
+
export type AuthConfig = {
|
|
8
|
+
type: "none";
|
|
9
|
+
} | {
|
|
10
|
+
type: "basic";
|
|
11
|
+
username: string;
|
|
12
|
+
password: string;
|
|
13
|
+
} | {
|
|
14
|
+
type: "bearer";
|
|
15
|
+
token: string;
|
|
16
|
+
} | {
|
|
17
|
+
type: "headers";
|
|
18
|
+
headers: Record<string, string>;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Builds HTTP headers including authentication if provided
|
|
22
|
+
*
|
|
23
|
+
* @param {AuthConfig} [auth] - Optional authentication configuration
|
|
24
|
+
* @returns {HeadersInit} Headers object with authentication applied
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* // Basic auth
|
|
28
|
+
* const headers = buildHeaders({
|
|
29
|
+
* type: "basic",
|
|
30
|
+
* username: "admin",
|
|
31
|
+
* password: "password"
|
|
32
|
+
* })
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* // Bearer token
|
|
36
|
+
* const headers = buildHeaders({
|
|
37
|
+
* type: "bearer",
|
|
38
|
+
* token: "eyJhbGc..."
|
|
39
|
+
* })
|
|
40
|
+
*/
|
|
41
|
+
export declare function buildHeaders(auth?: AuthConfig): HeadersInit;
|
|
42
|
+
//# sourceMappingURL=auth.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,MAAM,UAAU,GAClB;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,GAChB;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,GACrD;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GACjC;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAAE,CAAA;AAExD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,YAAY,CAAC,IAAI,CAAC,EAAE,UAAU,GAAG,WAAW,CAuB3D"}
|
package/dist/auth.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Builds HTTP headers including authentication if provided
|
|
3
|
+
*
|
|
4
|
+
* @param {AuthConfig} [auth] - Optional authentication configuration
|
|
5
|
+
* @returns {HeadersInit} Headers object with authentication applied
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* // Basic auth
|
|
9
|
+
* const headers = buildHeaders({
|
|
10
|
+
* type: "basic",
|
|
11
|
+
* username: "admin",
|
|
12
|
+
* password: "password"
|
|
13
|
+
* })
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* // Bearer token
|
|
17
|
+
* const headers = buildHeaders({
|
|
18
|
+
* type: "bearer",
|
|
19
|
+
* token: "eyJhbGc..."
|
|
20
|
+
* })
|
|
21
|
+
*/
|
|
22
|
+
export function buildHeaders(auth) {
|
|
23
|
+
const headers = {
|
|
24
|
+
"Content-Type": "application/json"
|
|
25
|
+
};
|
|
26
|
+
if (!auth || auth.type === "none")
|
|
27
|
+
return headers;
|
|
28
|
+
if (auth.type === "basic") {
|
|
29
|
+
const token = Buffer
|
|
30
|
+
.from(`${auth.username}:${auth.password}`)
|
|
31
|
+
.toString("base64");
|
|
32
|
+
headers.Authorization = `Basic ${token}`;
|
|
33
|
+
}
|
|
34
|
+
if (auth.type === "bearer") {
|
|
35
|
+
headers.Authorization = `Bearer ${auth.token}`;
|
|
36
|
+
}
|
|
37
|
+
if (auth.type === "headers") {
|
|
38
|
+
Object.assign(headers, auth.headers);
|
|
39
|
+
}
|
|
40
|
+
return headers;
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=auth.js.map
|
package/dist/auth.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.js","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"AAYA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,UAAU,YAAY,CAAC,IAAiB;IAC5C,MAAM,OAAO,GAA2B;QACtC,cAAc,EAAE,kBAAkB;KACnC,CAAA;IAED,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,IAAI,KAAK,MAAM;QAAE,OAAO,OAAO,CAAA;IAEjD,IAAI,IAAI,CAAC,IAAI,KAAK,OAAO,EAAE,CAAC;QAC1B,MAAM,KAAK,GAAG,MAAM;aACjB,IAAI,CAAC,GAAG,IAAI,CAAC,QAAQ,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;aACzC,QAAQ,CAAC,QAAQ,CAAC,CAAA;QACrB,OAAO,CAAC,aAAa,GAAG,SAAS,KAAK,EAAE,CAAA;IAC1C,CAAC;IAED,IAAI,IAAI,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;QAC3B,OAAO,CAAC,aAAa,GAAG,UAAU,IAAI,CAAC,KAAK,EAAE,CAAA;IAChD,CAAC;IAED,IAAI,IAAI,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;QAC5B,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,CAAA;IACtC,CAAC;IAED,OAAO,OAAO,CAAA;AAChB,CAAC"}
|
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":""}
|