kizlo 0.18.0 → 0.20.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/adapters/auth.d.ts +17 -16
- package/dist/adapters/auth.js +4 -5
- package/dist/cli/commands/_wiring.js +9 -8
- package/dist/cli/commands/check.js +11 -15
- package/dist/cli/commands/dev.js +3 -3
- package/dist/cli/commands/generate.js +15 -17
- package/dist/cli/commands/test.js +3 -3
- package/dist/cli/daemon/config.js +148 -82
- package/dist/cli/daemon/generate.js +55 -61
- package/dist/cli/daemon/watch.js +42 -55
- package/dist/cli/wp/constants.d.ts +2 -4
- package/dist/cli/wp/constants.js +2 -4
- package/dist/cli/wp/types.d.ts +6 -3
- package/dist/cli/wp/utils.d.ts +3 -3
- package/dist/cli/wp/utils.js +9 -3
- package/dist/comment/errors.js +0 -1
- package/dist/comment/index.js +6 -6
- package/dist/config.d.ts +61 -47
- package/dist/context.d.ts +8 -8
- package/dist/context.js +5 -5
- package/dist/index.d.ts +3 -3
- package/dist/kizlo.d.ts +6 -9
- package/dist/kizlo.js +8 -9
- package/dist/package.js +1 -1
- package/dist/procedures.d.ts +0 -1
- package/dist/test/auth.js +2 -3
- package/dist/test/users.d.ts +2 -4
- package/dist/test/users.js +4 -9
- package/dist/test.d.ts +2 -2
- package/dist/test.js +2 -2
- package/dist/wordpress/endpoint.js +2 -1
- package/dist/wordpress/error.d.ts +1 -0
- package/dist/wordpress/error.js +2 -0
- package/dist/wordpress/fetch-introspection.js +1 -1
- package/dist/wordpress/generate.js +13 -7
- package/dist/wordpress/transport.js +5 -3
- package/dist/wordpress/types.d.ts +5 -1
- package/dist/wordpress/utils.d.ts +1 -0
- package/package.json +1 -1
package/dist/config.d.ts
CHANGED
|
@@ -2,14 +2,28 @@ import { Fixture } from "./cli/wp/types.js";
|
|
|
2
2
|
import "./test.js";
|
|
3
3
|
|
|
4
4
|
//#region src/config.d.ts
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Where Kizlo generates, and what it watches. A string is the home directory Kizlo owns the layout
|
|
8
|
+
* under: sources in `<dir>/server`, and the generated files (`contract.json`, the barrel, and
|
|
9
|
+
* `introspection.ts`) under `<dir>/server/generated`. The object form sets each path on its own. Omit
|
|
10
|
+
* `server` and there are no sources to watch and no contract is built, so only the introspection is
|
|
11
|
+
* generated (the shape a package that ships procedures but no server takes).
|
|
12
|
+
*/
|
|
13
|
+
type KizloDir = string | {
|
|
14
|
+
/** Server sources (extensions and procedures). Watched by `kizlo dev`; its presence is what builds a contract. */
|
|
15
|
+
server?: string;
|
|
16
|
+
/** Where `contract.json` and the generated barrel are written. Defaults to `generated/` under `server`. */
|
|
17
|
+
contract?: string;
|
|
18
|
+
/** Where the generated `introspection.ts` is written. Defaults to `generated/` under `server`. */
|
|
19
|
+
introspection?: string;
|
|
20
|
+
};
|
|
5
21
|
interface KizloDevConfig {
|
|
6
22
|
/**
|
|
7
|
-
* Run
|
|
8
|
-
*
|
|
9
|
-
* (for a project pointing at your own WordPress). Set for you by `kizlo create` / `kizlo init`
|
|
10
|
-
* when you choose local WordPress.
|
|
23
|
+
* Run the dev stack. On by default when local WordPress is enabled; set `false` to keep local
|
|
24
|
+
* WordPress on for `kizlo test` while `kizlo dev` runs the contract watcher alone.
|
|
11
25
|
*/
|
|
12
|
-
|
|
26
|
+
enable?: boolean;
|
|
13
27
|
/** Published WP port (default 8080). */
|
|
14
28
|
port?: number;
|
|
15
29
|
/**
|
|
@@ -17,8 +31,8 @@ interface KizloDevConfig {
|
|
|
17
31
|
* Hub: a bare version (`"7.1.0"`), or a full tag (`"7.1.0-php8.3-apache"`) when you need
|
|
18
32
|
* a specific PHP. Defaults to `latest`, so an unconfigured project gets current WordPress.
|
|
19
33
|
*
|
|
20
|
-
* Worth setting once you commit a generated
|
|
21
|
-
* whatever the stack serves: on `latest` that
|
|
34
|
+
* Worth setting once you commit a generated introspection, which is derived from
|
|
35
|
+
* whatever the stack serves: on `latest` that introspection goes stale the day WordPress ships.
|
|
22
36
|
*
|
|
23
37
|
* An existing install keeps the core files it was provisioned with, so changing this
|
|
24
38
|
* takes effect on the next `kizlo dev reset` and Kizlo says so when the two disagree.
|
|
@@ -45,27 +59,24 @@ interface KizloDevConfig {
|
|
|
45
59
|
}
|
|
46
60
|
interface KizloTestConfig {
|
|
47
61
|
/**
|
|
48
|
-
* Run local WordPress
|
|
49
|
-
* WordPress
|
|
50
|
-
|
|
51
|
-
|
|
62
|
+
* Run the test stack. On by default when local WordPress is enabled; set `false` to keep local
|
|
63
|
+
* WordPress on for `kizlo dev` while `kizlo test` just runs the project's own test script.
|
|
64
|
+
*/
|
|
65
|
+
enable?: boolean;
|
|
66
|
+
/**
|
|
67
|
+
* Fall back to the dev stack's `version` and `fixtures` when this stack leaves them unset (default
|
|
68
|
+
* `true`), so the two stacks a local-WordPress project always wants together are declared once.
|
|
69
|
+
* Set `false` to configure the test stack independently, taking Kizlo's defaults where it is silent.
|
|
52
70
|
*/
|
|
53
|
-
|
|
71
|
+
inherit?: boolean;
|
|
54
72
|
/** Published WP port (default 8889). */
|
|
55
73
|
port?: number;
|
|
56
74
|
/**
|
|
57
75
|
* WordPress version the local stack boots, given as the tag after `wordpress:` on Docker
|
|
58
|
-
* Hub
|
|
59
|
-
* a specific PHP. Defaults to `latest`, so an unconfigured project gets current WordPress.
|
|
60
|
-
*
|
|
61
|
-
* Worth setting once you commit a generated WordPress client, which is derived from
|
|
62
|
-
* whatever the stack serves: on `latest` that client goes stale the day WordPress ships.
|
|
63
|
-
*
|
|
64
|
-
* An existing install keeps the core files it was provisioned with, so changing this
|
|
65
|
-
* takes effect on the next `kizlo test reset` and Kizlo says so when the two disagree.
|
|
76
|
+
* Hub. Falls back to the dev stack's `version` unless `inherit` is `false`; defaults to `latest`.
|
|
66
77
|
*/
|
|
67
78
|
version?: string;
|
|
68
|
-
/** Integration fixtures to install + seed. */
|
|
79
|
+
/** Integration fixtures to install + seed. Falls back to the dev stack's `fixtures` unless `inherit` is `false`. */
|
|
69
80
|
fixtures?: Fixture[];
|
|
70
81
|
/**
|
|
71
82
|
* Package manager used to launch the test script (default: auto-detected from
|
|
@@ -78,20 +89,12 @@ interface KizloTestConfig {
|
|
|
78
89
|
*/
|
|
79
90
|
command?: string;
|
|
80
91
|
}
|
|
81
|
-
interface
|
|
82
|
-
/**
|
|
83
|
-
* Kizlo's home directory. Kizlo owns the layout inside it: your server
|
|
84
|
-
* (`server/`, whose `index.ts` exports `procedures` plus your integrations), the
|
|
85
|
-
* browser `client.ts`, and the generated contract.
|
|
86
|
-
* @default 'src/lib/kizlo' (or 'lib/kizlo' without a src dir)
|
|
87
|
-
*/
|
|
88
|
-
dir?: string;
|
|
92
|
+
interface KizloLocalConfig {
|
|
89
93
|
/**
|
|
90
|
-
*
|
|
91
|
-
*
|
|
92
|
-
* again; an empty string (`""`) is the recorded choice to use relative imports.
|
|
94
|
+
* Enable local Docker WordPress (default `true` in this object form). Set `false` to keep the
|
|
95
|
+
* stacks configured but off, the same as omitting `local` entirely.
|
|
93
96
|
*/
|
|
94
|
-
|
|
97
|
+
enable?: boolean;
|
|
95
98
|
/**
|
|
96
99
|
* Base name for the local Docker stacks (`kizlo-<name>-dev`, `kizlo-<name>-test`). Defaults
|
|
97
100
|
* to the sanitized `package.json` name, falling back to the config dir basename.
|
|
@@ -99,8 +102,8 @@ interface KizloGlobalConfig {
|
|
|
99
102
|
name?: string;
|
|
100
103
|
/**
|
|
101
104
|
* Give each branch its own local Docker stacks, by appending the checked-out branch to
|
|
102
|
-
* {@link name} (`kizlo-<name>-<branch>-dev`). Off unless set, since the stacks it
|
|
103
|
-
* are the ones an existing project is already using.
|
|
105
|
+
* {@link KizloLocalConfig.name} (`kizlo-<name>-<branch>-dev`). Off unless set, since the stacks it
|
|
106
|
+
* isolates are the ones an existing project is already using.
|
|
104
107
|
*
|
|
105
108
|
* Turn it on when you work in several checkouts at once, typically git worktrees: without it
|
|
106
109
|
* every checkout of a project resolves to one stack, so parallel `kizlo dev` and `kizlo test`
|
|
@@ -109,20 +112,31 @@ interface KizloGlobalConfig {
|
|
|
109
112
|
* A detached `HEAD` names no branch and keeps the unsuffixed stack.
|
|
110
113
|
*/
|
|
111
114
|
worktrees?: boolean;
|
|
112
|
-
/**
|
|
113
|
-
* Directory to write the WordPress client into, as `<wordpressClientDir>/wordpress.ts`. For a package or
|
|
114
|
-
* workspace that ships procedures but no Kizlo server: there is no procedure tree to build a contract from,
|
|
115
|
-
* yet those procedures still call the generated tree, so they need the client on its own.
|
|
116
|
-
*
|
|
117
|
-
* Independent of `dir`. An app leaves this unset and gets its client inside `dir` alongside the
|
|
118
|
-
* contract; set both only if a project is somehow each of those things at once.
|
|
119
|
-
*/
|
|
120
|
-
wordpressClientDir?: string;
|
|
121
|
-
/** Local WordPress and contract watcher run by `kizlo dev`. */
|
|
115
|
+
/** The dev stack run by `kizlo dev`. */
|
|
122
116
|
dev?: KizloDevConfig;
|
|
123
|
-
/**
|
|
117
|
+
/** The test stack run by `kizlo test`. Inherits `version` and `fixtures` from {@link KizloLocalConfig.dev}. */
|
|
124
118
|
test?: KizloTestConfig;
|
|
125
119
|
}
|
|
120
|
+
interface KizloGlobalConfig {
|
|
121
|
+
/**
|
|
122
|
+
* Where Kizlo generates, and what it watches. A string names the home directory Kizlo owns the
|
|
123
|
+
* layout under; the object form sets the server, contract, and introspection paths independently.
|
|
124
|
+
* @default 'src/lib/kizlo' (or 'lib/kizlo' without a src dir)
|
|
125
|
+
*/
|
|
126
|
+
dir?: KizloDir;
|
|
127
|
+
/**
|
|
128
|
+
* Import alias prefix for generated imports (e.g. `@`). Recorded by `kizlo init`
|
|
129
|
+
* from your `--alias` flag or its prompt, so later runs reuse it instead of asking
|
|
130
|
+
* again; an empty string (`""`) is the recorded choice to use relative imports.
|
|
131
|
+
*/
|
|
132
|
+
alias?: string;
|
|
133
|
+
/**
|
|
134
|
+
* Local Docker WordPress, off unless set. `true` enables both the dev and test stacks with
|
|
135
|
+
* defaults; the object form enables and configures them, and is where the stack name, the
|
|
136
|
+
* per-branch `worktrees` toggle, and the two stacks live.
|
|
137
|
+
*/
|
|
138
|
+
local?: boolean | KizloLocalConfig;
|
|
139
|
+
}
|
|
126
140
|
declare function defineConfig(config: KizloGlobalConfig): KizloGlobalConfig;
|
|
127
141
|
//#endregion
|
|
128
|
-
export { KizloDevConfig, KizloGlobalConfig, KizloTestConfig, defineConfig };
|
|
142
|
+
export { KizloDevConfig, KizloDir, KizloGlobalConfig, KizloLocalConfig, KizloTestConfig, defineConfig };
|
package/dist/context.d.ts
CHANGED
|
@@ -16,11 +16,11 @@ interface ContextConfig {
|
|
|
16
16
|
siteSecret: string;
|
|
17
17
|
adapters?: ServiceAdapters;
|
|
18
18
|
credentials: WordPressCredentials;
|
|
19
|
-
|
|
19
|
+
introspection?: object;
|
|
20
20
|
/** WordPress plugins the registered integrations need, checked against what each response reports. */
|
|
21
21
|
integrationPlugins?: IntegrationPluginRequirement[];
|
|
22
22
|
}
|
|
23
|
-
type
|
|
23
|
+
type SessionFn = () => Promise<AuthUser | null>;
|
|
24
24
|
type ConnInfoFn = () => Promise<ConnInfo | null>;
|
|
25
25
|
type VerifyCaptchaFn = (token: string) => Promise<boolean>;
|
|
26
26
|
type VerifyPreviewTokenFn = (token: string) => Promise<PreviewTokenPayload | null>;
|
|
@@ -46,8 +46,8 @@ interface ProcedureContext {
|
|
|
46
46
|
config: ContextConfig;
|
|
47
47
|
/** Resolve the caller's connection info (IP, geo) via the geo adapter, or `null`. */
|
|
48
48
|
getConnInfo: ConnInfoFn;
|
|
49
|
-
/** Resolve the authenticated
|
|
50
|
-
|
|
49
|
+
/** Resolve the authenticated session via the auth adapter, or `null`. */
|
|
50
|
+
getSession: SessionFn;
|
|
51
51
|
/** Read and write cookies through the cookies adapter. */
|
|
52
52
|
cookies: CookiesStorage;
|
|
53
53
|
/** Verify a CAPTCHA token via the captcha adapter. */
|
|
@@ -84,7 +84,7 @@ declare class Context {
|
|
|
84
84
|
email: EmailService;
|
|
85
85
|
getConnInfo: ConnInfoFn;
|
|
86
86
|
verifyCaptcha: VerifyCaptchaFn;
|
|
87
|
-
|
|
87
|
+
getSession: SessionFn;
|
|
88
88
|
verifyPreviewToken: VerifyPreviewTokenFn;
|
|
89
89
|
cookies: CookiesStorage;
|
|
90
90
|
invokedBy: "client";
|
|
@@ -98,7 +98,7 @@ declare class Context {
|
|
|
98
98
|
wordpress: WordPressTransport;
|
|
99
99
|
settings: SettingsService;
|
|
100
100
|
email: EmailService;
|
|
101
|
-
|
|
101
|
+
getSession: SessionFn;
|
|
102
102
|
getConnInfo: ConnInfoFn;
|
|
103
103
|
verifyCaptcha: VerifyCaptchaFn;
|
|
104
104
|
verifyPreviewToken: VerifyPreviewTokenFn;
|
|
@@ -107,9 +107,9 @@ declare class Context {
|
|
|
107
107
|
private createRestCookieStorage;
|
|
108
108
|
private createVerifyCaptchaFn;
|
|
109
109
|
private createConnInfoFn;
|
|
110
|
-
private
|
|
110
|
+
private createGetSessionFn;
|
|
111
111
|
private createVerifyPreviewTokenFn;
|
|
112
112
|
private createLogger;
|
|
113
113
|
}
|
|
114
114
|
//#endregion
|
|
115
|
-
export {
|
|
115
|
+
export { ConnInfoFn, Context, ContextConfig, ProcedureContext, SessionFn, VerifyCaptchaFn, VerifyPreviewTokenFn };
|
package/dist/context.js
CHANGED
|
@@ -55,7 +55,7 @@ var Context = class {
|
|
|
55
55
|
this.wordpress = createWordPressClient(new WordPressTransport({
|
|
56
56
|
credentials: config.credentials,
|
|
57
57
|
onResult: (result) => this.warnIfOutdated(result)
|
|
58
|
-
}), config.
|
|
58
|
+
}), config.introspection ?? {});
|
|
59
59
|
this.settings = new SettingsService(this.wordpress);
|
|
60
60
|
this.email = new EmailService(this.wordpress);
|
|
61
61
|
this.logger = this.createLogger();
|
|
@@ -102,7 +102,7 @@ var Context = class {
|
|
|
102
102
|
email: this.email,
|
|
103
103
|
getConnInfo: this.createConnInfoFn(request),
|
|
104
104
|
verifyCaptcha: this.createVerifyCaptchaFn(request),
|
|
105
|
-
|
|
105
|
+
getSession: this.createGetSessionFn(request),
|
|
106
106
|
verifyPreviewToken: this.createVerifyPreviewTokenFn(),
|
|
107
107
|
cookies: this.createRestCookieStorage(request, headers),
|
|
108
108
|
invokedBy: "client"
|
|
@@ -118,7 +118,7 @@ var Context = class {
|
|
|
118
118
|
wordpress: this.wordpress,
|
|
119
119
|
settings: this.settings,
|
|
120
120
|
email: this.email,
|
|
121
|
-
|
|
121
|
+
getSession: this.createGetSessionFn(null),
|
|
122
122
|
getConnInfo: this.createConnInfoFn(null),
|
|
123
123
|
verifyCaptcha: this.createVerifyCaptchaFn(null),
|
|
124
124
|
verifyPreviewToken: this.createVerifyPreviewTokenFn(),
|
|
@@ -176,9 +176,9 @@ var Context = class {
|
|
|
176
176
|
return await this.config.adapters?.geo?.getConnInfo?.(request) ?? null;
|
|
177
177
|
};
|
|
178
178
|
}
|
|
179
|
-
|
|
179
|
+
createGetSessionFn(request) {
|
|
180
180
|
return async () => {
|
|
181
|
-
return await Promise.resolve(this.config.adapters?.auth?.
|
|
181
|
+
return await Promise.resolve(this.config.adapters?.auth?.getSession?.(request)) ?? null;
|
|
182
182
|
};
|
|
183
183
|
}
|
|
184
184
|
createVerifyPreviewTokenFn() {
|
package/dist/index.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { buildWordPressRequest, createWordPressClient, wpEndpoint } from "./word
|
|
|
5
5
|
import { isWordPressResourceError } from "./wordpress/utils.js";
|
|
6
6
|
import "./wordpress/index.js";
|
|
7
7
|
import { DevPluginSource, Fixture, FixtureCleanupFn, FixtureSeedFn, FixtureSettleFn, JsonValue, LocalPlugin, PluginSource, SeedContext, SettleContext, TestAdminUser, TestCredentials, TestUser, defineFixture, isLocalPlugin } from "./cli/wp/types.js";
|
|
8
|
-
import { AuthAdapter,
|
|
8
|
+
import { AuthAdapter, AuthGetSession, AuthUser, authMock, createAuthAdapter } from "./adapters/auth.js";
|
|
9
9
|
import { CaptchaAdapter, altcha, arkose, createCaptchaAdapter, friendlyCaptcha, hcaptcha, recaptcha, turnstile } from "./adapters/captcha.js";
|
|
10
10
|
import { CurrencyFormat, IdentifierInput, LIST_ORDER, ListMetadata, ListOrder, PreviewTokenData, PreviewTokenPayload, customFieldsSchema } from "./shared/schema.js";
|
|
11
11
|
import { AnyContext, AnyNestedClient, CookiesAdapter, CookiesDeleteAll, CookiesGetAll, CookiesSetAll, HTTPMethod, List, MaybeOptionalOptions, RedirectInput, RedirectStatus } from "./shared/types.js";
|
|
@@ -18,7 +18,7 @@ import { AuthorsSettings, AuthorsSettingsInput, BrandSettings, BrandSettingsInpu
|
|
|
18
18
|
import { IconDescriptor, ManifestIcon, ResolvedIcons, resolveIcons } from "./brand/icons.js";
|
|
19
19
|
import { CookiesStorage } from "./cookie.js";
|
|
20
20
|
import { SettingsService } from "./settings/service.js";
|
|
21
|
-
import {
|
|
21
|
+
import { ConnInfoFn, Context, ContextConfig, ProcedureContext, SessionFn, VerifyCaptchaFn, VerifyPreviewTokenFn } from "./context.js";
|
|
22
22
|
import { Post, PostCustomFields, PostCustomFieldsSchema } from "./post/schema.js";
|
|
23
23
|
import { Page, PageCustomFields, PageCustomFieldsSchema } from "./page/schema.js";
|
|
24
24
|
import { Category, CategoryCustomFields, CategoryCustomFieldsSchema } from "./category/schema.js";
|
|
@@ -43,4 +43,4 @@ import { ShaAlgorithm, compare, hash, hmac } from "./shared/crypto.js";
|
|
|
43
43
|
import { Identifier, parseIdentifier } from "./shared/identifier.js";
|
|
44
44
|
import { createOrpcRouter } from "./shared/router.js";
|
|
45
45
|
import { deserializeCurrencyFormat, deserializeListMetadata, emptyList, serializeCurrencyFormat } from "./shared/serialize.js";
|
|
46
|
-
export { ActiveWordPressClient, AnyContext, AnyEventSchema, AnyEvents, AnyIntegration, AnyKizloConfig, AnyMiddleware, AnyNestedClient, AnyProcedure, AnyProcedureTree, AuthAdapter,
|
|
46
|
+
export { ActiveWordPressClient, AnyContext, AnyEventSchema, AnyEvents, AnyIntegration, AnyKizloConfig, AnyMiddleware, AnyNestedClient, AnyProcedure, AnyProcedureTree, AuthAdapter, AuthGetSession, AuthUser, AuthorsSettings, AuthorsSettingsInput, BaseHandlerOptions, BrandSettings, BrandSettingsInput, COMMON_ERRORS, CONTENT_TYPES, CORE_PROCEDURES, CaptchaAdapter, type Category, type CategoryCustomFields, CategoryCustomFieldsSchema, CommonErrorCode, CommonErrorLiteral, CommonErrorMap, ConnInfo, ConnInfoFn, ConsoleLogAdapterOptions, ContentType, Context, ContextConfig, Contract, ContractProcedure, CookiesAdapter, CookiesDeleteAll, CookiesGetAll, CookiesSetAll, CookiesStorage, CoreProcedures, CrawlingSettings, CrawlingSettingsInput, CreateKizloOptions, CreateSitemapRouteOptions, CurrencyFormat, DefinedErrorMapLike, DevPluginSource, EnvReader, EnvRecord, EnvSource, ErrorDefinition, EventHandler, EventHandlerFn, ExtractIntegrationProcedures, ExtractMiddlewareContextOutput, ExtractParams, ExtractProcedureByScope, Fixture, FixtureCleanupFn, FixtureSeedFn, FixtureSettleFn, GeoAdapter, GeoGetConnInfo, HTTPMethod, HeadlessSettings, HeadlessSettingsInput, IconDescriptor, Identifier, IdentifierInput, IdentitySettings, IdentitySettingsInput, InferEventUnion, InferIntegrationProcedures, InferMiddlewares, InferProcedureData, InferProcedureError, InferProcedureInput, InferProcedureResult, Integration, IntegrationRequirements, InvocationScope, JsonValue, Kizlo, KizloClient, KizloClientConfig, KizloConfig, KizloEnv, KizloError, KizloErrorOptions, KizloErrorUnion, KizloResult, LIST_ORDER, List, ListMetadata, ListOrder, ListSitemapUrlInput, ListSitemapUrlInputBase, LocalPlugin, LogLevel, LogPayload, Logger, LoggerAdapter, ManifestIcon, MaybeCallerOptions, MaybeOptionalOptions, Middleware, MiddlewareHandler, MiddlewareNextFn, MiddlewareOptions, MiddlewareResult, OpenapiPart, OrganizationFounder, OrganizationSettings, OrganizationSettingsInput, type Page, type PageCustomFields, PageCustomFieldsSchema, PersonSettings, PersonSettingsInput, PluginSource, type Post, type PostCustomFields, PostCustomFieldsSchema, PostStatusDefinition, PostTypeSettings, PostTypeSettingsInput, PreviewTokenData, PreviewTokenPayload, Procedure, ProcedureContext, ProcedureErrors, ProcedureHandler, ProcedureMethod, ProcedureOptions, ProcedureTreeDepthTuple, RedirectInput, RedirectStatus, ResolveParamsPart, ResolvedIcons, ResolvedSchemaInput, ResolvedSchemaOutput, ResultClient, Robots, RobotsRule, RootProcedures, S2SClient, SITEMAP_BASE, SITEMAP_INDEX_SLUG, SchemaIO, SeedContext, Seo, SeoHead, SeoSchema, ServiceAdapters, SessionFn, Settings, SettingsService, SettleContext, ShaAlgorithm, SiteSettings, SiteSettingsInput, Sitemap, SitemapIndex, SitemapIndexEntry, SitemapList, SitemapRouteExtra, SitemapUrl, SitemapUrlImage, SitemapUrlList, SocialProfile, type Tag, type TagCustomFields, TagCustomFieldsSchema, TaxonomySettings, TaxonomySettingsInput, TestAdminUser, TestCredentials, TestUser, ThrowableErrorFn, ThrowableErrorMap, UploadsSettings, UploadsSettingsInput, VerifyCaptchaFn, VerifyPreviewTokenFn, WEB_MANIFEST_ROUTE, WPK_RobotRule, WPK_Robots, WPK_Seo, WPK_Sitemap, WPK_SitemapUrl, WPK_SitemapUrlImage, WP_CallOptions, WP_Client, WP_CommonErrorCode, WP_CurrencyFormat, WP_CustomFields, WP_CustomFieldsPath, WP_Endpoint, WP_EndpointData, WP_EndpointDefinition, WP_EndpointError, WP_EndpointInput, WP_EndpointPath, WP_EndpointResult, WP_Error, WP_ErrorData, WP_Failure, WP_List, WP_ListMetadata, WP_RequestBuild, WP_RequestContentType, WP_RequestInput, WP_RequestMethod, WP_ResponseContentType, WP_Result, WP_Success, WP_TransportFailure, WP_TypedHeaders, WebManifest, WebhookOptions, WebhookSettings, WebhookSettingsInput, WithCommonErrorMap, WordPressClientRegistry, WordPressCredentials, WordPressCustomFieldsRegistry, WordPressEndpointRegistry, WordPressEnv, WordPressTransport, WordPressTransportOptions, WordPressTransportResult, altcha, arkose, assertIntegrationEndpoints, assertIntegrationEnv, authMock, buildProcedure, buildWebManifest, buildWordPressRequest, combineDetailed, compare, consoleLog, createAuthAdapter, createCaptchaAdapter, createCookiesAdapter, createEventHandler, createGeoAdapter, createIntegration, createKizlo, createKizloClient, createLoggerAdapter, createManifestRoute, createMiddleware, createOrpcRouter, createProcedure, createResultClient, createSitemapRedirectRoute, createSitemapRoute, createThrowableErrorMap, createWebhookRouter, createWordPressClient, customFieldsSchema, defineErrorMap, defineFixture, deserializeCurrencyFormat, deserializeListMetadata, deserializeSeo, emptyList, friendlyCaptcha, generateContract, geoMock, geoVercelNext, handleUnexpectedError, hash, hcaptcha, hmac, integrationEnv, isContractProcedure, isKizloError, isLocalPlugin, isWordPressResourceError, mergeServiceAdapters, missingEndpoints, missingEnv, noopAdapter, parseIdentifier, parseSitemapSlug, readEnv, recaptcha, renderJsonLd, renderSitemapIndex, renderUrlSet, resolveIcons, resolveKizloConfig, resolveWordPressConnection, restoreContract, schemaType, serializeCurrencyFormat, sitemapEntryPath, toKizloError, turnstile, wpEndpoint, xmlResponse };
|
package/dist/kizlo.d.ts
CHANGED
|
@@ -14,7 +14,7 @@ interface KizloConfig<TIntegrations extends readonly AnyIntegration[]> {
|
|
|
14
14
|
integrations?: TIntegrations;
|
|
15
15
|
logging?: false | LogLevel;
|
|
16
16
|
credentials: WordPressCredentials;
|
|
17
|
-
|
|
17
|
+
introspection?: object;
|
|
18
18
|
}
|
|
19
19
|
type RootProcedures<TIntegrations extends readonly AnyIntegration[]> = InferIntegrationProcedures<TIntegrations> & CoreProcedures;
|
|
20
20
|
type S2SClient<TIntegrations extends readonly AnyIntegration[]> = ResultClient<RootProcedures<TIntegrations>>;
|
|
@@ -41,21 +41,18 @@ interface CreateKizloOptions<TIntegrations extends readonly AnyIntegration[] = [
|
|
|
41
41
|
/** Enable Kizlo's built-in console logger at this level. */
|
|
42
42
|
logging?: false | LogLevel;
|
|
43
43
|
/**
|
|
44
|
-
* The generated
|
|
45
|
-
* `
|
|
46
|
-
* `wordpressUsername`, and `wordpressPassword` values contributed by integrations.
|
|
44
|
+
* The generated WordPress introspection tree to run the typed client against. Pass the
|
|
45
|
+
* `introspection` export of your generated barrel. WordPress credentials resolve from the
|
|
46
|
+
* `wordpressUrl`, `wordpressUsername`, and `wordpressPassword` values contributed by integrations.
|
|
47
47
|
*/
|
|
48
|
-
|
|
49
|
-
endpoints?: object;
|
|
50
|
-
credentials?: Partial<WordPressCredentials>;
|
|
51
|
-
};
|
|
48
|
+
introspection?: object;
|
|
52
49
|
}
|
|
53
50
|
/**
|
|
54
51
|
* Compose environment sources without letting `undefined` erase an earlier value, then resolve
|
|
55
52
|
* Kizlo's active WordPress connection from the canonical `mode` value.
|
|
56
53
|
*/
|
|
57
54
|
declare function integrationEnv(integrations: readonly AnyIntegration[]): EnvReader;
|
|
58
|
-
declare function resolveWordPressConnection(
|
|
55
|
+
declare function resolveWordPressConnection(env: EnvReader): {
|
|
59
56
|
credentials: WordPressCredentials;
|
|
60
57
|
};
|
|
61
58
|
/**
|
package/dist/kizlo.js
CHANGED
|
@@ -30,7 +30,7 @@ var Kizlo = class {
|
|
|
30
30
|
adapters: integrations.adapters,
|
|
31
31
|
siteSecret: config.siteSecret,
|
|
32
32
|
credentials: config.credentials,
|
|
33
|
-
|
|
33
|
+
introspection: config.introspection,
|
|
34
34
|
integrationPlugins: integrations.plugins
|
|
35
35
|
});
|
|
36
36
|
this.procedures = Object.assign(Object.assign({}, {
|
|
@@ -105,7 +105,7 @@ var Kizlo = class {
|
|
|
105
105
|
if (reservedIds.has(integration.id)) throw new KizloError("INTEGRATION_ID_CONFLICT", { message: `The integration id "${integration.id}" is reserved by Kizlo. Choose a different integration id.` });
|
|
106
106
|
if (integrationIds.has(integration.id)) throw new KizloError("INTEGRATION_ID_CONFLICT", { message: `The integration id "${integration.id}" is registered more than once. Give every integration a unique id.` });
|
|
107
107
|
integrationIds.add(integration.id);
|
|
108
|
-
if (!generating) assertIntegrationEndpoints(integration, this.config.
|
|
108
|
+
if (!generating) assertIntegrationEndpoints(integration, this.config.introspection ?? {});
|
|
109
109
|
plugins.push(...integration.requires?.plugins ?? []);
|
|
110
110
|
if (integration.procedures && Object.keys(integration.procedures).length > 0) procedures[integration.id] = integration.procedures;
|
|
111
111
|
for (const handler of integration.events ?? []) events.push(handler);
|
|
@@ -161,12 +161,11 @@ function requireEnvValue(name, env) {
|
|
|
161
161
|
if (isContractGeneration()) return "";
|
|
162
162
|
throw new KizloError("MISSING_ENV_VALUE", { message: `Kizlo requires the "${name}" environment value. Provide it through an integration or an explicit createKizlo option.` });
|
|
163
163
|
}
|
|
164
|
-
function resolveWordPressConnection(
|
|
165
|
-
const credentials = options?.wordpress?.credentials;
|
|
164
|
+
function resolveWordPressConnection(env) {
|
|
166
165
|
return { credentials: {
|
|
167
|
-
url:
|
|
168
|
-
username:
|
|
169
|
-
password:
|
|
166
|
+
url: requireEnvValue("wordpressUrl", env),
|
|
167
|
+
username: requireEnvValue("wordpressUsername", env),
|
|
168
|
+
password: requireEnvValue("wordpressPassword", env)
|
|
170
169
|
} };
|
|
171
170
|
}
|
|
172
171
|
/**
|
|
@@ -176,14 +175,14 @@ function resolveKizloConfig(options) {
|
|
|
176
175
|
const integrations = options?.integrations ?? [];
|
|
177
176
|
const env = integrationEnv(integrations);
|
|
178
177
|
if (!isContractGeneration()) for (const integration of integrations) assertIntegrationEnv(integration, env);
|
|
179
|
-
const { credentials } = resolveWordPressConnection(
|
|
178
|
+
const { credentials } = resolveWordPressConnection(env);
|
|
180
179
|
return {
|
|
181
180
|
baseUrl: options?.baseUrl ?? requireEnvValue("baseUrl", env),
|
|
182
181
|
siteSecret: options?.siteSecret ?? requireEnvValue("siteSecret", env),
|
|
183
182
|
integrations,
|
|
184
183
|
logging: options?.logging,
|
|
185
184
|
credentials,
|
|
186
|
-
|
|
185
|
+
introspection: options?.introspection
|
|
187
186
|
};
|
|
188
187
|
}
|
|
189
188
|
/**
|
package/dist/package.js
CHANGED
package/dist/procedures.d.ts
CHANGED
package/dist/test/auth.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
//#region src/test/auth.ts
|
|
2
2
|
function testAuthAdapter(user) {
|
|
3
|
-
return {
|
|
3
|
+
return { getSession() {
|
|
4
4
|
return {
|
|
5
|
-
id: user.
|
|
5
|
+
id: user.id,
|
|
6
6
|
email: user.email,
|
|
7
|
-
phone: user.phone,
|
|
8
7
|
firstName: user.firstName,
|
|
9
8
|
lastName: user.lastName
|
|
10
9
|
};
|
package/dist/test/users.d.ts
CHANGED
|
@@ -2,12 +2,10 @@ import { TestCredentials } from "../cli/wp/types.js";
|
|
|
2
2
|
|
|
3
3
|
//#region src/test/users.d.ts
|
|
4
4
|
interface TestAuthAdapterUser {
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
id: string;
|
|
6
|
+
email: string;
|
|
7
7
|
firstName: string;
|
|
8
8
|
lastName: string;
|
|
9
|
-
email: string;
|
|
10
|
-
phone: string;
|
|
11
9
|
}
|
|
12
10
|
declare function toTestUser(user: TestCredentials["users"]["user"]): TestAuthAdapterUser;
|
|
13
11
|
//#endregion
|
package/dist/test/users.js
CHANGED
|
@@ -1,15 +1,10 @@
|
|
|
1
1
|
//#region src/test/users.ts
|
|
2
|
-
const STATIC_FIELDS = {
|
|
3
|
-
firstName: "Test",
|
|
4
|
-
lastName: "Customer",
|
|
5
|
-
email: "customer@example.com",
|
|
6
|
-
phone: "+10000000002"
|
|
7
|
-
};
|
|
8
2
|
function toTestUser(user) {
|
|
9
3
|
return {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
4
|
+
id: String(user.id),
|
|
5
|
+
email: user.email,
|
|
6
|
+
firstName: "Test",
|
|
7
|
+
lastName: "Customer"
|
|
13
8
|
};
|
|
14
9
|
}
|
|
15
10
|
|
package/dist/test.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DevPluginSource, Fixture, FixtureCleanupFn, FixtureSeedFn, FixtureSettleFn, JsonValue, LocalPlugin, PluginSource, SeedContext, SettleContext, TestAdminUser, TestCredentials, TestUser, defineFixture, isLocalPlugin } from "./cli/wp/types.js";
|
|
2
|
-
import { COMPOSE_FILE, CONFIG_FILES, CREDENTIALS_REL, DEFAULT_PLUGINS, DEFAULT_PORT, DEFAULT_WORDPRESS_TAG, LOCAL_DIR_REL, OPCACHE_INI, REMAP_ENTRYPOINT, SEED_MARKER_OPTION, SEED_VERSION, TEST_ADMIN, TEST_USER,
|
|
2
|
+
import { COMPOSE_FILE, CONFIG_FILES, CREDENTIALS_REL, DEFAULT_PLUGINS, DEFAULT_PORT, DEFAULT_WORDPRESS_TAG, INTROSPECTION_META_REL, LOCAL_DIR_REL, OPCACHE_INI, REMAP_ENTRYPOINT, SEED_MARKER_OPTION, SEED_VERSION, TEST_ADMIN, TEST_USER, githubRelease, kizloRelease } from "./cli/wp/constants.js";
|
|
3
3
|
import { DockerStack, DockerStatus, RunResult, Stack, StackStatus, compose, composeDown, composePull, composeStop, composeUp, createStack, dockerAvailable, dockerHint, dockerStatus, runningProjectContainers, stackStatus, stopProjectContainers, wpCli, wpEval } from "./cli/wp/docker.js";
|
|
4
4
|
import { activateLocalPlugin, credentialsPath, ensurePlugin, ensurePlugins, findConfigDir, getTestCredentials, isSeeded, recordedPort, resolvePluginSource, settleFixtures } from "./cli/wp/utils.js";
|
|
5
5
|
import { TestAuthAdapterUser, toTestUser } from "./test/users.js";
|
|
@@ -8,4 +8,4 @@ import { CAPTCHA_TEST_TOKEN_PASS, captchaMock } from "./test/captcha.js";
|
|
|
8
8
|
import { menuFixture } from "./menu/fixture.js";
|
|
9
9
|
import { postFixture } from "./post/fixture.js";
|
|
10
10
|
import { coreFixtures } from "./test/fixtures.js";
|
|
11
|
-
export { CAPTCHA_TEST_TOKEN_PASS, COMPOSE_FILE, CONFIG_FILES, CREDENTIALS_REL, DEFAULT_PLUGINS, DEFAULT_PORT, DEFAULT_WORDPRESS_TAG, DevPluginSource, DockerStack, DockerStatus, Fixture, FixtureCleanupFn, FixtureSeedFn, FixtureSettleFn, JsonValue, LOCAL_DIR_REL, LocalPlugin, OPCACHE_INI, PluginSource, REMAP_ENTRYPOINT, RunResult, SEED_MARKER_OPTION, SEED_VERSION, SeedContext, SettleContext, Stack, StackStatus, TEST_ADMIN, TEST_USER, TestAdminUser, TestAuthAdapterUser, TestCredentials, TestUser,
|
|
11
|
+
export { CAPTCHA_TEST_TOKEN_PASS, COMPOSE_FILE, CONFIG_FILES, CREDENTIALS_REL, DEFAULT_PLUGINS, DEFAULT_PORT, DEFAULT_WORDPRESS_TAG, DevPluginSource, DockerStack, DockerStatus, Fixture, FixtureCleanupFn, FixtureSeedFn, FixtureSettleFn, INTROSPECTION_META_REL, JsonValue, LOCAL_DIR_REL, LocalPlugin, OPCACHE_INI, PluginSource, REMAP_ENTRYPOINT, RunResult, SEED_MARKER_OPTION, SEED_VERSION, SeedContext, SettleContext, Stack, StackStatus, TEST_ADMIN, TEST_USER, TestAdminUser, TestAuthAdapterUser, TestCredentials, TestUser, activateLocalPlugin, captchaMock, compose, composeDown, composePull, composeStop, composeUp, coreFixtures, createStack, credentialsPath, defineFixture, dockerAvailable, dockerHint, dockerStatus, ensurePlugin, ensurePlugins, findConfigDir, getTestCredentials, githubRelease, isLocalPlugin, isSeeded, kizloRelease, menuFixture, postFixture, recordedPort, resolvePluginSource, runningProjectContainers, settleFixtures, stackStatus, stopProjectContainers, testAuthAdapter, toTestUser, wpCli, wpEval };
|
package/dist/test.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { defineFixture, isLocalPlugin } from "./cli/wp/types.js";
|
|
2
|
-
import { COMPOSE_FILE, CONFIG_FILES, CREDENTIALS_REL, DEFAULT_PLUGINS, DEFAULT_PORT, DEFAULT_WORDPRESS_TAG, LOCAL_DIR_REL, OPCACHE_INI, REMAP_ENTRYPOINT, SEED_MARKER_OPTION, SEED_VERSION, TEST_ADMIN, TEST_USER,
|
|
2
|
+
import { COMPOSE_FILE, CONFIG_FILES, CREDENTIALS_REL, DEFAULT_PLUGINS, DEFAULT_PORT, DEFAULT_WORDPRESS_TAG, INTROSPECTION_META_REL, LOCAL_DIR_REL, OPCACHE_INI, REMAP_ENTRYPOINT, SEED_MARKER_OPTION, SEED_VERSION, TEST_ADMIN, TEST_USER, githubRelease, kizloRelease } from "./cli/wp/constants.js";
|
|
3
3
|
import { compose, composeDown, composePull, composeStop, composeUp, createStack, dockerAvailable, dockerHint, dockerStatus, runningProjectContainers, stackStatus, stopProjectContainers, wpCli, wpEval } from "./cli/wp/docker.js";
|
|
4
4
|
import { activateLocalPlugin, credentialsPath, ensurePlugin, ensurePlugins, findConfigDir, getTestCredentials, isSeeded, recordedPort, resolvePluginSource, settleFixtures } from "./cli/wp/utils.js";
|
|
5
5
|
import { testAuthAdapter } from "./test/auth.js";
|
|
@@ -9,4 +9,4 @@ import { postFixture } from "./post/fixture.js";
|
|
|
9
9
|
import { coreFixtures } from "./test/fixtures.js";
|
|
10
10
|
import { toTestUser } from "./test/users.js";
|
|
11
11
|
|
|
12
|
-
export { CAPTCHA_TEST_TOKEN_PASS, COMPOSE_FILE, CONFIG_FILES, CREDENTIALS_REL, DEFAULT_PLUGINS, DEFAULT_PORT, DEFAULT_WORDPRESS_TAG, LOCAL_DIR_REL, OPCACHE_INI, REMAP_ENTRYPOINT, SEED_MARKER_OPTION, SEED_VERSION, TEST_ADMIN, TEST_USER,
|
|
12
|
+
export { CAPTCHA_TEST_TOKEN_PASS, COMPOSE_FILE, CONFIG_FILES, CREDENTIALS_REL, DEFAULT_PLUGINS, DEFAULT_PORT, DEFAULT_WORDPRESS_TAG, INTROSPECTION_META_REL, LOCAL_DIR_REL, OPCACHE_INI, REMAP_ENTRYPOINT, SEED_MARKER_OPTION, SEED_VERSION, TEST_ADMIN, TEST_USER, activateLocalPlugin, captchaMock, compose, composeDown, composePull, composeStop, composeUp, coreFixtures, createStack, credentialsPath, defineFixture, dockerAvailable, dockerHint, dockerStatus, ensurePlugin, ensurePlugins, findConfigDir, getTestCredentials, githubRelease, isLocalPlugin, isSeeded, kizloRelease, menuFixture, postFixture, recordedPort, resolvePluginSource, runningProjectContainers, settleFixtures, stackStatus, stopProjectContainers, testAuthAdapter, toTestUser, wpCli, wpEval };
|
|
@@ -66,7 +66,8 @@ function buildWordPressRequest(definition, input) {
|
|
|
66
66
|
body: rest,
|
|
67
67
|
requestContentType: definition.requestContentType
|
|
68
68
|
} : { searchParams: rest },
|
|
69
|
-
responseContentTypes: definition.responseContentTypes
|
|
69
|
+
responseContentTypes: definition.responseContentTypes,
|
|
70
|
+
dataResponseStatuses: definition.dataResponseStatuses
|
|
70
71
|
},
|
|
71
72
|
error: null
|
|
72
73
|
};
|
|
@@ -3,6 +3,7 @@ import { WP_CommonErrorCode, WP_ErrorData } from "./types.js";
|
|
|
3
3
|
//#region src/wordpress/error.d.ts
|
|
4
4
|
declare class WP_Error<TCode extends string = string> extends Error {
|
|
5
5
|
code: TCode | WP_CommonErrorCode;
|
|
6
|
+
readonly data: unknown;
|
|
6
7
|
constructor(error: WP_ErrorData<TCode>);
|
|
7
8
|
}
|
|
8
9
|
//#endregion
|
package/dist/wordpress/error.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
//#region src/wordpress/error.ts
|
|
2
2
|
var WP_Error = class extends Error {
|
|
3
3
|
code;
|
|
4
|
+
data;
|
|
4
5
|
constructor(error) {
|
|
5
6
|
super(error.message ?? "Internal server error, please try again.");
|
|
6
7
|
this.name = "WordPress Error";
|
|
7
8
|
this.code = error.code;
|
|
9
|
+
this.data = error.data ?? null;
|
|
8
10
|
}
|
|
9
11
|
};
|
|
10
12
|
|
|
@@ -6,7 +6,7 @@ import { PLUGIN_VERSION_HEADER } from "@kizlo/shared";
|
|
|
6
6
|
* WordPress could not be asked, or did not answer with a contract: a transport failure, a non-2xx
|
|
7
7
|
* status, a body that is not JSON. A document that parsed is never one of these, however much of it
|
|
8
8
|
* WordPress had to exclude, because what to do about an exclusion is the generator's policy and not
|
|
9
|
-
* this function's. It reports; {@link
|
|
9
|
+
* this function's. It reports; {@link generateIntrospectionOnce} decides.
|
|
10
10
|
*/
|
|
11
11
|
var IntrospectionFetchError = class extends Error {
|
|
12
12
|
/**
|
|
@@ -182,6 +182,9 @@ function responseStatus(status) {
|
|
|
182
182
|
function isSuccessStatus(status) {
|
|
183
183
|
return /^2\d\d$/.test(status);
|
|
184
184
|
}
|
|
185
|
+
function isWordPressErrorResponse(response) {
|
|
186
|
+
return response.body?.$ref === "kizlo.error";
|
|
187
|
+
}
|
|
185
188
|
/**
|
|
186
189
|
* Every failing status of an endpoint carries the same error union, so spelling one member per
|
|
187
190
|
* status would repeat it four or five times for no discrimination anyone can act on. They collapse
|
|
@@ -193,10 +196,10 @@ function renderResult(apiId, operationId, operation, context) {
|
|
|
193
196
|
const name = endpointName(apiId, operationId, "EndpointResult");
|
|
194
197
|
const errors = operation.errors.map(literal).join(" | ") || "never";
|
|
195
198
|
const responses = sortedEntries(operation.responses);
|
|
196
|
-
const failures = responses.filter(([
|
|
199
|
+
const failures = responses.filter(([, response]) => isWordPressErrorResponse(response));
|
|
197
200
|
const headerNames = [...new Set(responses.flatMap(([, response]) => responseHeaderNames(response, context)))].sort((left, right) => left.localeCompare(right)).map(literal).join(" | ");
|
|
198
201
|
const sharedHeaderNames = headerNames ? `, ${headerNames}` : "";
|
|
199
|
-
const variants = responses.filter(([
|
|
202
|
+
const variants = responses.filter(([, response]) => !isWordPressErrorResponse(response)).map(([status, response]) => `WP_Success<${responseBody(response, context)}, ${status}, ${responseHeaders(response, context)}${sharedHeaderNames}>`);
|
|
200
203
|
if (new Set([NO_HEADERS, ...failures.map(([, response]) => responseHeaders(response, context))]).size === 1) variants.push(`WP_Failure<${errors}, number, ${NO_HEADERS}${sharedHeaderNames}>`);
|
|
201
204
|
else {
|
|
202
205
|
for (const [status, response] of failures) variants.push(`WP_Failure<${errors}, ${responseStatus(status)}, ${responseHeaders(response, context)}${sharedHeaderNames}>`);
|
|
@@ -257,13 +260,15 @@ function sortedEndpoints(node) {
|
|
|
257
260
|
function endpointDefinition(entry) {
|
|
258
261
|
const pathParameters = sortedEntries(entry.operation.input.properties ?? {}).filter(([, schema]) => schema.in === "path").map(([name]) => name);
|
|
259
262
|
const responseContentTypes = Object.fromEntries(sortedEntries(entry.operation.responses).map(([status, response]) => [status, response.content_type]));
|
|
263
|
+
const dataResponseStatuses = sortedEntries(entry.operation.responses).filter(([status, response]) => !isSuccessStatus(status) && !isWordPressErrorResponse(response)).map(([status]) => status);
|
|
260
264
|
return {
|
|
261
265
|
namespace: entry.namespace,
|
|
262
266
|
path: entry.path,
|
|
263
267
|
method: entry.operation.method,
|
|
264
268
|
pathParameters,
|
|
265
269
|
...entry.operation.input.content_type ? { requestContentType: entry.operation.input.content_type } : {},
|
|
266
|
-
responseContentTypes
|
|
270
|
+
responseContentTypes,
|
|
271
|
+
...dataResponseStatuses.length > 0 ? { dataResponseStatuses } : {}
|
|
267
272
|
};
|
|
268
273
|
}
|
|
269
274
|
function renderRecord(value) {
|
|
@@ -279,7 +284,8 @@ function renderDefinition(definition) {
|
|
|
279
284
|
`method: ${literal(definition.method)}`,
|
|
280
285
|
`pathParameters: [${definition.pathParameters.map(literal).join(", ")}]`,
|
|
281
286
|
...definition.requestContentType ? [`requestContentType: ${literal(definition.requestContentType)}`] : [],
|
|
282
|
-
`responseContentTypes: ${renderRecord(definition.responseContentTypes)}
|
|
287
|
+
`responseContentTypes: ${renderRecord(definition.responseContentTypes)}`,
|
|
288
|
+
...definition.dataResponseStatuses?.length ? [`dataResponseStatuses: [${definition.dataResponseStatuses.map(literal).join(", ")}]`] : []
|
|
283
289
|
].join(", ")} }`;
|
|
284
290
|
}
|
|
285
291
|
/**
|
|
@@ -377,7 +383,7 @@ function renderRegistries(tree, document) {
|
|
|
377
383
|
return [
|
|
378
384
|
`declare module "kizlo" {`,
|
|
379
385
|
`\tinterface WordPressClientRegistry {`,
|
|
380
|
-
`\t\
|
|
386
|
+
`\t\tintrospection: typeof introspection`,
|
|
381
387
|
`\t}`,
|
|
382
388
|
`\tinterface WordPressEndpointRegistry {`,
|
|
383
389
|
...endpoints,
|
|
@@ -425,8 +431,8 @@ function generateWordPressModule(document) {
|
|
|
425
431
|
const endpointBody = renderEndpointNode(tree, " ");
|
|
426
432
|
const moduleBody = [
|
|
427
433
|
body,
|
|
428
|
-
`export const
|
|
429
|
-
`export type WordPressClient = WP_Client<typeof
|
|
434
|
+
`export const introspection = ${endpointBody}`,
|
|
435
|
+
`export type WordPressClient = WP_Client<typeof introspection>`,
|
|
430
436
|
renderRegistries(tree, document)
|
|
431
437
|
].join(DECLARATION_SEPARATOR);
|
|
432
438
|
const imports = `import { ${kizloImports(moduleBody, endpointBody !== "{}")} } from "kizlo"`;
|