kizlo 0.26.0 → 0.26.2
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 +1 -1
- package/dist/client.js +10 -2
- package/dist/context.d.ts +2 -0
- package/dist/context.js +15 -4
- package/dist/integrations/nextjs/integration.js +2 -0
- package/dist/kizlo.js +1 -0
- package/dist/package.js +1 -1
- package/package.json +1 -1
package/dist/adapters/auth.d.ts
CHANGED
|
@@ -15,7 +15,7 @@ interface AuthUser {
|
|
|
15
15
|
}
|
|
16
16
|
type AuthGetSession = (request: Request | null) => Promisify<AuthUser | null>;
|
|
17
17
|
interface AuthAdapter {
|
|
18
|
-
/** Resolve the
|
|
18
|
+
/** Resolve the session from an HTTP request, a cookie-derived server request, or `null` when neither is available. */
|
|
19
19
|
getSession: AuthGetSession;
|
|
20
20
|
}
|
|
21
21
|
/** Author a custom auth adapter, typed against the {@link AuthAdapter} contract. */
|
package/dist/client.js
CHANGED
|
@@ -2,7 +2,7 @@ import { RPC_PROTOCOL_HEADER } from "./shared/constants.js";
|
|
|
2
2
|
import { isContractProcedure as isContractProcedure$1, restoreContract } from "./shared/contract.js";
|
|
3
3
|
import { createResultClient } from "./shared/result.js";
|
|
4
4
|
import { getObjectProperty } from "./shared/utils.js";
|
|
5
|
-
import { DynamicLink, createORPCClient } from "@orpc/client";
|
|
5
|
+
import { DynamicLink, createORPCClient, createORPCErrorFromJson, isORPCErrorJson } from "@orpc/client";
|
|
6
6
|
import { RPCLink } from "@orpc/client/fetch";
|
|
7
7
|
import { inferRPCMethodFromContractRouter } from "@orpc/contract";
|
|
8
8
|
import { OpenAPILink } from "@orpc/openapi-client/fetch";
|
|
@@ -17,7 +17,15 @@ var KizloClient = class {
|
|
|
17
17
|
const orpcContract = restoreContract(config.contract);
|
|
18
18
|
const openapiLink = new OpenAPILink(orpcContract, {
|
|
19
19
|
url,
|
|
20
|
-
fetch: config.fetch
|
|
20
|
+
fetch: config.fetch,
|
|
21
|
+
customErrorResponseBodyDecoder(body, response) {
|
|
22
|
+
if (body === null || typeof body !== "object" || Array.isArray(body)) return void 0;
|
|
23
|
+
const error = {
|
|
24
|
+
defined: false,
|
|
25
|
+
...body
|
|
26
|
+
};
|
|
27
|
+
return isORPCErrorJson(error) && error.status === response.status ? createORPCErrorFromJson(error) : void 0;
|
|
28
|
+
}
|
|
21
29
|
});
|
|
22
30
|
const remoteLink = new RPCLink({
|
|
23
31
|
url,
|
package/dist/context.d.ts
CHANGED
|
@@ -13,6 +13,8 @@ import { IntegrationPluginRequirement } from "@kizlo/shared";
|
|
|
13
13
|
|
|
14
14
|
//#region src/context.d.ts
|
|
15
15
|
interface ContextConfig {
|
|
16
|
+
/** Public Kizlo URL used to resolve cookie-based authentication for direct server calls. */
|
|
17
|
+
baseUrl?: string;
|
|
16
18
|
siteSecret: string;
|
|
17
19
|
adapters?: ServiceAdapters;
|
|
18
20
|
credentials: WordPressCredentials;
|
package/dist/context.js
CHANGED
|
@@ -109,8 +109,9 @@ var Context = class {
|
|
|
109
109
|
};
|
|
110
110
|
}
|
|
111
111
|
createServerContext() {
|
|
112
|
+
const cookies = new CookiesStorage(this.config.adapters?.cookies);
|
|
112
113
|
return {
|
|
113
|
-
cookies
|
|
114
|
+
cookies,
|
|
114
115
|
headers: null,
|
|
115
116
|
request: null,
|
|
116
117
|
config: this.config,
|
|
@@ -118,7 +119,7 @@ var Context = class {
|
|
|
118
119
|
wordpress: this.wordpress,
|
|
119
120
|
settings: this.settings,
|
|
120
121
|
email: this.email,
|
|
121
|
-
getSession: this.createGetSessionFn(null),
|
|
122
|
+
getSession: this.createGetSessionFn(null, cookies),
|
|
122
123
|
getConnInfo: this.createConnInfoFn(null),
|
|
123
124
|
verifyCaptcha: this.createVerifyCaptchaFn(null),
|
|
124
125
|
verifyPreviewToken: this.createVerifyPreviewTokenFn(),
|
|
@@ -176,9 +177,19 @@ var Context = class {
|
|
|
176
177
|
return await this.config.adapters?.geo?.getConnInfo?.(request) ?? null;
|
|
177
178
|
};
|
|
178
179
|
}
|
|
179
|
-
createGetSessionFn(request) {
|
|
180
|
+
createGetSessionFn(request, cookies) {
|
|
180
181
|
return async () => {
|
|
181
|
-
|
|
182
|
+
const auth = this.config.adapters?.auth;
|
|
183
|
+
if (!auth) return null;
|
|
184
|
+
let authRequest = request;
|
|
185
|
+
if (!authRequest && this.config.baseUrl && cookies) {
|
|
186
|
+
const cookieHeader = (await cookies.get()).map(({ name, value }) => stringifySetCookie({
|
|
187
|
+
name,
|
|
188
|
+
value
|
|
189
|
+
})).join("; ");
|
|
190
|
+
if (cookieHeader) authRequest = new Request(this.config.baseUrl, { headers: { cookie: cookieHeader } });
|
|
191
|
+
}
|
|
192
|
+
return await auth.getSession(authRequest) ?? null;
|
|
182
193
|
};
|
|
183
194
|
}
|
|
184
195
|
createVerifyPreviewTokenFn() {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { FRAMEWORK_INTEGRATION_ORDER } from "../../shared/constants.js";
|
|
2
2
|
import { createIntegration } from "../../shared/integration.js";
|
|
3
3
|
import { runtimeEnv } from "../runtime-env.js";
|
|
4
|
+
import { createNextCookiesInterface } from "./utils.js";
|
|
4
5
|
import { nextRevalidation } from "./revalidate.js";
|
|
5
6
|
|
|
6
7
|
//#region src/integrations/nextjs/integration.ts
|
|
@@ -11,6 +12,7 @@ function nextjs(options = {}) {
|
|
|
11
12
|
return createIntegration({
|
|
12
13
|
id: "nextjs",
|
|
13
14
|
order: FRAMEWORK_INTEGRATION_ORDER,
|
|
15
|
+
adapters: { cookies: createNextCookiesInterface() },
|
|
14
16
|
env: runtimeEnv(source, "NEXT_PUBLIC_KIZLO_BASE_URL"),
|
|
15
17
|
events: revalidation === false ? void 0 : nextRevalidation(typeof revalidation === "object" ? revalidation : void 0).events
|
|
16
18
|
});
|
package/dist/kizlo.js
CHANGED
|
@@ -27,6 +27,7 @@ var Kizlo = class {
|
|
|
27
27
|
this.config = config;
|
|
28
28
|
const integrations = this.registerIntegrations();
|
|
29
29
|
this.context = new Context({
|
|
30
|
+
baseUrl: config.baseUrl,
|
|
30
31
|
adapters: integrations.adapters,
|
|
31
32
|
siteSecret: config.siteSecret,
|
|
32
33
|
credentials: config.credentials,
|
package/dist/package.js
CHANGED