kizlo 0.1.0 → 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/dist/adapters/auth.d.ts +11 -2
- package/dist/adapters/auth.js +5 -1
- package/dist/adapters/captcha.d.ts +3 -1
- package/dist/adapters/captcha.js +5 -1
- package/dist/adapters/cookies.d.ts +7 -0
- package/dist/adapters/cookies.js +8 -0
- package/dist/adapters/geo.d.ts +13 -2
- package/dist/adapters/geo.js +5 -1
- package/dist/adapters/logger.d.ts +8 -1
- package/dist/adapters/logger.js +5 -1
- package/dist/cli/banner.js +12 -1
- package/dist/cli/commands/dev.js +262 -0
- package/dist/cli/commands/init.js +235 -43
- package/dist/cli/commands/test.js +133 -34
- package/dist/cli/commands/watch.js +2 -2
- package/dist/cli/daemon/config.js +73 -7
- package/dist/cli/daemon/generate.js +1 -1
- package/dist/cli/daemon/lock.js +1 -1
- package/dist/cli/index.js +1 -1
- package/dist/cli/presets/base.js +8 -1
- package/dist/cli/presets/nextjs.js +1 -1
- package/dist/cli/utils.js +90 -6
- package/dist/cli/wp/bootstrap.js +13 -10
- package/dist/cli/wp/byo.js +113 -0
- package/dist/cli/wp/compose/docker-compose.yml +13 -2
- package/dist/cli/wp/compose/opcache.ini +16 -0
- package/dist/cli/wp/compose/override.js +104 -0
- package/dist/cli/wp/compose/override.test.ts +115 -0
- package/dist/cli/wp/compose/override.ts +134 -0
- package/dist/cli/wp/compose/remap-entrypoint.sh +17 -0
- package/dist/cli/wp/constants.js +7 -8
- package/dist/cli/wp/dev.js +146 -0
- package/dist/cli/wp/docker.d.ts +55 -15
- package/dist/cli/wp/docker.js +102 -41
- package/dist/cli/wp/ports.js +72 -0
- package/dist/cli/wp/session.js +150 -0
- package/dist/cli/wp/settings.js +73 -0
- package/dist/cli/wp/setup.js +1 -1
- package/dist/cli/wp/stack.js +58 -0
- package/dist/cli/wp/types.d.ts +26 -5
- package/dist/cli/wp/types.js +5 -1
- package/dist/cli/wp/utils.d.ts +29 -2
- package/dist/cli/wp/utils.js +61 -3
- package/dist/cli/wp/watchdog.d.ts +1 -0
- package/dist/cli/wp/watchdog.js +45 -0
- package/dist/client.d.ts +1 -1
- package/dist/client.js +2 -2
- package/dist/config.d.ts +49 -3
- package/dist/context.d.ts +12 -1
- package/dist/context.js +1 -1
- package/dist/index.d.ts +16 -11
- package/dist/index.js +10 -6
- package/dist/integrations/nextjs/kizlo.server.d.ts +1 -1
- package/dist/integrations/nextjs/kizlo.server.js +2 -2
- package/dist/integrations/nextjs/utils.js +2 -2
- package/dist/kizlo.d.ts +27 -6
- package/dist/kizlo.js +24 -11
- package/dist/menu/fixture.d.ts +1 -1
- package/dist/package.js +1 -1
- package/dist/post/fixture.d.ts +1 -1
- package/dist/service.d.ts +2 -0
- package/dist/service.js +3 -0
- package/dist/settings/service.d.ts +22 -0
- package/dist/settings/service.interface.d.ts +134 -0
- package/dist/settings/service.js +43 -0
- package/dist/shared/error.d.ts +16 -5
- package/dist/shared/error.js +4 -0
- package/dist/shared/extension.d.ts +2 -0
- package/dist/shared/middleware.d.ts +13 -10
- package/dist/shared/middleware.js +7 -0
- package/dist/shared/procedure.d.ts +34 -28
- package/dist/shared/procedure.js +3 -6
- package/dist/shared/types.d.ts +19 -13
- package/dist/test/client.d.ts +5 -0
- package/dist/test/client.js +5 -0
- package/dist/test/server.d.ts +6 -0
- package/dist/test/server.js +6 -0
- package/dist/test.d.ts +4 -4
- package/dist/test.js +4 -4
- package/dist/webhook/index.d.ts +14 -13
- package/dist/webhook/index.js +5 -5
- package/dist/webhook/schema.d.ts +3 -3
- package/dist/webhook/schema.js +37 -37
- package/dist/webhook/utils.js +4 -4
- package/dist/wordpress/service.js +6 -0
- package/package.json +2 -2
- package/dist/cli/commands/wp.js +0 -66
package/dist/cli/wp/utils.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { isLocalPlugin } from "./types.js";
|
|
2
2
|
import { compose, wpCli } from "./docker.js";
|
|
3
|
-
import {
|
|
3
|
+
import { CONFIG_FILES, CREDENTIALS_REL, SEED_MARKER_OPTION, SEED_VERSION } from "./constants.js";
|
|
4
4
|
import { existsSync, readFileSync } from "node:fs";
|
|
5
|
+
import { basename, dirname, resolve } from "node:path";
|
|
5
6
|
|
|
6
7
|
//#region src/cli/wp/utils.ts
|
|
7
8
|
/**
|
|
@@ -32,6 +33,14 @@ async function isSeeded() {
|
|
|
32
33
|
function githubRelease(repo, tag) {
|
|
33
34
|
return `https://github.com/${repo}/releases/download/${tag}/${tag}.zip`;
|
|
34
35
|
}
|
|
36
|
+
/**
|
|
37
|
+
* Download URL for a Kizlo plugin's latest release, served by kizlo.io (it 302s to
|
|
38
|
+
* the current GitHub release asset). Always tracks the newest published version —
|
|
39
|
+
* use {@link githubRelease} instead to pin a specific tag.
|
|
40
|
+
*/
|
|
41
|
+
function kizloRelease(slug) {
|
|
42
|
+
return `https://kizlo.io/plugins/${slug}/download`;
|
|
43
|
+
}
|
|
35
44
|
/** Resolve a `PluginSource` to the `(name, source)` pair `ensurePlugin` needs. */
|
|
36
45
|
function resolvePluginSource(plugin) {
|
|
37
46
|
return typeof plugin === "string" ? [plugin, plugin] : [plugin.name, plugin.source];
|
|
@@ -76,6 +85,39 @@ async function ensurePlugin(name, source) {
|
|
|
76
85
|
]);
|
|
77
86
|
}
|
|
78
87
|
/**
|
|
88
|
+
* Activate a bind-mounted local plugin by its directory basename (the slug the
|
|
89
|
+
* mount lands at under `wp-content/plugins`). Idempotent: the files arrive via the
|
|
90
|
+
* compose bind, so there's nothing to install — just activate if it isn't already.
|
|
91
|
+
*/
|
|
92
|
+
async function activateLocalPlugin(pluginPath) {
|
|
93
|
+
const slug = basename(pluginPath);
|
|
94
|
+
if ((await compose([
|
|
95
|
+
"exec",
|
|
96
|
+
"-T",
|
|
97
|
+
"wp-cli",
|
|
98
|
+
"wp",
|
|
99
|
+
"plugin",
|
|
100
|
+
"is-active",
|
|
101
|
+
slug
|
|
102
|
+
])).code !== 0) await wpCli([
|
|
103
|
+
"plugin",
|
|
104
|
+
"activate",
|
|
105
|
+
slug
|
|
106
|
+
]);
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Ensure every plugin is active. Installable sources go first so a bind-mounted
|
|
110
|
+
* local plugin that depends on one (e.g. a WooCommerce extension) finds it already
|
|
111
|
+
* present; then each {@link LocalPlugin} is activated by basename. A local plugin
|
|
112
|
+
* whose slug matches an installable (e.g. mounting `kizlo` over the released
|
|
113
|
+
* `kizlo`) is seen as already installed, so `ensurePlugin` activates the live
|
|
114
|
+
* files instead of downloading over them.
|
|
115
|
+
*/
|
|
116
|
+
async function ensurePlugins(plugins) {
|
|
117
|
+
for (const plugin of plugins) if (!isLocalPlugin(plugin)) await ensurePlugin(...resolvePluginSource(plugin));
|
|
118
|
+
for (const plugin of plugins) if (isLocalPlugin(plugin)) await activateLocalPlugin(plugin.path);
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
79
121
|
* The directory holding `kizlo.config.*`, found by walking up from `cwd` (falling
|
|
80
122
|
* back to `cwd` when none is found). Anchoring the credentials artifact here —
|
|
81
123
|
* rather than each process's cwd — is what lets the CLI writer and the test reader
|
|
@@ -100,6 +142,22 @@ function getTestCredentials() {
|
|
|
100
142
|
cached = JSON.parse(readFileSync(credentialsPath(), "utf-8"));
|
|
101
143
|
return cached;
|
|
102
144
|
}
|
|
145
|
+
/**
|
|
146
|
+
* The host port the credentials artifact advertises, if it exists — the port a warm test
|
|
147
|
+
* stack is pinned to. Tests connect via this URL, so a reused stack must come back up on
|
|
148
|
+
* the same port; `undefined` means no stack has ever been seeded here (a cold boot).
|
|
149
|
+
*/
|
|
150
|
+
function recordedPort() {
|
|
151
|
+
const path$1 = credentialsPath();
|
|
152
|
+
if (!existsSync(path$1)) return void 0;
|
|
153
|
+
try {
|
|
154
|
+
const { url } = JSON.parse(readFileSync(path$1, "utf-8"));
|
|
155
|
+
const port = new URL(url).port;
|
|
156
|
+
return port ? Number(port) : void 0;
|
|
157
|
+
} catch {
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
103
161
|
|
|
104
162
|
//#endregion
|
|
105
|
-
export { credentialsPath, ensurePlugin, findConfigDir, getTestCredentials, githubRelease, isSeeded, resolvePluginSource };
|
|
163
|
+
export { activateLocalPlugin, credentialsPath, ensurePlugin, ensurePlugins, findConfigDir, getTestCredentials, githubRelease, isSeeded, kizloRelease, recordedPort, resolvePluginSource };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { execFile } from "node:child_process";
|
|
2
|
+
import { promisify } from "node:util";
|
|
3
|
+
|
|
4
|
+
//#region src/cli/wp/watchdog.ts
|
|
5
|
+
const exec = promisify(execFile);
|
|
6
|
+
/**
|
|
7
|
+
* Standalone watchdog process spawned (detached, in its own session) by a foreground
|
|
8
|
+
* `kizlo dev`. It polls the parent PID and, the moment the parent is gone — for *any*
|
|
9
|
+
* reason the parent itself couldn't handle: terminal/tab closed, SIGHUP, SIGKILL, a
|
|
10
|
+
* crash — stops that project's containers. This is the guarantee the in-process signal
|
|
11
|
+
* handlers can't give, because a dying process can't be trusted to finish async work.
|
|
12
|
+
*
|
|
13
|
+
* Invoked as: `node watchdog.js <parentPid> <composeProject>`.
|
|
14
|
+
*/
|
|
15
|
+
const parentPid = Number(process.argv[2]);
|
|
16
|
+
const project = process.argv[3];
|
|
17
|
+
function parentAlive() {
|
|
18
|
+
try {
|
|
19
|
+
process.kill(parentPid, 0);
|
|
20
|
+
return true;
|
|
21
|
+
} catch {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
async function stopStack() {
|
|
26
|
+
try {
|
|
27
|
+
const { stdout } = await exec("docker", [
|
|
28
|
+
"ps",
|
|
29
|
+
"-q",
|
|
30
|
+
"--filter",
|
|
31
|
+
`label=com.docker.compose.project=${project}`
|
|
32
|
+
]);
|
|
33
|
+
const ids = stdout.split("\n").filter(Boolean);
|
|
34
|
+
if (ids.length) await exec("docker", ["stop", ...ids]);
|
|
35
|
+
} catch {}
|
|
36
|
+
}
|
|
37
|
+
if (!parentPid || !project) process.exit(1);
|
|
38
|
+
const timer = setInterval(() => {
|
|
39
|
+
if (parentAlive()) return;
|
|
40
|
+
clearInterval(timer);
|
|
41
|
+
stopStack().then(() => process.exit(0));
|
|
42
|
+
}, 1e3);
|
|
43
|
+
|
|
44
|
+
//#endregion
|
|
45
|
+
export { };
|
package/dist/client.d.ts
CHANGED
|
@@ -15,7 +15,7 @@ declare class KizloClient<TRouter extends AnyProcedureRouter> {
|
|
|
15
15
|
}
|
|
16
16
|
/**
|
|
17
17
|
* Creates a browser client for a generated contract. Defaults the URL to the
|
|
18
|
-
* current origin; framework packages wrap this to resolve it from their env.
|
|
18
|
+
* current origin (`window.location.origin`); framework packages wrap this to resolve it from their env.
|
|
19
19
|
*/
|
|
20
20
|
declare function createKizloClient<T extends AnyProcedureRouter>(contract: T, options?: {
|
|
21
21
|
url?: string;
|
package/dist/client.js
CHANGED
|
@@ -37,12 +37,12 @@ var KizloClient = class {
|
|
|
37
37
|
})));
|
|
38
38
|
}
|
|
39
39
|
getUrl() {
|
|
40
|
-
return this.config.url ?? window.location.
|
|
40
|
+
return this.config.url ?? window.location.origin;
|
|
41
41
|
}
|
|
42
42
|
};
|
|
43
43
|
/**
|
|
44
44
|
* Creates a browser client for a generated contract. Defaults the URL to the
|
|
45
|
-
* current origin; framework packages wrap this to resolve it from their env.
|
|
45
|
+
* current origin (`window.location.origin`); framework packages wrap this to resolve it from their env.
|
|
46
46
|
*/
|
|
47
47
|
function createKizloClient(contract, options) {
|
|
48
48
|
return new KizloClient({
|
package/dist/config.d.ts
CHANGED
|
@@ -2,9 +2,48 @@ import { Fixture } from "./cli/wp/types.js";
|
|
|
2
2
|
import "./test.js";
|
|
3
3
|
|
|
4
4
|
//#region src/config.d.ts
|
|
5
|
-
interface
|
|
5
|
+
interface KizloDevConfig {
|
|
6
|
+
/**
|
|
7
|
+
* Folder where your local WordPress install lives, relative to the config dir.
|
|
8
|
+
* The entire install (core, themes, uploads, plugins) is bind-mounted here, so
|
|
9
|
+
* you browse and edit every file from your file manager and your changes are
|
|
10
|
+
* live. This is your persistent dev site — pick a real, visible folder (e.g.
|
|
11
|
+
* `"wordpress"`), not a hidden one, and don't delete it. `reset` wipes it.
|
|
12
|
+
*/
|
|
13
|
+
path: string;
|
|
6
14
|
/** Published WP port (default 8080). */
|
|
7
15
|
port?: number;
|
|
16
|
+
/**
|
|
17
|
+
* Adopt an existing WordPress site instead of provisioning a blank one. Points at a
|
|
18
|
+
* `.tar.gz` archive (path relative to the config dir) whose root holds a `wordpress/`
|
|
19
|
+
* directory (the install) and a single `.sql` dump (the database). Applied when the
|
|
20
|
+
* stack is fresh — the first `kizlo dev`, or after a `kizlo dev reset` — and ignored
|
|
21
|
+
* once the stack is provisioned. Keep the archive outside `path` (reset wipes that).
|
|
22
|
+
*/
|
|
23
|
+
byo?: string;
|
|
24
|
+
/**
|
|
25
|
+
* Host port the dev MySQL is published on (default 3307), bound to `127.0.0.1` so
|
|
26
|
+
* you can point a SQL client (TablePlus, DBeaver, `mysql`) at the database to
|
|
27
|
+
* inspect or edit tables directly. Connect with db `wordpress`, user `wordpress`,
|
|
28
|
+
* password `wppass`. Pick a port that's free — change it if you run multiple stacks
|
|
29
|
+
* or already have MySQL on the default.
|
|
30
|
+
*/
|
|
31
|
+
dbPort?: number;
|
|
32
|
+
/**
|
|
33
|
+
* Code-defined seed data for a **fresh** dev stack — the same {@link Fixture}s the
|
|
34
|
+
* test stack uses, so you can populate your dev site from versioned code instead of a
|
|
35
|
+
* blank install. Each fixture also declares the plugins it needs — wp.org slugs / zip
|
|
36
|
+
* sources to install, or `{ path }` local directories bind-mounted live so your edits
|
|
37
|
+
* show up without a reinstall — which the dev stack ensures every run. Each fixture's
|
|
38
|
+
* `seed` runs once over REST (and may drop to wp-cli) on the first `kizlo dev` and
|
|
39
|
+
* after `kizlo dev reset`; existing stacks are left alone. Mutually exclusive with
|
|
40
|
+
* {@link byo} (which brings its own data).
|
|
41
|
+
*/
|
|
42
|
+
fixtures?: Fixture[];
|
|
43
|
+
}
|
|
44
|
+
interface KizloTestConfig {
|
|
45
|
+
/** Published WP port (default 8889). */
|
|
46
|
+
port?: number;
|
|
8
47
|
/** Extension fixtures to install + seed. */
|
|
9
48
|
fixtures?: Fixture[];
|
|
10
49
|
/**
|
|
@@ -31,9 +70,16 @@ interface KizloGlobalConfig {
|
|
|
31
70
|
* tsconfig at init; omit (or empty) to use relative imports.
|
|
32
71
|
*/
|
|
33
72
|
alias?: string;
|
|
34
|
-
/**
|
|
73
|
+
/**
|
|
74
|
+
* Base name for the local Docker stacks (`<name>-dev`, `<name>-test`). Defaults
|
|
75
|
+
* to the sanitized `package.json` name, falling back to the config dir basename.
|
|
76
|
+
*/
|
|
77
|
+
name?: string;
|
|
78
|
+
/** Local WordPress dev stack used by `kizlo dev`. */
|
|
79
|
+
dev?: KizloDevConfig;
|
|
80
|
+
/** WordPress test environment used by `kizlo test`. */
|
|
35
81
|
test?: KizloTestConfig;
|
|
36
82
|
}
|
|
37
83
|
declare function defineConfig(config: KizloGlobalConfig): KizloGlobalConfig;
|
|
38
84
|
//#endregion
|
|
39
|
-
export { KizloGlobalConfig, KizloTestConfig, defineConfig };
|
|
85
|
+
export { KizloDevConfig, KizloGlobalConfig, KizloTestConfig, defineConfig };
|
package/dist/context.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { WordPressCredentials } from "./wordpress/types.js";
|
|
2
2
|
import "./wordpress/index.js";
|
|
3
3
|
import { AuthUser } from "./adapters/auth.js";
|
|
4
|
+
import { PreviewTokenPayload } from "./shared/schema.js";
|
|
4
5
|
import { ConnInfo } from "./adapters/geo.js";
|
|
5
6
|
import { Logger } from "./adapters/logger.js";
|
|
6
|
-
import { PreviewTokenPayload } from "./shared/schema.js";
|
|
7
7
|
import { CookiesStorage } from "./cookie.js";
|
|
8
8
|
import { ServiceAdapters } from "./kizlo.js";
|
|
9
9
|
import { Service } from "./service.js";
|
|
@@ -19,16 +19,27 @@ type ConnInfoFn = () => Promise<ConnInfo | null>;
|
|
|
19
19
|
type VerifyCaptchaFn = (token: string) => Promise<boolean>;
|
|
20
20
|
type VerifyPreviewTokenFn = (token: string) => Promise<PreviewTokenPayload | null>;
|
|
21
21
|
interface ServerContext {
|
|
22
|
+
/** The incoming HTTP `Request`, or `null` for server-side (non-HTTP) invocations. */
|
|
22
23
|
request: Request | null;
|
|
24
|
+
/** Response headers to be sent (e.g. `Set-Cookie`), or `null` server-side. */
|
|
23
25
|
headers: Headers | null;
|
|
26
|
+
/** The configured logger adapter. */
|
|
24
27
|
logger: Logger;
|
|
28
|
+
/** Typed service clients — the WordPress client at `service.wordpress`, with more services added over time. */
|
|
25
29
|
service: Service;
|
|
30
|
+
/** The resolved context config: site secret, adapters, and WordPress credentials. */
|
|
26
31
|
config: ContextConfig;
|
|
32
|
+
/** Resolve the caller's connection info (IP, geo) via the geo adapter, or `null`. */
|
|
27
33
|
getConnInfo: ConnInfoFn;
|
|
34
|
+
/** Resolve the authenticated user via the auth adapter, or `null`. */
|
|
28
35
|
getAuthUser: AuthUserFn;
|
|
36
|
+
/** Read and write cookies through the cookies adapter. */
|
|
29
37
|
cookies: CookiesStorage;
|
|
38
|
+
/** Verify a CAPTCHA token via the captcha adapter. */
|
|
30
39
|
verifyCaptcha: VerifyCaptchaFn;
|
|
40
|
+
/** Verify a preview token and return its payload, or `null`. */
|
|
31
41
|
verifyPreviewToken: VerifyPreviewTokenFn;
|
|
42
|
+
/** How the procedure was called: `"client"` (over HTTP) or `"server"` (direct server invocation). */
|
|
32
43
|
invokedBy: "client" | "server";
|
|
33
44
|
}
|
|
34
45
|
declare class Context {
|
package/dist/context.js
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -14,20 +14,25 @@ import { CommentService } from "./wordpress/comment/service.js";
|
|
|
14
14
|
import { CART_HASH_HEADER_KEY, SAFE_REQUEST_TIMEOUT, UNEXPECTED_BODY_SNIPPET_LENGTH, WC_CORE_BASE, WC_STORE_BASE, WP_AUTH_HEADER_KEY, WP_AUTH_TYPE, WP_CORE_BASE, WP_KIZLO_BASE } from "./wordpress/constants.js";
|
|
15
15
|
import { isWordPressResourceError } from "./wordpress/utils.js";
|
|
16
16
|
import "./wordpress/index.js";
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
20
|
-
import { geoVercelNext } from "./adapters/geo.vercel.js";
|
|
21
|
-
import { ConsoleLogAdapterOptions, Environment, LogLevel, LogPayload, Logger, LoggerAdapter, consoleLog, noopAdapter } from "./adapters/logger.js";
|
|
17
|
+
import { DevPluginSource, Fixture, FixtureCleanupFn, FixtureSeedFn, JsonValue, LocalPlugin, PluginSource, SeedContext, TestAdminUser, TestCredentials, TestUser, defineFixture, isLocalPlugin } from "./cli/wp/types.js";
|
|
18
|
+
import { AuthAdapter, AuthGetUser, AuthUser, authMock, createAuthAdapter } from "./adapters/auth.js";
|
|
19
|
+
import { CaptchaAdapter, altcha, arkose, createCaptchaAdapter, friendlyCaptcha, hcaptcha, recaptcha, turnstile } from "./adapters/captcha.js";
|
|
22
20
|
import { CurrencyFormat, IdentifierInput, LIST_ORDER, ListMetadata, ListOrder, Media, PreviewTokenData, PreviewTokenPayload } from "./shared/schema.js";
|
|
23
|
-
import { AnyContext, AnyNestedClient, CookiesAdapter, HTTPMethod, List, MaybeOptionalOptions, RedirectInput, RedirectStatus } from "./shared/types.js";
|
|
24
|
-
import {
|
|
21
|
+
import { AnyContext, AnyNestedClient, CookiesAdapter, CookiesDeleteAll, CookiesGetAll, CookiesSetAll, HTTPMethod, List, MaybeOptionalOptions, RedirectInput, RedirectStatus } from "./shared/types.js";
|
|
22
|
+
import { createCookiesAdapter } from "./adapters/cookies.js";
|
|
23
|
+
import { ConnInfo, GeoAdapter, GeoGetConnInfo, createGeoAdapter, geoMock } from "./adapters/geo.js";
|
|
24
|
+
import { geoVercelNext } from "./adapters/geo.vercel.js";
|
|
25
|
+
import { ConsoleLogAdapterOptions, Environment, LogLevel, LogPayload, Logger, LoggerAdapter, consoleLog, createLoggerAdapter, noopAdapter } from "./adapters/logger.js";
|
|
26
|
+
import { AnyEventSchema, AnyEvents, EventHandler, EventHandlerFn, InferEventUnion, WebhookOptions, createEventHandler, createWebhookRouter } from "./webhook/index.js";
|
|
25
27
|
import { AnyExtension, Extension, ExtensionInitFn, ExtensionInitOptions, ExtensionInitResult, ExtractExtensionRouter, InferExtensionRouter, createExtension } from "./shared/extension.js";
|
|
26
|
-
import { COMMON_ERRORS, CommonErrorCode, CommonErrorLiteral, CommonErrorMap,
|
|
27
|
-
import { AnyKizloConfig, CreateKizloOptions, Kizlo, KizloConfig, RootRouter, S2SClient, ServiceAdapters, createKizlo, resolveKizloConfig } from "./kizlo.js";
|
|
28
|
+
import { COMMON_ERRORS, CommonErrorCode, CommonErrorLiteral, CommonErrorMap, DefinedErrorMapLike, ErrorDefinition, KizloError, KizloErrorOptions, ThrowableErrorFn, ThrowableErrorMap, WithCommonErrorMap, createThrowableErrorMap, defineErrorMap, isKizloError, toKizloError } from "./shared/error.js";
|
|
29
|
+
import { AnyKizloConfig, CreateKizloOptions, Kizlo, KizloConfig, KizloTarget, RootRouter, S2SClient, ServiceAdapters, createKizlo, resolveKizloConfig } from "./kizlo.js";
|
|
30
|
+
import { KizloAuthorsSettings, KizloAuthorsSettingsInput, KizloCrawlingSettings, KizloCrawlingSettingsInput, KizloIdentitySettings, KizloIdentitySettingsInput, KizloMedia, KizloOrganizationFounder, KizloOrganizationSettings, KizloOrganizationSettingsInput, KizloPersonSettings, KizloPersonSettingsInput, KizloPostStatus, KizloPostTypeSettings, KizloPostTypeSettingsInput, KizloSettings, KizloSiteSettings, KizloSiteSettingsInput, KizloSocialProfile, KizloTaxonomySettings, KizloTaxonomySettingsInput, KizloWebhookSettings, KizloWebhookSettingsInput } from "./settings/service.interface.js";
|
|
31
|
+
import { KizloSettingsService } from "./settings/service.js";
|
|
28
32
|
import { Service, ServiceConfig } from "./service.js";
|
|
29
33
|
import { AuthUserFn, ConnInfoFn, Context, ContextConfig, ServerContext, VerifyCaptchaFn, VerifyPreviewTokenFn } from "./context.js";
|
|
30
|
-
import { AnyMiddleware,
|
|
34
|
+
import { AnyMiddleware, ExtractMiddlewareContextOutput, InferUses, Middleware, MiddlewareHandler, MiddlewareNextFn, MiddlewareOptions, MiddlewareResult, createMiddleware } from "./shared/middleware.js";
|
|
35
|
+
import { AnyProcedure, AnyProcedureRouter, BaseHandlerOptions, ExtractParams, ExtractProcedureByScope, InvocationScope, OpenapiPart, Procedure, ProcedureContext, ProcedureErrors, ProcedureHandler, ProcedureOptions, ResolveParamsPart, ResolvedSchemaInput, ResolvedSchemaOutput, RouterDepthTuple, SchemaIO, buildProcedure, combineDetailed, createProcedure, handleUnexpectedError, schemaType } from "./shared/procedure.js";
|
|
31
36
|
import { KizloClient, KizloClientConfig, createKizloClient } from "./client.js";
|
|
32
37
|
import { CONTENT_TYPES, ContentType, ListSitemapUrlInput, ListSitemapUrlInputBase, Robots, RobotsRule, Seo, SeoHead, SeoSchema, Sitemap, SitemapList, SitemapUrl, SitemapUrlImage, SitemapUrlList } from "./seo/schema.js";
|
|
33
38
|
import { WPK_ListSitemapUrlInput, WPK_RobotRule, WPK_Robots, WPK_Seo, WPK_Sitemap, WPK_SitemapContentType, WPK_SitemapUrl, WPK_SitemapUrlImage } from "./seo/types.js";
|
|
@@ -36,4 +41,4 @@ import { compare, hash, hmac } from "./shared/crypto.js";
|
|
|
36
41
|
import { Identifier, parseIdentifier } from "./shared/identifier.js";
|
|
37
42
|
import { createOrpcRouter } from "./shared/router.js";
|
|
38
43
|
import { deserializeCurrencyFormat, deserializeListMetadata, emptyList, serializeCurrencyFormat } from "./shared/serialize.js";
|
|
39
|
-
export { AnyContext, AnyExtension, AnyKizloConfig, AnyMiddleware, AnyNestedClient, AnyProcedure, AnyProcedureRouter,
|
|
44
|
+
export { AnyContext, AnyEventSchema, AnyEvents, AnyExtension, AnyKizloConfig, AnyMiddleware, AnyNestedClient, AnyProcedure, AnyProcedureRouter, AuthAdapter, AuthGetUser, AuthUser, AuthUserFn, BaseHandlerOptions, CART_HASH_HEADER_KEY, COMMON_ERRORS, CONTENT_TYPES, CaptchaAdapter, CommentService, CommonErrorCode, CommonErrorLiteral, CommonErrorMap, ConnInfo, ConnInfoFn, ConsoleLogAdapterOptions, ContentType, Context, ContextConfig, Contract, ContractProcedure, CookiesAdapter, CookiesDeleteAll, CookiesGetAll, CookiesSetAll, CreateKizloOptions, CurrencyFormat, DefinedErrorMapLike, DevPluginSource, Environment, ErrorDefinition, EventHandler, EventHandlerFn, Extension, ExtensionInitFn, ExtensionInitOptions, ExtensionInitResult, ExtractExtensionRouter, ExtractMiddlewareContextOutput, ExtractParams, ExtractProcedureByScope, Fixture, FixtureCleanupFn, FixtureSeedFn, GeoAdapter, GeoGetConnInfo, HTTPMethod, Identifier, IdentifierInput, InferEventUnion, InferExtensionRouter, InferUses, InvocationScope, JsonValue, Kizlo, KizloAuthorsSettings, KizloAuthorsSettingsInput, KizloClient, KizloClientConfig, KizloConfig, KizloCrawlingSettings, KizloCrawlingSettingsInput, KizloError, KizloErrorOptions, KizloIdentitySettings, KizloIdentitySettingsInput, KizloMedia, KizloOrganizationFounder, KizloOrganizationSettings, KizloOrganizationSettingsInput, KizloPersonSettings, KizloPersonSettingsInput, KizloPostStatus, KizloPostTypeSettings, KizloPostTypeSettingsInput, KizloSettings, KizloSettingsService, KizloSiteSettings, KizloSiteSettingsInput, KizloSocialProfile, KizloTarget, KizloTaxonomySettings, KizloTaxonomySettingsInput, KizloWebhookSettings, KizloWebhookSettingsInput, LIST_ORDER, List, ListMetadata, ListOrder, ListSitemapUrlInput, ListSitemapUrlInputBase, LocalPlugin, LogLevel, LogPayload, Logger, LoggerAdapter, MaybeOptionalOptions, Media, MenuItemService, MenuService, Middleware, MiddlewareHandler, MiddlewareNextFn, MiddlewareOptions, MiddlewareResult, OpenapiPart, PluginSource, PostService, PreviewTokenData, PreviewTokenPayload, Procedure, ProcedureContext, ProcedureErrors, ProcedureHandler, ProcedureOptions, RedirectInput, RedirectStatus, ResolveParamsPart, ResolvedSchemaInput, ResolvedSchemaOutput, Robots, RobotsRule, RootRouter, RouterDepthTuple, S2SClient, SAFE_REQUEST_TIMEOUT, SchemaIO, SeedContext, Seo, SeoHead, SeoSchema, ServerContext, Service, ServiceAdapters, ServiceConfig, Sitemap, SitemapList, SitemapUrl, SitemapUrlImage, SitemapUrlList, TestAdminUser, TestCredentials, TestUser, ThrowableErrorFn, ThrowableErrorMap, UNEXPECTED_BODY_SNIPPET_LENGTH, UserService, VerifyCaptchaFn, VerifyPreviewTokenFn, WC_CORE_BASE, WC_STORE_BASE, WPK_ListSitemapUrlInput, WPK_RobotRule, WPK_Robots, WPK_Seo, WPK_Sitemap, WPK_SitemapContentType, WPK_SitemapUrl, WPK_SitemapUrlImage, WP_AUTH_HEADER_KEY, WP_AUTH_TYPE, WP_CORE_BASE, WP_Comment, WP_CommentAvatarUrls, WP_CommentContent, WP_CommentContentInput, WP_CommentCreateErrorCode, WP_CommentCreateInput, WP_CommentDeleteErrorCode, WP_CommentDeleteInput, WP_CommentDeleteResponse, WP_CommentLinks, WP_CommentListErrorCode, WP_CommentListInput, WP_CommentOrderBy, WP_CommentRetrieveErrorCode, WP_CommentRetrieveInput, WP_CommentStatus, WP_CommentStatusFilter, WP_CommentStatusInput, WP_CommentType, WP_CommentUpdateErrorCode, WP_CommentUpdateInput, WP_CommonErrorCode, WP_Context, WP_CurrencyFormat, WP_Error, WP_ErrorData, WP_KIZLO_BASE, WP_Link, WP_List, WP_ListMetadata, WP_ListOrder, WP_Menu, WP_MenuCreateErrorCode, WP_MenuCreateInput, WP_MenuDeleteErrorCode, WP_MenuDeleteInput, WP_MenuDeleteResponse, WP_MenuItem, WP_MenuItemCreateErrorCode, WP_MenuItemCreateInput, WP_MenuItemDeleteErrorCode, WP_MenuItemDeleteInput, WP_MenuItemDeleteResponse, WP_MenuItemLinks, WP_MenuItemListErrorCode, WP_MenuItemListInput, WP_MenuItemOrderBy, WP_MenuItemRetrieveErrorCode, WP_MenuItemRetrieveInput, WP_MenuItemStatus, WP_MenuItemStatusFilter, WP_MenuItemTarget, WP_MenuItemTaxRelation, WP_MenuItemTitle, WP_MenuItemTitleInput, WP_MenuItemType, WP_MenuItemUpdateErrorCode, WP_MenuItemUpdateInput, WP_MenuLinks, WP_MenuListErrorCode, WP_MenuListInput, WP_MenuOrderBy, WP_MenuRetrieveErrorCode, WP_MenuRetrieveInput, WP_MenuUpdateErrorCode, WP_MenuUpdateInput, WP_Post, WP_PostCommentStatus, WP_PostContent, WP_PostContentInput, WP_PostCreateErrorCode, WP_PostCreateInput, WP_PostDeleteErrorCode, WP_PostDeleteInput, WP_PostDeleteResponse, WP_PostExcerpt, WP_PostExcerptInput, WP_PostFormat, WP_PostGuid, WP_PostLinks, WP_PostListErrorCode, WP_PostListInput, WP_PostOrderBy, WP_PostRetrieveErrorCode, WP_PostRetrieveInput, WP_PostStatus, WP_PostStatusFilter, WP_PostTaxRelation, WP_PostTitle, WP_PostTitleInput, WP_PostUpdateErrorCode, WP_PostUpdateInput, WP_RequestInput, WP_Result, WP_User, WP_UserAvatarUrls, WP_UserCapabilities, WP_UserCreateErrorCode, WP_UserCreateInput, WP_UserDeleteErrorCode, WP_UserDeleteInput, WP_UserDeleteMeErrorCode, WP_UserDeleteMeInput, WP_UserDeleteMeResponse, WP_UserDeleteResponse, WP_UserLinks, WP_UserListErrorCode, WP_UserListInput, WP_UserOrderBy, WP_UserRetrieveErrorCode, WP_UserRetrieveInput, WP_UserRetrieveMeErrorCode, WP_UserRetrieveMeInput, WP_UserUpdateErrorCode, WP_UserUpdateInput, WP_UserUpdateMeErrorCode, WP_UserUpdateMeInput, WP_UserWho, WebhookOptions, WithCommonErrorMap, WordPressCredentials, WordPressService, altcha, arkose, authMock, buildProcedure, combineDetailed, compare, consoleLog, createAuthAdapter, createCaptchaAdapter, createCookiesAdapter, createEventHandler, createExtension, createGeoAdapter, createKizlo, createKizloClient, createLoggerAdapter, createMiddleware, createOrpcRouter, createProcedure, createThrowableErrorMap, createWebhookRouter, defineErrorMap, defineFixture, deserializeCurrencyFormat, deserializeListMetadata, emptyList, friendlyCaptcha, generateContract, geoMock, geoVercelNext, handleUnexpectedError, hash, hcaptcha, hmac, isContractProcedure, isKizloError, isLocalPlugin, isWordPressResourceError, noopAdapter, parseIdentifier, recaptcha, resolveKizloConfig, restoreContract, schemaType, serializeCurrencyFormat, toKizloError, turnstile };
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import { authMock } from "./adapters/auth.js";
|
|
2
|
-
import { altcha, arkose, friendlyCaptcha, hcaptcha, recaptcha, turnstile } from "./adapters/captcha.js";
|
|
3
|
-
import {
|
|
1
|
+
import { authMock, createAuthAdapter } from "./adapters/auth.js";
|
|
2
|
+
import { altcha, arkose, createCaptchaAdapter, friendlyCaptcha, hcaptcha, recaptcha, turnstile } from "./adapters/captcha.js";
|
|
3
|
+
import { createCookiesAdapter } from "./adapters/cookies.js";
|
|
4
|
+
import { createGeoAdapter, geoMock } from "./adapters/geo.js";
|
|
4
5
|
import { geoVercelNext } from "./adapters/geo.vercel.js";
|
|
5
|
-
import { consoleLog, noopAdapter } from "./adapters/logger.js";
|
|
6
|
+
import { consoleLog, createLoggerAdapter, noopAdapter } from "./adapters/logger.js";
|
|
7
|
+
import { defineFixture, isLocalPlugin } from "./cli/wp/types.js";
|
|
6
8
|
import { COMMON_ERRORS, KizloError, createThrowableErrorMap, defineErrorMap, isKizloError, toKizloError } from "./shared/error.js";
|
|
7
|
-
import { buildProcedure, combineDetailed,
|
|
9
|
+
import { buildProcedure, combineDetailed, createProcedure, handleUnexpectedError, schemaType } from "./shared/procedure.js";
|
|
8
10
|
import { createOrpcRouter } from "./shared/router.js";
|
|
9
11
|
import { generateContract, isContractProcedure, restoreContract } from "./shared/contract.js";
|
|
10
12
|
import { CurrencyFormat, IdentifierInput, LIST_ORDER, ListMetadata, ListOrder, Media, PreviewTokenData, PreviewTokenPayload } from "./shared/schema.js";
|
|
@@ -18,6 +20,7 @@ import { PostService } from "./wordpress/post/service.js";
|
|
|
18
20
|
import { UserService } from "./wordpress/user/service.js";
|
|
19
21
|
import { isWordPressResourceError } from "./wordpress/utils.js";
|
|
20
22
|
import { WordPressService } from "./wordpress/service.js";
|
|
23
|
+
import { KizloSettingsService } from "./settings/service.js";
|
|
21
24
|
import { Service } from "./service.js";
|
|
22
25
|
import { compare, hash, hmac } from "./shared/crypto.js";
|
|
23
26
|
import { Context } from "./context.js";
|
|
@@ -27,5 +30,6 @@ import { CONTENT_TYPES, ContentType, ListSitemapUrlInput, ListSitemapUrlInputBas
|
|
|
27
30
|
import { createEventHandler, createWebhookRouter } from "./webhook/index.js";
|
|
28
31
|
import { Kizlo, createKizlo, resolveKizloConfig } from "./kizlo.js";
|
|
29
32
|
import { createExtension } from "./shared/extension.js";
|
|
33
|
+
import { createMiddleware } from "./shared/middleware.js";
|
|
30
34
|
|
|
31
|
-
export { CART_HASH_HEADER_KEY, COMMON_ERRORS, CONTENT_TYPES, CommentService, ContentType, Context, CurrencyFormat, IdentifierInput, Kizlo, KizloClient, KizloError, LIST_ORDER, ListMetadata, ListOrder, ListSitemapUrlInput, ListSitemapUrlInputBase, Media, MenuItemService, MenuService, PostService, PreviewTokenData, PreviewTokenPayload, Robots, RobotsRule, SAFE_REQUEST_TIMEOUT, Seo, SeoHead, SeoSchema, Service, Sitemap, SitemapList, SitemapUrl, SitemapUrlImage, SitemapUrlList, UNEXPECTED_BODY_SNIPPET_LENGTH, UserService, WC_CORE_BASE, WC_STORE_BASE, WP_AUTH_HEADER_KEY, WP_AUTH_TYPE, WP_CORE_BASE, WP_Error, WP_KIZLO_BASE, WordPressService, altcha, arkose, authMock, buildProcedure, combineDetailed, compare, consoleLog, createEventHandler, createExtension, createKizlo, createKizloClient, createMiddleware, createOrpcRouter, createProcedure, createThrowableErrorMap, createWebhookRouter, defineErrorMap, deserializeCurrencyFormat, deserializeListMetadata, emptyList, friendlyCaptcha, generateContract, geoMock, geoVercelNext, handleUnexpectedError, hash, hcaptcha, hmac, isContractProcedure, isKizloError, isWordPressResourceError, noopAdapter, parseIdentifier, recaptcha, resolveKizloConfig, restoreContract, schemaType, serializeCurrencyFormat, toKizloError, turnstile };
|
|
35
|
+
export { CART_HASH_HEADER_KEY, COMMON_ERRORS, CONTENT_TYPES, CommentService, ContentType, Context, CurrencyFormat, IdentifierInput, Kizlo, KizloClient, KizloError, KizloSettingsService, LIST_ORDER, ListMetadata, ListOrder, ListSitemapUrlInput, ListSitemapUrlInputBase, Media, MenuItemService, MenuService, PostService, PreviewTokenData, PreviewTokenPayload, Robots, RobotsRule, SAFE_REQUEST_TIMEOUT, Seo, SeoHead, SeoSchema, Service, Sitemap, SitemapList, SitemapUrl, SitemapUrlImage, SitemapUrlList, UNEXPECTED_BODY_SNIPPET_LENGTH, UserService, WC_CORE_BASE, WC_STORE_BASE, WP_AUTH_HEADER_KEY, WP_AUTH_TYPE, WP_CORE_BASE, WP_Error, WP_KIZLO_BASE, WordPressService, altcha, arkose, authMock, buildProcedure, combineDetailed, compare, consoleLog, createAuthAdapter, createCaptchaAdapter, createCookiesAdapter, createEventHandler, createExtension, createGeoAdapter, createKizlo, createKizloClient, createLoggerAdapter, createMiddleware, createOrpcRouter, createProcedure, createThrowableErrorMap, createWebhookRouter, defineErrorMap, defineFixture, deserializeCurrencyFormat, deserializeListMetadata, emptyList, friendlyCaptcha, generateContract, geoMock, geoVercelNext, handleUnexpectedError, hash, hcaptcha, hmac, isContractProcedure, isKizloError, isLocalPlugin, isWordPressResourceError, noopAdapter, parseIdentifier, recaptcha, resolveKizloConfig, restoreContract, schemaType, serializeCurrencyFormat, toKizloError, turnstile };
|
|
@@ -5,7 +5,7 @@ import { CreateKizloOptions, Kizlo } from "../../kizlo.js";
|
|
|
5
5
|
type KizloServerOptions<TExts extends readonly AnyExtension[] = []> = CreateKizloOptions<TExts>;
|
|
6
6
|
/**
|
|
7
7
|
* Creates a Kizlo server for Next.js — same as the base `createKizlo`, but reads
|
|
8
|
-
* the public base URL from `
|
|
8
|
+
* the public base URL from `NEXT_PUBLIC_KIZLO_BACKEND_URL`.
|
|
9
9
|
*/
|
|
10
10
|
declare function createKizlo<TExts extends readonly AnyExtension[] = []>(options?: CreateKizloOptions<TExts>): Kizlo<TExts>;
|
|
11
11
|
//#endregion
|
|
@@ -3,10 +3,10 @@ import { Kizlo, resolveKizloConfig } from "../../kizlo.js";
|
|
|
3
3
|
//#region src/integrations/nextjs/kizlo.server.ts
|
|
4
4
|
/**
|
|
5
5
|
* Creates a Kizlo server for Next.js — same as the base `createKizlo`, but reads
|
|
6
|
-
* the public base URL from `
|
|
6
|
+
* the public base URL from `NEXT_PUBLIC_KIZLO_BACKEND_URL`.
|
|
7
7
|
*/
|
|
8
8
|
function createKizlo(options) {
|
|
9
|
-
return new Kizlo(resolveKizloConfig(options, { baseUrlEnvKey: "
|
|
9
|
+
return new Kizlo(resolveKizloConfig(options, { baseUrlEnvKey: "NEXT_PUBLIC_KIZLO_BACKEND_URL" }));
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
//#endregion
|
|
@@ -2,8 +2,8 @@ import { KizloError } from "../../shared/error.js";
|
|
|
2
2
|
|
|
3
3
|
//#region src/integrations/nextjs/utils.ts
|
|
4
4
|
function getServerBaseUrl() {
|
|
5
|
-
const baseUrl = process.env.
|
|
6
|
-
if (!baseUrl) throw new KizloError("MISSING_ENV_VARIABLE", { message: "Please define
|
|
5
|
+
const baseUrl = process.env.NEXT_PUBLIC_KIZLO_BACKEND_URL;
|
|
6
|
+
if (!baseUrl) throw new KizloError("MISSING_ENV_VARIABLE", { message: "Please define NEXT_PUBLIC_KIZLO_BACKEND_URL in your .env file." });
|
|
7
7
|
return baseUrl;
|
|
8
8
|
}
|
|
9
9
|
|
package/dist/kizlo.d.ts
CHANGED
|
@@ -2,25 +2,30 @@ import { WordPressCredentials } from "./wordpress/types.js";
|
|
|
2
2
|
import "./wordpress/index.js";
|
|
3
3
|
import { AuthAdapter } from "./adapters/auth.js";
|
|
4
4
|
import { CaptchaAdapter } from "./adapters/captcha.js";
|
|
5
|
+
import { CookiesAdapter } from "./shared/types.js";
|
|
5
6
|
import { GeoAdapter } from "./adapters/geo.js";
|
|
6
7
|
import { Environment, LoggerAdapter } from "./adapters/logger.js";
|
|
7
|
-
import { CookiesAdapter } from "./shared/types.js";
|
|
8
8
|
import { RouterMap } from "./router.js";
|
|
9
9
|
import { AnyExtension, InferExtensionRouter } from "./shared/extension.js";
|
|
10
10
|
import { ResultClient } from "./shared/result.js";
|
|
11
11
|
import { Context } from "./context.js";
|
|
12
|
-
import { Pathname } from "@kizlo/shared";
|
|
13
12
|
|
|
14
13
|
//#region src/kizlo.d.ts
|
|
15
14
|
type AnyKizloConfig = KizloConfig<any>;
|
|
15
|
+
/**
|
|
16
|
+
* Which credential set to read from the environment. Independent of `environment`
|
|
17
|
+
* (which carries logging semantics off `NODE_ENV`): `"dev"` reads the `KIZLO_DEV_WORDPRESS_*`
|
|
18
|
+
* / `KIZLO_DEV_SITE_SECRET` keys the local stack manages, `"production"` reads `KIZLO_WORDPRESS_*` / `KIZLO_SITE_SECRET`.
|
|
19
|
+
*/
|
|
20
|
+
type KizloTarget = "dev" | "production";
|
|
16
21
|
interface KizloConfig<TExts extends readonly AnyExtension[]> {
|
|
17
22
|
baseUrl: string;
|
|
18
23
|
siteSecret: string;
|
|
19
24
|
extensions?: TExts;
|
|
20
25
|
environment: Environment;
|
|
26
|
+
target: KizloTarget;
|
|
21
27
|
adapters?: ServiceAdapters;
|
|
22
28
|
credentials: WordPressCredentials;
|
|
23
|
-
webhookPath?: Pathname;
|
|
24
29
|
}
|
|
25
30
|
interface ServiceAdapters {
|
|
26
31
|
geo?: GeoAdapter;
|
|
@@ -45,11 +50,27 @@ declare class Kizlo<TExts extends readonly AnyExtension[] = []> {
|
|
|
45
50
|
private registerExtensions;
|
|
46
51
|
}
|
|
47
52
|
interface CreateKizloOptions<TExts extends readonly AnyExtension[] = []> {
|
|
53
|
+
/** Public base URL of your Kizlo server, used to route requests. Falls back to the `KIZLO_BACKEND_URL` env var. */
|
|
48
54
|
baseUrl?: string;
|
|
55
|
+
/** Secret shared with the WordPress plugin to sign and verify webhooks. Falls back to the `KIZLO_SITE_SECRET` env var (target-selected). */
|
|
49
56
|
siteSecret?: string;
|
|
57
|
+
/** Extensions to register, built with `createExtension` — mounts their namespaces on the client and their routes and event handlers on the handler. */
|
|
50
58
|
extensions?: TExts;
|
|
59
|
+
/** Runtime environment. Falls back to `NODE_ENV`, then `"development"`. */
|
|
51
60
|
environment?: Environment;
|
|
61
|
+
/**
|
|
62
|
+
* Which credential set to use. Falls back to the `KIZLO_TARGET` env var, then `"production"`.
|
|
63
|
+
* Independent of `environment`: `"dev"` reads `KIZLO_DEV_WORDPRESS_*` / `KIZLO_DEV_SITE_SECRET` (the keys the
|
|
64
|
+
* local dev stack manages), `"production"` reads `KIZLO_WORDPRESS_*` / `KIZLO_SITE_SECRET`.
|
|
65
|
+
*/
|
|
66
|
+
target?: KizloTarget;
|
|
67
|
+
/** Service adapters: auth, captcha, geo, logger, and cookies. */
|
|
52
68
|
adapters?: ServiceAdapters;
|
|
69
|
+
/**
|
|
70
|
+
* WordPress connection. Each credential falls back to a target-selected env var: with the default
|
|
71
|
+
* `"production"` target to `KIZLO_WORDPRESS_URL` / `KIZLO_WORDPRESS_USERNAME` / `KIZLO_WORDPRESS_APPLICATION_PASSWORD`,
|
|
72
|
+
* and with the `"dev"` target to their `KIZLO_DEV_WORDPRESS_*` counterparts.
|
|
73
|
+
*/
|
|
53
74
|
wordpress?: {
|
|
54
75
|
credentials?: Partial<WordPressCredentials>;
|
|
55
76
|
};
|
|
@@ -64,10 +85,10 @@ declare function resolveKizloConfig<TExts extends readonly AnyExtension[]>(optio
|
|
|
64
85
|
adapters?: ServiceAdapters;
|
|
65
86
|
}): KizloConfig<TExts>;
|
|
66
87
|
/**
|
|
67
|
-
* Creates a Kizlo server from the environment (`
|
|
68
|
-
* `
|
|
88
|
+
* Creates a Kizlo server from the environment (`KIZLO_BACKEND_URL`, `KIZLO_SITE_SECRET`,
|
|
89
|
+
* `KIZLO_WORDPRESS_*`), with options taking precedence. Framework packages wrap this
|
|
69
90
|
* with their own URL convention and adapters.
|
|
70
91
|
*/
|
|
71
92
|
declare function createKizlo<TExts extends readonly AnyExtension[] = []>(options?: CreateKizloOptions<TExts>): Kizlo<TExts>;
|
|
72
93
|
//#endregion
|
|
73
|
-
export { AnyKizloConfig, CreateKizloOptions, Kizlo, KizloConfig, RootRouter, S2SClient, ServiceAdapters, createKizlo, resolveKizloConfig };
|
|
94
|
+
export { AnyKizloConfig, CreateKizloOptions, Kizlo, KizloConfig, KizloTarget, RootRouter, S2SClient, ServiceAdapters, createKizlo, resolveKizloConfig };
|
package/dist/kizlo.js
CHANGED
|
@@ -30,10 +30,7 @@ var Kizlo = class {
|
|
|
30
30
|
this.router = Object.assign(Object.assign({}, {
|
|
31
31
|
...extensions.router,
|
|
32
32
|
...ROUTER_MAP
|
|
33
|
-
}), { webhooks: createWebhookRouter({
|
|
34
|
-
path: this.config.webhookPath,
|
|
35
|
-
events: extensions.events
|
|
36
|
-
}) });
|
|
33
|
+
}), { webhooks: createWebhookRouter({ events: extensions.events }) });
|
|
37
34
|
const orpcRouter = createOrpcRouter(this.router);
|
|
38
35
|
this.client = createResultClient(createRouterClient(orpcRouter, { context: this.context }));
|
|
39
36
|
this.remoteHandler = new RPCHandler(orpcRouter, {
|
|
@@ -108,6 +105,19 @@ function requireEnv(name) {
|
|
|
108
105
|
if (!value) throw new KizloError("MISSING_ENV_VARIABLE", { message: `Please define ${name} in your .env file.` });
|
|
109
106
|
return value;
|
|
110
107
|
}
|
|
108
|
+
function resolveTarget(option) {
|
|
109
|
+
return option ?? (process.env.KIZLO_TARGET === "dev" ? "dev" : "production");
|
|
110
|
+
}
|
|
111
|
+
/** Env var names for a credential set: `KIZLO_DEV_WORDPRESS_URL` / `KIZLO_DEV_SITE_SECRET` for dev, `KIZLO_WORDPRESS_URL` / `KIZLO_SITE_SECRET` for production. */
|
|
112
|
+
function targetEnvKeys(target) {
|
|
113
|
+
const prefix = target === "dev" ? "KIZLO_DEV_" : "KIZLO_";
|
|
114
|
+
return {
|
|
115
|
+
siteSecret: `${prefix}SITE_SECRET`,
|
|
116
|
+
url: `${prefix}WORDPRESS_URL`,
|
|
117
|
+
username: `${prefix}WORDPRESS_USERNAME`,
|
|
118
|
+
password: `${prefix}WORDPRESS_APPLICATION_PASSWORD`
|
|
119
|
+
};
|
|
120
|
+
}
|
|
111
121
|
/**
|
|
112
122
|
* Resolves a full `KizloConfig` from options and the environment. Shared by the
|
|
113
123
|
* base `createKizlo` and each framework factory — the single place env values
|
|
@@ -115,29 +125,32 @@ function requireEnv(name) {
|
|
|
115
125
|
*/
|
|
116
126
|
function resolveKizloConfig(options, defaults) {
|
|
117
127
|
const credentials = options?.wordpress?.credentials;
|
|
128
|
+
const target = resolveTarget(options?.target);
|
|
129
|
+
const keys = targetEnvKeys(target);
|
|
118
130
|
return {
|
|
119
131
|
baseUrl: options?.baseUrl ?? requireEnv(defaults.baseUrlEnvKey),
|
|
120
|
-
siteSecret: options?.siteSecret ?? requireEnv(
|
|
132
|
+
siteSecret: options?.siteSecret ?? requireEnv(keys.siteSecret),
|
|
121
133
|
environment: options?.environment ?? process.env.NODE_ENV ?? "development",
|
|
134
|
+
target,
|
|
122
135
|
extensions: options?.extensions,
|
|
123
136
|
adapters: {
|
|
124
137
|
...defaults.adapters,
|
|
125
138
|
...options?.adapters
|
|
126
139
|
},
|
|
127
140
|
credentials: {
|
|
128
|
-
url: credentials?.url ?? requireEnv(
|
|
129
|
-
username: credentials?.username ?? requireEnv(
|
|
130
|
-
password: credentials?.password ?? requireEnv(
|
|
141
|
+
url: credentials?.url ?? requireEnv(keys.url),
|
|
142
|
+
username: credentials?.username ?? requireEnv(keys.username),
|
|
143
|
+
password: credentials?.password ?? requireEnv(keys.password)
|
|
131
144
|
}
|
|
132
145
|
};
|
|
133
146
|
}
|
|
134
147
|
/**
|
|
135
|
-
* Creates a Kizlo server from the environment (`
|
|
136
|
-
* `
|
|
148
|
+
* Creates a Kizlo server from the environment (`KIZLO_BACKEND_URL`, `KIZLO_SITE_SECRET`,
|
|
149
|
+
* `KIZLO_WORDPRESS_*`), with options taking precedence. Framework packages wrap this
|
|
137
150
|
* with their own URL convention and adapters.
|
|
138
151
|
*/
|
|
139
152
|
function createKizlo(options) {
|
|
140
|
-
return new Kizlo(resolveKizloConfig(options, { baseUrlEnvKey: "
|
|
153
|
+
return new Kizlo(resolveKizloConfig(options, { baseUrlEnvKey: "KIZLO_BACKEND_URL" }));
|
|
141
154
|
}
|
|
142
155
|
|
|
143
156
|
//#endregion
|
package/dist/menu/fixture.d.ts
CHANGED
package/dist/package.js
CHANGED
package/dist/post/fixture.d.ts
CHANGED
package/dist/service.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { WordPressCredentials } from "./wordpress/types.js";
|
|
|
2
2
|
import { WordPressService } from "./wordpress/service.js";
|
|
3
3
|
import "./wordpress/index.js";
|
|
4
4
|
import { EmailService } from "./email/service.js";
|
|
5
|
+
import { KizloSettingsService } from "./settings/service.js";
|
|
5
6
|
|
|
6
7
|
//#region src/service.d.ts
|
|
7
8
|
interface ServiceConfig {
|
|
@@ -9,6 +10,7 @@ interface ServiceConfig {
|
|
|
9
10
|
}
|
|
10
11
|
declare class Service {
|
|
11
12
|
readonly email: EmailService;
|
|
13
|
+
readonly settings: KizloSettingsService;
|
|
12
14
|
readonly wordpress: WordPressService;
|
|
13
15
|
private readonly config;
|
|
14
16
|
constructor(config: ServiceConfig);
|
package/dist/service.js
CHANGED
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
import { WordPressService } from "./wordpress/service.js";
|
|
2
2
|
import { EmailService } from "./email/service.js";
|
|
3
|
+
import { KizloSettingsService } from "./settings/service.js";
|
|
3
4
|
|
|
4
5
|
//#region src/service.ts
|
|
5
6
|
var Service = class {
|
|
6
7
|
email;
|
|
8
|
+
settings;
|
|
7
9
|
wordpress;
|
|
8
10
|
config;
|
|
9
11
|
constructor(config) {
|
|
10
12
|
this.config = config;
|
|
11
13
|
this.email = new EmailService(this);
|
|
14
|
+
this.settings = new KizloSettingsService(this);
|
|
12
15
|
this.wordpress = new WordPressService(this.config);
|
|
13
16
|
}
|
|
14
17
|
};
|