@pterodoc/wordpress 0.2.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/LICENCE.md +10 -0
- package/README.md +10 -0
- package/lib/client.d.ts +76 -0
- package/lib/client.d.ts.map +1 -0
- package/lib/index.d.ts +49 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +655 -0
- package/lib/index.js.map +1 -0
- package/lib/media.d.ts +26 -0
- package/lib/media.d.ts.map +1 -0
- package/lib/pages.d.ts +87 -0
- package/lib/pages.d.ts.map +1 -0
- package/lib/plugin.d.ts +35 -0
- package/lib/plugin.d.ts.map +1 -0
- package/lib/url.d.ts +45 -0
- package/lib/url.d.ts.map +1 -0
- package/package.json +24 -0
- package/src/client.ts +215 -0
- package/src/index.ts +275 -0
- package/src/media.ts +106 -0
- package/src/pages.ts +201 -0
- package/src/plugin.ts +69 -0
- package/src/url.ts +69 -0
package/LICENCE.md
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
Creative Commons Attribution-ShareAlike 4.0 International (CC BY-SA 4.0)
|
|
2
|
+
|
|
3
|
+
Copyright (c) Onyx <hello@onyx.ac> (https://onyx.ac)
|
|
4
|
+
|
|
5
|
+
This work is licensed under the Creative Commons Attribution-ShareAlike 4.0
|
|
6
|
+
International License. You are free to share and adapt this work, including
|
|
7
|
+
commercially, provided you give appropriate attribution and distribute any
|
|
8
|
+
derivative works under the same license.
|
|
9
|
+
|
|
10
|
+
Full legal text: https://creativecommons.org/licenses/by-sa/4.0/legalcode
|
package/README.md
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# @pterodoc/wordpress
|
|
2
|
+
|
|
3
|
+
The WordPress REST target for [pterodoc](https://github.com/onyx-ac/pterodoc): pages
|
|
4
|
+
identified by parent and slug, media keyed by content hash, and pruning that trashes
|
|
5
|
+
rather than deletes.
|
|
6
|
+
|
|
7
|
+
You probably want the [`pterodoc`](https://www.npmjs.com/package/pterodoc) package
|
|
8
|
+
instead.
|
|
9
|
+
|
|
10
|
+
Licensed CC-BY-SA-4.0.
|
package/lib/client.d.ts
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A small WordPress REST client, scoped to what publishing needs.
|
|
3
|
+
*
|
|
4
|
+
* Authentication is an Application Password over HTTP Basic. `fetch` and the
|
|
5
|
+
* clock are injectable so the whole sync can be tested without a network.
|
|
6
|
+
*/
|
|
7
|
+
/** Fields needed to compare a remote page with a rendered one. */
|
|
8
|
+
export declare const PAGE_FIELDS = "id,parent,slug,status,link,title,menu_order,template";
|
|
9
|
+
/** Those, plus the content only fetched when a page is about to be compared. */
|
|
10
|
+
export declare const FULL_PAGE_FIELDS = "id,parent,slug,status,link,title,menu_order,template,content,excerpt,meta";
|
|
11
|
+
/** How hard to try again when WordPress is busy. */
|
|
12
|
+
export interface RetryPolicy {
|
|
13
|
+
/** Extra attempts after the first. */
|
|
14
|
+
attempts: number;
|
|
15
|
+
/** Delay before the first retry, doubling after that. */
|
|
16
|
+
baseDelayMs: number;
|
|
17
|
+
/** Longest delay to wait, however far the backoff has grown. */
|
|
18
|
+
maxDelayMs: number;
|
|
19
|
+
}
|
|
20
|
+
/** The retry policy used when a site configures none. */
|
|
21
|
+
export declare const DEFAULT_RETRY: RetryPolicy;
|
|
22
|
+
/** What the client needs to reach a site. */
|
|
23
|
+
export interface WpClientOptions {
|
|
24
|
+
/** Site origin, without a trailing slash. */
|
|
25
|
+
baseUrl: string;
|
|
26
|
+
/** WordPress username. */
|
|
27
|
+
user?: string;
|
|
28
|
+
/** An Application Password; display spaces are removed. */
|
|
29
|
+
appPassword?: string;
|
|
30
|
+
/** Polylang language code, sent as a `lang` parameter. */
|
|
31
|
+
lang?: string;
|
|
32
|
+
/** Send DELETE as POST with an override header, for hosts that block DELETE. */
|
|
33
|
+
methodOverride?: boolean;
|
|
34
|
+
/** How hard to retry. */
|
|
35
|
+
retry?: RetryPolicy;
|
|
36
|
+
/** Injected for tests. */
|
|
37
|
+
fetch?: typeof globalThis.fetch;
|
|
38
|
+
/** Injected for tests. */
|
|
39
|
+
sleep?: (ms: number) => Promise<void>;
|
|
40
|
+
/** Called with progress worth seeing under `--verbose`. */
|
|
41
|
+
log?: (message: string) => void;
|
|
42
|
+
}
|
|
43
|
+
/** One request, before it is sent. */
|
|
44
|
+
interface RequestOptions {
|
|
45
|
+
query?: Record<string, string | number | undefined>;
|
|
46
|
+
body?: unknown;
|
|
47
|
+
/** A multipart body, used for media uploads. */
|
|
48
|
+
form?: FormData;
|
|
49
|
+
}
|
|
50
|
+
export declare class WpClient {
|
|
51
|
+
private readonly baseUrl;
|
|
52
|
+
private readonly user;
|
|
53
|
+
private readonly appPassword;
|
|
54
|
+
private readonly lang;
|
|
55
|
+
private readonly methodOverride;
|
|
56
|
+
private readonly retry;
|
|
57
|
+
private readonly doFetch;
|
|
58
|
+
private readonly sleep;
|
|
59
|
+
private readonly log;
|
|
60
|
+
/** How many requests have been made, for the run summary. */
|
|
61
|
+
requestCount: number;
|
|
62
|
+
constructor(options: WpClientOptions);
|
|
63
|
+
/** Headers every request carries. */
|
|
64
|
+
private headers;
|
|
65
|
+
/**
|
|
66
|
+
* Perform one REST call, retrying only what is worth retrying.
|
|
67
|
+
*/
|
|
68
|
+
request<T = unknown>(method: 'GET' | 'POST' | 'DELETE', path: string, options?: RequestOptions): Promise<{
|
|
69
|
+
data: T;
|
|
70
|
+
headers: Headers;
|
|
71
|
+
}>;
|
|
72
|
+
/** Follow `X-WP-TotalPages` to the end of a collection. */
|
|
73
|
+
listAll<T>(path: string, query: Record<string, string | number>): Promise<T[]>;
|
|
74
|
+
}
|
|
75
|
+
export {};
|
|
76
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,kEAAkE;AAClE,eAAO,MAAM,W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IAC9B,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAS;IACrC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAS;IAC9B,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAU;IACzC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAc;IACpC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAA0B;IAClD,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAgC;IACtD,OAAO,CAAC,QAAQ,CAAC,GAAG,CAA4B;IAEhD,6DAA6D;IAC7D,YAAY,SAAK;gBAEL,OAAO,EAAE,eAAe;IAYpC,qCAAqC;IACrC,OAAO,CAAC,OAAO;IASf;;OAEG;IACG,OAAO,CAAC,CAAC,GAAG,OAAO,EACvB,MAAM,EAAE,KAAK,GAAG,MAAM,GAAG,QAAQ,EACjC,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,cAAmB,GAC3B,OAAO,CAAC;QAAE,IAAI,EAAE,CAAC,CAAC;QAAC,OAAO,EAAE,OAAO,CAAA;KAAE,CAAC;IAiGzC,2DAA2D;IACrD,OAAO,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,GAAG,OAAO,CAAC,CAAC,EAAE,CAAC;CAerF"}
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/** The WordPress target. */
|
|
2
|
+
import { renderNavigationStub } from '@pterodoc/core/render';
|
|
3
|
+
import type { Target, TargetCapabilities } from '@pterodoc/core/target';
|
|
4
|
+
import { type RetryPolicy } from './client';
|
|
5
|
+
import { type WordpressUrlPolicy } from './url';
|
|
6
|
+
/** What WordPress can do. */
|
|
7
|
+
export declare const WORDPRESS_CAPABILITIES: TargetCapabilities;
|
|
8
|
+
/** Content a page holds between being created and being rendered. */
|
|
9
|
+
declare const PLACEHOLDER = "<!-- wp:paragraph -->\n<p>Publishing\u2026</p>\n<!-- /wp:paragraph -->";
|
|
10
|
+
/** How to reach and shape a WordPress site. */
|
|
11
|
+
export interface WordpressTargetOptions {
|
|
12
|
+
/** Site origin. */
|
|
13
|
+
url: string;
|
|
14
|
+
/** Username of the Application Password. */
|
|
15
|
+
user: string;
|
|
16
|
+
/** The Application Password. */
|
|
17
|
+
appPassword: string;
|
|
18
|
+
/** Where the tree hangs and how versions and locales are addressed. */
|
|
19
|
+
policy: WordpressUrlPolicy;
|
|
20
|
+
/** Status applied to every synced page. */
|
|
21
|
+
status: 'publish' | 'draft' | 'private';
|
|
22
|
+
/** Page template slug, or empty for the theme default. */
|
|
23
|
+
template: string;
|
|
24
|
+
/** Polylang language code. */
|
|
25
|
+
lang: string;
|
|
26
|
+
/** Prefix of the slug that identifies uploaded media. */
|
|
27
|
+
mediaSlugPrefix: string;
|
|
28
|
+
/** Send DELETE as POST with an override header. */
|
|
29
|
+
methodOverride: boolean;
|
|
30
|
+
/** Retry policy. */
|
|
31
|
+
retry?: RetryPolicy;
|
|
32
|
+
}
|
|
33
|
+
/** Injected so the target can be exercised without a network. */
|
|
34
|
+
export interface WordpressTargetDeps {
|
|
35
|
+
fetch?: typeof globalThis.fetch;
|
|
36
|
+
sleep?: (ms: number) => Promise<void>;
|
|
37
|
+
log?: (message: string) => void;
|
|
38
|
+
}
|
|
39
|
+
/** Create the WordPress target. */
|
|
40
|
+
export declare function createWordpressTarget(options: WordpressTargetOptions, deps?: WordpressTargetDeps): Target;
|
|
41
|
+
export { splitOwnership, hrefFor, prefixSegments } from './url';
|
|
42
|
+
export type { WordpressUrlPolicy } from './url';
|
|
43
|
+
export { WpClient, DEFAULT_RETRY } from './client';
|
|
44
|
+
export { detectPlugin } from './plugin';
|
|
45
|
+
export type { PluginStatus } from './plugin';
|
|
46
|
+
export type { RetryPolicy, WpClientOptions } from './client';
|
|
47
|
+
export { renderNavigationStub };
|
|
48
|
+
export { PLACEHOLDER };
|
|
49
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -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