zitejs 0.10.0-start.3 → 0.10.0-start.4
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.
|
@@ -16,7 +16,8 @@ const accessOf = (chain, problems) => {
|
|
|
16
16
|
if (base.length > 1)
|
|
17
17
|
problems.push(`access-conflict: ${base.join(" + ")}`);
|
|
18
18
|
const kind = base.includes("webhook") ? "webhook" : base.includes("signedIn") ? "signedIn" : "anyone";
|
|
19
|
-
|
|
19
|
+
const paused = kinds.some((k) => k.kind === "webhook" && k.paused === true);
|
|
20
|
+
return paused ? { kind, roles, paused } : { kind, roles };
|
|
20
21
|
};
|
|
21
22
|
const jsonSchemaOf = (validator) => {
|
|
22
23
|
if (validator && typeof validator === "object" && "_zod" in validator) {
|
|
@@ -39,7 +39,10 @@ export declare const isSignInRequired: (error: unknown) => boolean;
|
|
|
39
39
|
export declare function loginHref(redirectTo?: string): string;
|
|
40
40
|
/** What a zitejs middleware means, for describe. Keyed by identity, so composing or re-exporting keeps it. */
|
|
41
41
|
export type ZiteMiddlewareKind = {
|
|
42
|
-
kind: "signedIn" | "anyone" | "
|
|
42
|
+
kind: "signedIn" | "anyone" | "factory";
|
|
43
|
+
} | {
|
|
44
|
+
kind: "webhook";
|
|
45
|
+
paused?: true;
|
|
43
46
|
} | {
|
|
44
47
|
kind: "role";
|
|
45
48
|
role: string;
|
|
@@ -54,8 +57,14 @@ export declare const signedIn: import("@tanstack/react-start").RequestMiddleware
|
|
|
54
57
|
export declare const anyone: import("@tanstack/react-start").RequestMiddlewareAfterServer<{}, undefined, {
|
|
55
58
|
user: User | null;
|
|
56
59
|
}>;
|
|
57
|
-
/**
|
|
58
|
-
|
|
60
|
+
/**
|
|
61
|
+
* Webhooks delivered by the platform, which already checked the URL token.
|
|
62
|
+
* `webhook.paused` keeps the URL but runs nothing: the platform answers the
|
|
63
|
+
* provider 200 and drops the delivery until it's switched back.
|
|
64
|
+
*/
|
|
65
|
+
export declare const webhook: import("@tanstack/react-start").RequestMiddlewareAfterServer<{}, undefined, undefined> & {
|
|
66
|
+
paused: import("@tanstack/react-start").RequestMiddlewareAfterServer<{}, undefined, undefined>;
|
|
67
|
+
};
|
|
59
68
|
/** Signed-in users with this role. */
|
|
60
69
|
export declare const role: (name: string) => import("@tanstack/react-start").RequestMiddlewareAfterServer<{}, readonly [import("@tanstack/react-start").RequestMiddlewareAfterServer<{}, undefined, {
|
|
61
70
|
user: User;
|
package/dist/esm/start/index.js
CHANGED
|
@@ -120,12 +120,17 @@ export const anyone = tag(createMiddleware().server(({ next, serverFnMeta }) =>
|
|
|
120
120
|
const { user } = host();
|
|
121
121
|
return runInScope({ kind: "anyone", user }, () => next({ context: { user } }));
|
|
122
122
|
})), { kind: "anyone" });
|
|
123
|
-
|
|
124
|
-
export const webhook = tag(createMiddleware().server(({ next }) => {
|
|
123
|
+
const webhookMiddleware = (paused) => tag(createMiddleware().server(({ next }) => {
|
|
125
124
|
if (host().invoke?.kind !== "webhook")
|
|
126
125
|
return new Response("Not found", { status: 404 });
|
|
127
126
|
return runInScope({ kind: "webhook", user: null }, () => next());
|
|
128
|
-
}), { kind: "webhook" });
|
|
127
|
+
}), paused ? { kind: "webhook", paused: true } : { kind: "webhook" });
|
|
128
|
+
/**
|
|
129
|
+
* Webhooks delivered by the platform, which already checked the URL token.
|
|
130
|
+
* `webhook.paused` keeps the URL but runs nothing: the platform answers the
|
|
131
|
+
* provider 200 and drops the delivery until it's switched back.
|
|
132
|
+
*/
|
|
133
|
+
export const webhook = Object.assign(webhookMiddleware(false), { paused: webhookMiddleware(true) });
|
|
129
134
|
/** Signed-in users with this role. */
|
|
130
135
|
export const role = (name) => tag(createMiddleware()
|
|
131
136
|
.middleware([signedIn])
|
package/dist/esm/start/server.js
CHANGED
|
@@ -150,7 +150,12 @@ export function createZiteFetch(options) {
|
|
|
150
150
|
const { platform } = host;
|
|
151
151
|
if (!host.runs.length || !platform)
|
|
152
152
|
return;
|
|
153
|
-
const
|
|
153
|
+
const batch = { runs: host.runs };
|
|
154
|
+
// On the request's session when it has one: one call, not another binding round trip.
|
|
155
|
+
const flushed = (async () => {
|
|
156
|
+
const session = host.session ? await host.session : undefined;
|
|
157
|
+
await (session?.runs ? session.runs(batch) : platform.runs(batch));
|
|
158
|
+
})().catch((error) => {
|
|
154
159
|
console.error("[zite] couldn't record runs", error);
|
|
155
160
|
});
|
|
156
161
|
ctx?.waitUntil(flushed);
|
|
@@ -42,6 +42,10 @@ export type PlatformCallResult = {
|
|
|
42
42
|
};
|
|
43
43
|
export type PlatformSession = {
|
|
44
44
|
call(call: PlatformCallInput): Promise<PlatformCallResult>;
|
|
45
|
+
/** As `PlatformBinding.runs`, on a session the request already holds. Hosts before 0.10.0-start.4 lack it. */
|
|
46
|
+
runs?(batch: {
|
|
47
|
+
runs: RunRecord[];
|
|
48
|
+
}): Promise<void>;
|
|
45
49
|
};
|
|
46
50
|
/** What the host hands each request: its platform, already scoped to the app, build, request and user. */
|
|
47
51
|
export type PlatformBinding = {
|