@dapplelight/signet-server 0.3.2 → 0.5.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/README.md +1481 -13
- package/dist/abuse/captcha.d.ts +46 -0
- package/dist/abuse/captcha.d.ts.map +1 -0
- package/dist/abuse/captcha.js +123 -0
- package/dist/abuse/captcha.js.map +1 -0
- package/dist/abuse/disposable-domains.d.ts +2 -0
- package/dist/abuse/disposable-domains.d.ts.map +1 -0
- package/dist/abuse/disposable-domains.js +2 -0
- package/dist/abuse/disposable-domains.js.map +1 -0
- package/dist/abuse/email.d.ts +15 -0
- package/dist/abuse/email.d.ts.map +1 -0
- package/dist/abuse/email.js +87 -0
- package/dist/abuse/email.js.map +1 -0
- package/dist/adapters/cloudflare.d.ts +43 -0
- package/dist/adapters/cloudflare.d.ts.map +1 -0
- package/dist/adapters/cloudflare.js +36 -0
- package/dist/adapters/cloudflare.js.map +1 -0
- package/dist/adapters/index.d.ts +39 -0
- package/dist/adapters/index.d.ts.map +1 -0
- package/dist/adapters/index.js +80 -0
- package/dist/adapters/index.js.map +1 -0
- package/dist/adapters/node.d.ts +3 -0
- package/dist/adapters/node.d.ts.map +1 -0
- package/dist/adapters/node.js +37 -0
- package/dist/adapters/node.js.map +1 -0
- package/dist/adapters/s3.d.ts +25 -0
- package/dist/adapters/s3.d.ts.map +1 -0
- package/dist/adapters/s3.js +102 -0
- package/dist/adapters/s3.js.map +1 -0
- package/dist/adapters/supabase.d.ts +20 -0
- package/dist/adapters/supabase.d.ts.map +1 -0
- package/dist/adapters/supabase.js +88 -0
- package/dist/adapters/supabase.js.map +1 -0
- package/dist/adapters/upstash.d.ts +15 -0
- package/dist/adapters/upstash.d.ts.map +1 -0
- package/dist/adapters/upstash.js +63 -0
- package/dist/adapters/upstash.js.map +1 -0
- package/dist/adapters/vercel.d.ts +3 -0
- package/dist/adapters/vercel.d.ts.map +1 -0
- package/dist/adapters/vercel.js +4 -0
- package/dist/adapters/vercel.js.map +1 -0
- package/dist/analytics/engine.d.ts +3 -0
- package/dist/analytics/engine.d.ts.map +1 -1
- package/dist/analytics/engine.js +2 -1
- package/dist/analytics/engine.js.map +1 -1
- package/dist/analytics/index.d.ts +2 -0
- package/dist/analytics/index.d.ts.map +1 -1
- package/dist/analytics/index.js +2 -0
- package/dist/analytics/index.js.map +1 -1
- package/dist/analytics/ingest.d.ts +6 -2
- package/dist/analytics/ingest.d.ts.map +1 -1
- package/dist/analytics/ingest.js +11 -2
- package/dist/analytics/ingest.js.map +1 -1
- package/dist/analytics/session.d.ts +23 -0
- package/dist/analytics/session.d.ts.map +1 -0
- package/dist/analytics/session.js +26 -0
- package/dist/analytics/session.js.map +1 -0
- package/dist/analytics/sinks.d.ts +21 -0
- package/dist/analytics/sinks.d.ts.map +1 -0
- package/dist/analytics/sinks.js +58 -0
- package/dist/analytics/sinks.js.map +1 -0
- package/dist/auth/api-keys.d.ts +49 -0
- package/dist/auth/api-keys.d.ts.map +1 -0
- package/dist/auth/api-keys.js +111 -0
- package/dist/auth/api-keys.js.map +1 -0
- package/dist/auth/client-login.d.ts +89 -0
- package/dist/auth/client-login.d.ts.map +1 -0
- package/dist/auth/client-login.js +293 -0
- package/dist/auth/client-login.js.map +1 -0
- package/dist/auth/hono.d.ts +167 -1
- package/dist/auth/hono.d.ts.map +1 -1
- package/dist/auth/hono.js +162 -3
- package/dist/auth/hono.js.map +1 -1
- package/dist/auth/index.d.ts +4 -0
- package/dist/auth/index.d.ts.map +1 -1
- package/dist/auth/index.js +4 -0
- package/dist/auth/index.js.map +1 -1
- package/dist/auth/mcp.d.ts +10 -0
- package/dist/auth/mcp.d.ts.map +1 -0
- package/dist/auth/mcp.js +81 -0
- package/dist/auth/mcp.js.map +1 -0
- package/dist/auth/otp.d.ts +63 -0
- package/dist/auth/otp.d.ts.map +1 -0
- package/dist/auth/otp.js +132 -0
- package/dist/auth/otp.js.map +1 -0
- package/dist/auth/session.d.ts +12 -2
- package/dist/auth/session.d.ts.map +1 -1
- package/dist/auth/session.js +32 -16
- package/dist/auth/session.js.map +1 -1
- package/dist/auth/sessions.d.ts +65 -0
- package/dist/auth/sessions.d.ts.map +1 -0
- package/dist/auth/sessions.js +194 -0
- package/dist/auth/sessions.js.map +1 -0
- package/dist/http/admin.d.ts +21 -0
- package/dist/http/admin.d.ts.map +1 -0
- package/dist/http/admin.js +49 -0
- package/dist/http/admin.js.map +1 -0
- package/dist/http/ai-spend.d.ts +127 -0
- package/dist/http/ai-spend.d.ts.map +1 -0
- package/dist/http/ai-spend.js +109 -0
- package/dist/http/ai-spend.js.map +1 -0
- package/dist/http/cache.d.ts +26 -0
- package/dist/http/cache.d.ts.map +1 -0
- package/dist/http/cache.js +143 -0
- package/dist/http/cache.js.map +1 -0
- package/dist/http/collab.d.ts +229 -0
- package/dist/http/collab.d.ts.map +1 -0
- package/dist/http/collab.js +154 -0
- package/dist/http/collab.js.map +1 -0
- package/dist/http/errors.d.ts.map +1 -1
- package/dist/http/errors.js +20 -0
- package/dist/http/errors.js.map +1 -1
- package/dist/http/experiments.d.ts +174 -0
- package/dist/http/experiments.d.ts.map +1 -0
- package/dist/http/experiments.js +78 -0
- package/dist/http/experiments.js.map +1 -0
- package/dist/http/funnels.d.ts +207 -0
- package/dist/http/funnels.d.ts.map +1 -0
- package/dist/http/funnels.js +366 -0
- package/dist/http/funnels.js.map +1 -0
- package/dist/http/monetisation.d.ts +504 -0
- package/dist/http/monetisation.d.ts.map +1 -0
- package/dist/http/monetisation.js +323 -0
- package/dist/http/monetisation.js.map +1 -0
- package/dist/http/openapi.d.ts +112 -0
- package/dist/http/openapi.d.ts.map +1 -0
- package/dist/http/openapi.js +247 -0
- package/dist/http/openapi.js.map +1 -0
- package/dist/http/orgs.d.ts +605 -0
- package/dist/http/orgs.d.ts.map +1 -0
- package/dist/http/orgs.js +241 -0
- package/dist/http/orgs.js.map +1 -0
- package/dist/http/routes.d.ts +90 -0
- package/dist/http/routes.d.ts.map +1 -0
- package/dist/http/routes.js +29 -0
- package/dist/http/routes.js.map +1 -0
- package/dist/http/sanitize.d.ts +3 -0
- package/dist/http/sanitize.d.ts.map +1 -0
- package/dist/http/sanitize.js +158 -0
- package/dist/http/sanitize.js.map +1 -0
- package/dist/http/status.d.ts +157 -0
- package/dist/http/status.d.ts.map +1 -0
- package/dist/http/status.js +53 -0
- package/dist/http/status.js.map +1 -0
- package/dist/http/store-helpers.d.ts +9 -0
- package/dist/http/store-helpers.d.ts.map +1 -0
- package/dist/http/store-helpers.js +28 -0
- package/dist/http/store-helpers.js.map +1 -0
- package/dist/http/validate.d.ts +13 -1
- package/dist/http/validate.d.ts.map +1 -1
- package/dist/http/validate.js +14 -3
- package/dist/http/validate.js.map +1 -1
- package/dist/http/webhooks.d.ts +206 -0
- package/dist/http/webhooks.d.ts.map +1 -0
- package/dist/http/webhooks.js +91 -0
- package/dist/http/webhooks.js.map +1 -0
- package/dist/http/workflows.d.ts +182 -0
- package/dist/http/workflows.d.ts.map +1 -0
- package/dist/http/workflows.js +109 -0
- package/dist/http/workflows.js.map +1 -0
- package/dist/jobs/cron.d.ts +40 -0
- package/dist/jobs/cron.d.ts.map +1 -0
- package/dist/jobs/cron.js +106 -0
- package/dist/jobs/cron.js.map +1 -0
- package/dist/jobs/index.d.ts +6 -0
- package/dist/jobs/index.d.ts.map +1 -0
- package/dist/jobs/index.js +5 -0
- package/dist/jobs/index.js.map +1 -0
- package/dist/jobs/jobs.d.ts +206 -0
- package/dist/jobs/jobs.d.ts.map +1 -0
- package/dist/jobs/jobs.js +439 -0
- package/dist/jobs/jobs.js.map +1 -0
- package/dist/jobs/runtimes.d.ts +51 -0
- package/dist/jobs/runtimes.d.ts.map +1 -0
- package/dist/jobs/runtimes.js +162 -0
- package/dist/jobs/runtimes.js.map +1 -0
- package/dist/jobs/steps.d.ts +64 -0
- package/dist/jobs/steps.d.ts.map +1 -0
- package/dist/jobs/steps.js +143 -0
- package/dist/jobs/steps.js.map +1 -0
- package/dist/jobs/tools.d.ts +7 -0
- package/dist/jobs/tools.d.ts.map +1 -0
- package/dist/jobs/tools.js +110 -0
- package/dist/jobs/tools.js.map +1 -0
- package/dist/mcp/approvals.d.ts +46 -0
- package/dist/mcp/approvals.d.ts.map +1 -0
- package/dist/mcp/approvals.js +116 -0
- package/dist/mcp/approvals.js.map +1 -0
- package/dist/mcp/client.d.ts +43 -0
- package/dist/mcp/client.d.ts.map +1 -0
- package/dist/mcp/client.js +175 -0
- package/dist/mcp/client.js.map +1 -0
- package/dist/mcp/errors.d.ts +1 -0
- package/dist/mcp/errors.d.ts.map +1 -1
- package/dist/mcp/errors.js +4 -1
- package/dist/mcp/errors.js.map +1 -1
- package/dist/mcp/hono.d.ts +12 -3
- package/dist/mcp/hono.d.ts.map +1 -1
- package/dist/mcp/hono.js +45 -7
- package/dist/mcp/hono.js.map +1 -1
- package/dist/mcp/index.d.ts +3 -1
- package/dist/mcp/index.d.ts.map +1 -1
- package/dist/mcp/index.js +3 -1
- package/dist/mcp/index.js.map +1 -1
- package/dist/mcp/interaction.d.ts +9 -1
- package/dist/mcp/interaction.d.ts.map +1 -1
- package/dist/mcp/interaction.js +75 -0
- package/dist/mcp/interaction.js.map +1 -1
- package/dist/mcp/routes.d.ts +40 -0
- package/dist/mcp/routes.d.ts.map +1 -0
- package/dist/mcp/routes.js +190 -0
- package/dist/mcp/routes.js.map +1 -0
- package/dist/mcp/server.d.ts +65 -2
- package/dist/mcp/server.d.ts.map +1 -1
- package/dist/mcp/server.js +135 -9
- package/dist/mcp/server.js.map +1 -1
- package/dist/middleware/cors.d.ts +1 -0
- package/dist/middleware/cors.d.ts.map +1 -1
- package/dist/middleware/cors.js +11 -11
- package/dist/middleware/cors.js.map +1 -1
- package/dist/middleware/csrf.d.ts +4 -0
- package/dist/middleware/csrf.d.ts.map +1 -0
- package/dist/middleware/csrf.js +24 -0
- package/dist/middleware/csrf.js.map +1 -0
- package/dist/middleware/index.d.ts +2 -0
- package/dist/middleware/index.d.ts.map +1 -1
- package/dist/middleware/index.js +2 -0
- package/dist/middleware/index.js.map +1 -1
- package/dist/middleware/maintenance.d.ts +18 -0
- package/dist/middleware/maintenance.d.ts.map +1 -0
- package/dist/middleware/maintenance.js +38 -0
- package/dist/middleware/maintenance.js.map +1 -0
- package/dist/middleware/rate-limit.d.ts +5 -1
- package/dist/middleware/rate-limit.d.ts.map +1 -1
- package/dist/middleware/rate-limit.js +65 -5
- package/dist/middleware/rate-limit.js.map +1 -1
- package/dist/notify/channels.d.ts +61 -0
- package/dist/notify/channels.d.ts.map +1 -0
- package/dist/notify/channels.js +239 -0
- package/dist/notify/channels.js.map +1 -0
- package/dist/notify/notifier.d.ts +326 -0
- package/dist/notify/notifier.d.ts.map +1 -0
- package/dist/notify/notifier.js +610 -0
- package/dist/notify/notifier.js.map +1 -0
- package/dist/notify/push.d.ts +26 -0
- package/dist/notify/push.d.ts.map +1 -1
- package/dist/notify/push.js +110 -0
- package/dist/notify/push.js.map +1 -1
- package/dist/notify/tools.d.ts +9 -0
- package/dist/notify/tools.d.ts.map +1 -0
- package/dist/notify/tools.js +122 -0
- package/dist/notify/tools.js.map +1 -0
- package/dist/notify/webhooks.d.ts +65 -0
- package/dist/notify/webhooks.d.ts.map +1 -0
- package/dist/notify/webhooks.js +201 -0
- package/dist/notify/webhooks.js.map +1 -0
- package/dist/observability/sentry.d.ts +32 -1
- package/dist/observability/sentry.d.ts.map +1 -1
- package/dist/observability/sentry.js +63 -14
- package/dist/observability/sentry.js.map +1 -1
- package/dist/realtime/bun.d.ts +33 -0
- package/dist/realtime/bun.d.ts.map +1 -0
- package/dist/realtime/bun.js +38 -0
- package/dist/realtime/bun.js.map +1 -0
- package/dist/realtime/cloudflare.d.ts +28 -0
- package/dist/realtime/cloudflare.d.ts.map +1 -0
- package/dist/realtime/cloudflare.js +60 -0
- package/dist/realtime/cloudflare.js.map +1 -0
- package/dist/realtime/index.d.ts +118 -0
- package/dist/realtime/index.d.ts.map +1 -0
- package/dist/realtime/index.js +397 -0
- package/dist/realtime/index.js.map +1 -0
- package/dist/realtime/node.d.ts +8 -0
- package/dist/realtime/node.d.ts.map +1 -0
- package/dist/realtime/node.js +153 -0
- package/dist/realtime/node.js.map +1 -0
- package/dist/storage/index.d.ts +3 -0
- package/dist/storage/index.d.ts.map +1 -0
- package/dist/storage/index.js +3 -0
- package/dist/storage/index.js.map +1 -0
- package/dist/storage/metadata.d.ts +3 -0
- package/dist/storage/metadata.d.ts.map +1 -0
- package/dist/storage/metadata.js +183 -0
- package/dist/storage/metadata.js.map +1 -0
- package/dist/storage/uploads.d.ts +146 -0
- package/dist/storage/uploads.d.ts.map +1 -0
- package/dist/storage/uploads.js +315 -0
- package/dist/storage/uploads.js.map +1 -0
- package/package.json +174 -2
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { type Context } from "hono";
|
|
2
|
+
import type { MaintenanceState } from "../middleware/maintenance.js";
|
|
3
|
+
import { type Actor } from "./store-helpers.js";
|
|
4
|
+
export type StatusStore = {
|
|
5
|
+
summary(opts?: {
|
|
6
|
+
days?: number;
|
|
7
|
+
}): Promise<unknown>;
|
|
8
|
+
components(): Promise<unknown[]>;
|
|
9
|
+
incidents(opts?: {
|
|
10
|
+
days?: number;
|
|
11
|
+
limit?: number;
|
|
12
|
+
}): Promise<unknown[]>;
|
|
13
|
+
setComponent(key: string, input: never, opts: {
|
|
14
|
+
actor: Actor;
|
|
15
|
+
}): Promise<unknown>;
|
|
16
|
+
removeComponent(key: string, opts: {
|
|
17
|
+
actor: Actor;
|
|
18
|
+
}): Promise<boolean>;
|
|
19
|
+
openIncident(input: never, opts: {
|
|
20
|
+
actor: Actor;
|
|
21
|
+
}): Promise<unknown>;
|
|
22
|
+
updateIncident(id: string, input: never, opts: {
|
|
23
|
+
actor: Actor;
|
|
24
|
+
}): Promise<unknown>;
|
|
25
|
+
maintenance(): Promise<MaintenanceState>;
|
|
26
|
+
setMaintenance(input: {
|
|
27
|
+
on: boolean;
|
|
28
|
+
message?: string | null;
|
|
29
|
+
until?: Date | null;
|
|
30
|
+
}, opts: {
|
|
31
|
+
actor: Actor;
|
|
32
|
+
}): Promise<unknown>;
|
|
33
|
+
};
|
|
34
|
+
export declare function statusRoutes(opts: {
|
|
35
|
+
status: Pick<StatusStore, "summary">;
|
|
36
|
+
maxAge?: number;
|
|
37
|
+
}): import("hono/hono-base").HonoBase<import("hono/types").BlankEnv, {
|
|
38
|
+
"/": {
|
|
39
|
+
$get: {
|
|
40
|
+
output: import("hono/utils/types").JSONValue;
|
|
41
|
+
outputFormat: "json";
|
|
42
|
+
status: import("hono/utils/http-status").ContentfulStatusCode;
|
|
43
|
+
input: {};
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
}, "/", "/">;
|
|
47
|
+
export type StatusAdminOptions = {
|
|
48
|
+
status: StatusStore;
|
|
49
|
+
authorize: (c: Context) => unknown;
|
|
50
|
+
actor: (c: Context) => Actor | Promise<Actor>;
|
|
51
|
+
};
|
|
52
|
+
export declare function statusAdminRoutes(opts: StatusAdminOptions): import("hono/hono-base").HonoBase<import("hono/types").BlankEnv, {
|
|
53
|
+
"/components": {
|
|
54
|
+
$get: {
|
|
55
|
+
output: {
|
|
56
|
+
components: import("hono/utils/types").JSONValue[];
|
|
57
|
+
};
|
|
58
|
+
outputFormat: "json";
|
|
59
|
+
status: import("hono/utils/http-status").ContentfulStatusCode;
|
|
60
|
+
input: {};
|
|
61
|
+
};
|
|
62
|
+
};
|
|
63
|
+
} & {
|
|
64
|
+
"/components/:key": {
|
|
65
|
+
$put: {
|
|
66
|
+
output: {
|
|
67
|
+
component: import("hono/utils/types").JSONValue;
|
|
68
|
+
};
|
|
69
|
+
outputFormat: "json";
|
|
70
|
+
status: import("hono/utils/http-status").ContentfulStatusCode;
|
|
71
|
+
input: {
|
|
72
|
+
param: {
|
|
73
|
+
key: string;
|
|
74
|
+
};
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
};
|
|
78
|
+
} & {
|
|
79
|
+
"/components/:key": {
|
|
80
|
+
$delete: {
|
|
81
|
+
output: {
|
|
82
|
+
removed: true;
|
|
83
|
+
};
|
|
84
|
+
outputFormat: "json";
|
|
85
|
+
status: import("hono/utils/http-status").ContentfulStatusCode;
|
|
86
|
+
input: {
|
|
87
|
+
param: {
|
|
88
|
+
key: string;
|
|
89
|
+
};
|
|
90
|
+
};
|
|
91
|
+
};
|
|
92
|
+
};
|
|
93
|
+
} & {
|
|
94
|
+
"/incidents": {
|
|
95
|
+
$get: {
|
|
96
|
+
output: {
|
|
97
|
+
incidents: import("hono/utils/types").JSONValue[];
|
|
98
|
+
};
|
|
99
|
+
outputFormat: "json";
|
|
100
|
+
status: import("hono/utils/http-status").ContentfulStatusCode;
|
|
101
|
+
input: {};
|
|
102
|
+
};
|
|
103
|
+
};
|
|
104
|
+
} & {
|
|
105
|
+
"/incidents": {
|
|
106
|
+
$post: {
|
|
107
|
+
output: {
|
|
108
|
+
incident: import("hono/utils/types").JSONValue;
|
|
109
|
+
};
|
|
110
|
+
outputFormat: "json";
|
|
111
|
+
status: 201;
|
|
112
|
+
input: {};
|
|
113
|
+
};
|
|
114
|
+
};
|
|
115
|
+
} & {
|
|
116
|
+
"/incidents/:id/updates": {
|
|
117
|
+
$post: {
|
|
118
|
+
output: {
|
|
119
|
+
incident: import("hono/utils/types").JSONValue;
|
|
120
|
+
};
|
|
121
|
+
outputFormat: "json";
|
|
122
|
+
status: import("hono/utils/http-status").ContentfulStatusCode;
|
|
123
|
+
input: {
|
|
124
|
+
param: {
|
|
125
|
+
id: string;
|
|
126
|
+
};
|
|
127
|
+
};
|
|
128
|
+
};
|
|
129
|
+
};
|
|
130
|
+
} & {
|
|
131
|
+
"/maintenance": {
|
|
132
|
+
$get: {
|
|
133
|
+
output: {
|
|
134
|
+
maintenance: {
|
|
135
|
+
on: boolean;
|
|
136
|
+
message?: string | null;
|
|
137
|
+
until?: string | null | undefined;
|
|
138
|
+
};
|
|
139
|
+
};
|
|
140
|
+
outputFormat: "json";
|
|
141
|
+
status: import("hono/utils/http-status").ContentfulStatusCode;
|
|
142
|
+
input: {};
|
|
143
|
+
};
|
|
144
|
+
};
|
|
145
|
+
} & {
|
|
146
|
+
"/maintenance": {
|
|
147
|
+
$put: {
|
|
148
|
+
output: {
|
|
149
|
+
maintenance: import("hono/utils/types").JSONValue;
|
|
150
|
+
};
|
|
151
|
+
outputFormat: "json";
|
|
152
|
+
status: import("hono/utils/http-status").ContentfulStatusCode;
|
|
153
|
+
input: {};
|
|
154
|
+
};
|
|
155
|
+
};
|
|
156
|
+
}, "/", "/maintenance">;
|
|
157
|
+
//# sourceMappingURL=status.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"status.d.ts","sourceRoot":"","sources":["../../src/http/status.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,KAAK,OAAO,EAAQ,MAAM,MAAM,CAAA;AACzC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAA;AAEpE,OAAO,EAAE,KAAK,KAAK,EAAmC,MAAM,oBAAoB,CAAA;AAGhF,MAAM,MAAM,WAAW,GAAG;IACxB,OAAO,CAAC,IAAI,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,OAAO,CAAC,CAAA;IACnD,UAAU,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC,CAAA;IAChC,SAAS,CAAC,IAAI,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC,CAAA;IACvE,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE;QAAE,KAAK,EAAE,KAAK,CAAA;KAAE,GAAG,OAAO,CAAC,OAAO,CAAC,CAAA;IACjF,eAAe,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE;QAAE,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
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { Hono } from "hono";
|
|
2
|
+
import { ApiException } from "./errors.js";
|
|
3
|
+
import { adminGate, jsonBody, storeError } from "./store-helpers.js";
|
|
4
|
+
export function statusRoutes(opts) {
|
|
5
|
+
return new Hono().get("/", async (c) => {
|
|
6
|
+
c.header("Cache-Control", `public, max-age=${opts.maxAge ?? 30}`);
|
|
7
|
+
return c.json(await opts.status.summary());
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
export function statusAdminRoutes(opts) {
|
|
11
|
+
const { status } = opts;
|
|
12
|
+
const app = new Hono();
|
|
13
|
+
app.onError(storeError);
|
|
14
|
+
app.use(adminGate(opts.authorize));
|
|
15
|
+
const actor = async (c) => ({ actor: await opts.actor(c) });
|
|
16
|
+
return app
|
|
17
|
+
.get("/components", async (c) => c.json({ components: await status.components() }))
|
|
18
|
+
.put("/components/:key", async (c) => c.json({
|
|
19
|
+
component: await status.setComponent(c.req.param("key"), (await jsonBody(c)), await actor(c)),
|
|
20
|
+
}))
|
|
21
|
+
.delete("/components/:key", async (c) => {
|
|
22
|
+
if (!(await status.removeComponent(c.req.param("key"), await actor(c))))
|
|
23
|
+
throw new ApiException(404, "No such component.", "NOT_FOUND");
|
|
24
|
+
return c.json({ removed: true });
|
|
25
|
+
})
|
|
26
|
+
.get("/incidents", async (c) => {
|
|
27
|
+
const days = Number(c.req.query("days") ?? 30);
|
|
28
|
+
if (!Number.isFinite(days) || days < 0 || days > 3650)
|
|
29
|
+
throw new ApiException(400, "days is 0 to 3650.", "VALIDATION_FAILED");
|
|
30
|
+
return c.json({ incidents: await status.incidents({ days, limit: 200 }) });
|
|
31
|
+
})
|
|
32
|
+
.post("/incidents", async (c) => c.json({ incident: await status.openIncident((await jsonBody(c)), await actor(c)) }, 201))
|
|
33
|
+
.post("/incidents/:id/updates", async (c) => c.json({
|
|
34
|
+
incident: await status.updateIncident(c.req.param("id"), (await jsonBody(c)), await actor(c)),
|
|
35
|
+
}))
|
|
36
|
+
.get("/maintenance", async (c) => c.json({ maintenance: await status.maintenance() }))
|
|
37
|
+
.put("/maintenance", async (c) => {
|
|
38
|
+
const b = await jsonBody(c);
|
|
39
|
+
let until = null;
|
|
40
|
+
if (b.until != null) {
|
|
41
|
+
until = new Date(String(b.until));
|
|
42
|
+
if (Number.isNaN(until.getTime()))
|
|
43
|
+
throw new ApiException(400, "until is an ISO date.", "VALIDATION_FAILED");
|
|
44
|
+
}
|
|
45
|
+
if (typeof b.on !== "boolean")
|
|
46
|
+
throw new ApiException(400, "on is true or false.", "VALIDATION_FAILED");
|
|
47
|
+
const message = typeof b.message === "string" ? b.message : null;
|
|
48
|
+
return c.json({
|
|
49
|
+
maintenance: await status.setMaintenance({ on: b.on, message, until }, await actor(c)),
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=status.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"status.js","sourceRoot":"","sources":["../../src/http/status.ts"],"names":[],"mappings":"AAeA,OAAO,EAAgB,IAAI,EAAE,MAAM,MAAM,CAAA;AAEzC,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAC1C,OAAO,EAAc,SAAS,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA;AAuBhF,MAAM,UAAU,YAAY,CAAC,IAA+D;IAC1F,OAAO,IAAI,IAAI,EAAE,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE;QACrC,CAAC,CAAC,MAAM,CAAC,eAAe,EAAE,mBAAmB,IAAI,CAAC,MAAM,IAAI,EAAE,EAAE,CAAC,CAAA;QACjE,OAAO,CAAC,CAAC,IAAI,CAAC,MAAM,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC,CAAA;IAC5C,CAAC,CAAC,CAAA;AACJ,CAAC;AAsBD,MAAM,UAAU,iBAAiB,CAAC,IAAwB;IACxD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AE,KAAK,EAAE,CAAC,EAAE,EAAE;QAC/B,MAAM,CAAC,GAAG,MAAM,QAAQ,CAAC,CAAC,CAAC,CAAA;QAC3B,IAAI,KAAK,GAAgB,IAAI,CAAA;QAC7B,IAAI,CAAC,CAAC,KAAK,IAAI,IAAI,EAAE,CAAC;YACpB,KAAK,GAAG,IAAI,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAA;YACjC,IAAI,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC;gBAC/B,MAAM,IAAI,YAAY,CAAC,GAAG,EAAE,uBAAuB,EAAE,mBAAmB,CAAC,CAAA;QAC7E,CAAC;QACD,IAAI,OAAO,CAAC,CAAC,EAAE,KAAK,SAAS;YAC3B,MAAM,IAAI,YAAY,CAAC,GAAG,EAAE,sBAAsB,EAAE,mBAAmB,CAAC,CAAA;QAC1E,MAAM,OAAO,GAAG,OAAO,CAAC,CAAC,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAA;QAChE,OAAO,CAAC,CAAC,IAAI,CAAC;YACZ,WAAW,EAAE,MAAM,MAAM,CAAC,cAAc,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC;SACvF,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AACN,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Context, MiddlewareHandler } from "hono";
|
|
2
|
+
export type Actor = {
|
|
3
|
+
type: "user" | "agent" | "system";
|
|
4
|
+
id: string;
|
|
5
|
+
};
|
|
6
|
+
export declare const storeError: (e: Error) => never;
|
|
7
|
+
export declare const jsonBody: (c: Context) => Promise<Record<string, unknown>>;
|
|
8
|
+
export declare const adminGate: (authorize: (c: Context) => unknown) => MiddlewareHandler;
|
|
9
|
+
//# sourceMappingURL=store-helpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"store-helpers.d.ts","sourceRoot":"","sources":["../../src/http/store-helpers.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,OAAO,EAAE,iBAAiB,EAAE,MAAM,MAAM,CAAA;AAGtD,MAAM,MAAM,KAAK,GAAG;IAAE,IAAI,EAAE,MAAM,GAAG,OAAO,GAAG,QAAQ,CAAC;IAAC,EAAE,EAAE,MAAM,CAAA;CAAE,CAAA;AAUrE,eAAO,MAAM,UAAU,MAAO,KAAK,UASlC,CAAA;AAGD,eAAO,MAAM,QAAQ,MAAa,OAAO,KAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAO1E,CAAA;AAGD,eAAO,MAAM,SAAS,cACR,CAAC,CAAC,EAAE,OAAO,KAAK,OAAO,KAAG,iBAKrC,CAAA"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { ApiException } from "./errors.js";
|
|
2
|
+
const STATUS = {
|
|
3
|
+
BAD_VALUE: 400,
|
|
4
|
+
NOT_FOUND: 404,
|
|
5
|
+
CONFLICT: 409,
|
|
6
|
+
FORBIDDEN: 403,
|
|
7
|
+
};
|
|
8
|
+
export const storeError = (e) => {
|
|
9
|
+
const code = e.code;
|
|
10
|
+
if (e.name === "SignetDbError" && typeof code === "string" && STATUS[code])
|
|
11
|
+
throw new ApiException(STATUS[code], e.message, code === "BAD_VALUE" ? "VALIDATION_FAILED" : code);
|
|
12
|
+
throw e;
|
|
13
|
+
};
|
|
14
|
+
export const jsonBody = async (c) => {
|
|
15
|
+
try {
|
|
16
|
+
const v = await c.req.json();
|
|
17
|
+
return v && typeof v === "object" && !Array.isArray(v) ? v : {};
|
|
18
|
+
}
|
|
19
|
+
catch {
|
|
20
|
+
throw new ApiException(400, "Invalid JSON body", "INVALID_JSON");
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
export const adminGate = (authorize) => async (c, next) => {
|
|
24
|
+
if ((await authorize(c)) !== true)
|
|
25
|
+
throw new ApiException(403, "You do not have permission to do that.", "FORBIDDEN");
|
|
26
|
+
await next();
|
|
27
|
+
};
|
|
28
|
+
//# sourceMappingURL=store-helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"store-helpers.js","sourceRoot":"","sources":["../../src/http/store-helpers.ts"],"names":[],"mappings":"AAOA,OAAO,EAAuB,YAAY,EAAE,MAAM,aAAa,CAAA;AAI/D,MAAM,MAAM,GAAmC;IAC7C,SAAS,EAAE,GAAG;IACd,SAAS,EAAE,GAAG;IACd,QAAQ,EAAE,GAAG;IACb,SAAS,EAAE,GAAG;CACf,CAAA;AAGD,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,CAAQ,EAAE,EAAE;IACrC,MAAM,IAAI,GAAI,CAAwB,CAAC,IAAI,CAAA;IAC3C,IAAI,CAAC,CAAC,IAAI,KAAK,eAAe,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,MAAM,CAAC,IAAI,CAAC;QACxE,MAAM,IAAI,YAAY,CACpB,MAAM,CAAC,IAAI,CAAmB,EAC9B,CAAC,CAAC,OAAO,EACT,IAAI,KAAK,WAAW,CAAC,CAAC,CAAC,mBAAmB,CAAC,CAAC,CAAC,IAAI,CAClD,CAAA;IACH,MAAM,CAAC,CAAA;AACT,CAAC,CAAA;AAGD,MAAM,CAAC,MAAM,QAAQ,GAAG,KAAK,EAAE,CAAU,EAAoC,EAAE;IAC7E,IAAI,CAAC;QACH,MAAM,CAAC,GAAG,MAAM,CAAC,CAAC,GAAG,CAAC,IAAI,EAAE,CAAA;QAC5B,OAAO,CAAC,IAAI,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAE,CAA6B,CAAC,CAAC,CAAC,EAAE,CAAA;IAC9F,CAAC;IAAC,MAAM,CAAC;QACP,MAAM,IAAI,YAAY,CAAC,GAAG,EAAE,mBAAmB,EAAE,cAAc,CAAC,CAAA;IAClE,CAAC;AACH,CAAC,CAAA;AAGD,MAAM,CAAC,MAAM,SAAS,GACpB,CAAC,SAAkC,EAAqB,EAAE,CAC1D,KAAK,EAAE,CAAC,EAAE,IAAI,EAAE,EAAE;IAChB,IAAI,CAAC,MAAM,SAAS,CAAC,CAAC,CAAC,CAAC,KAAK,IAAI;QAC/B,MAAM,IAAI,YAAY,CAAC,GAAG,EAAE,wCAAwC,EAAE,WAAW,CAAC,CAAA;IACpF,MAAM,IAAI,EAAE,CAAA;AACd,CAAC,CAAA"}
|
package/dist/http/validate.d.ts
CHANGED
|
@@ -1,6 +1,18 @@
|
|
|
1
|
-
import type { Context } from "hono";
|
|
1
|
+
import type { Context, MiddlewareHandler, ValidationTargets } from "hono";
|
|
2
|
+
import { type InferInput } from "hono/validator";
|
|
2
3
|
import type { z } from "zod";
|
|
3
4
|
export declare function parseBody<T>(c: Context, schema: z.ZodType<T>): Promise<T>;
|
|
4
5
|
export declare function parseQuery<T>(c: Context, schema: z.ZodType<T>): T;
|
|
5
6
|
export declare function parseParams<T>(c: Context, schema: z.ZodType<T>): T;
|
|
7
|
+
type ClientInput<T extends keyof ValidationTargets, S extends z.ZodType> = T extends "json" ? z.input<S> : InferInput<z.input<S>, T>;
|
|
8
|
+
export declare function zValidator<T extends keyof ValidationTargets, S extends z.ZodType>(target: T, schema: S): MiddlewareHandler<any, string, {
|
|
9
|
+
in: {
|
|
10
|
+
[K in T]: ClientInput<K, S>;
|
|
11
|
+
};
|
|
12
|
+
out: {
|
|
13
|
+
[K in T]: z.output<S>;
|
|
14
|
+
};
|
|
15
|
+
}>;
|
|
16
|
+
export declare const VALIDATES: unique symbol;
|
|
17
|
+
export {};
|
|
6
18
|
//# sourceMappingURL=validate.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../../src/http/validate.ts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,CAAC,CAAC;KAAE,CAAC;IAAC,GAAG,EAAE;SAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;KAAE,CAAA;CAAE,CACxE,CASA;AAGD,eAAO,MAAM,SAAS,eAAsC,CAAA"}
|
package/dist/http/validate.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
+
import { validator } from "hono/validator";
|
|
1
2
|
import { ApiException } from "./errors.js";
|
|
2
3
|
function fail(result) {
|
|
3
4
|
const formErrors = [];
|
|
4
5
|
const fieldErrors = {};
|
|
5
6
|
for (const issue of result.error.issues) {
|
|
6
|
-
|
|
7
|
-
if (key === undefined)
|
|
7
|
+
if (issue.path.length === 0)
|
|
8
8
|
formErrors.push(issue.message);
|
|
9
9
|
else {
|
|
10
|
-
const k = String(
|
|
10
|
+
const k = issue.path.map(String).join(".");
|
|
11
11
|
fieldErrors[k] = [...(fieldErrors[k] ?? []), issue.message];
|
|
12
12
|
}
|
|
13
13
|
}
|
|
@@ -39,4 +39,15 @@ export function parseParams(c, schema) {
|
|
|
39
39
|
fail(result);
|
|
40
40
|
return result.data;
|
|
41
41
|
}
|
|
42
|
+
export function zValidator(target, schema) {
|
|
43
|
+
const mw = validator(target, async (value) => {
|
|
44
|
+
const result = await schema.safeParseAsync(value);
|
|
45
|
+
if (!result.success)
|
|
46
|
+
fail(result);
|
|
47
|
+
return result.data;
|
|
48
|
+
});
|
|
49
|
+
Object.defineProperty(mw, VALIDATES, { value: { target, schema } });
|
|
50
|
+
return mw;
|
|
51
|
+
}
|
|
52
|
+
export const VALIDATES = Symbol.for("signet.http.validates");
|
|
42
53
|
//# sourceMappingURL=validate.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validate.js","sourceRoot":"","sources":["../../src/http/validate.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"validate.js","sourceRoot":"","sources":["../../src/http/validate.ts"],"names":[],"mappings":"AAUA,OAAO,EA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AE,EAAE,KAAK,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,CAAC,CAAA;IACnE,OAAO,EAAW,CAAA;AACpB,CAAC;AAGD,MAAM,CAAC,MAAM,SAAS,GAAG,MAAM,CAAC,GAAG,CAAC,uBAAuB,CAAC,CAAA"}
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import { type Context } from "hono";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
export type WebhookDeliveryStatus = "pending" | "retrying" | "delivered" | "failed" | "skipped";
|
|
4
|
+
export type WebhookStore<E, D> = {
|
|
5
|
+
list(owner: string): Promise<E[]>;
|
|
6
|
+
register(input: {
|
|
7
|
+
owner: string;
|
|
8
|
+
url: string;
|
|
9
|
+
events: string[];
|
|
10
|
+
description?: string;
|
|
11
|
+
}): Promise<{
|
|
12
|
+
endpoint: E;
|
|
13
|
+
secret: string;
|
|
14
|
+
}>;
|
|
15
|
+
update(owner: string, id: string, patch: {
|
|
16
|
+
url?: string;
|
|
17
|
+
events?: string[];
|
|
18
|
+
description?: string | null;
|
|
19
|
+
enabled?: boolean;
|
|
20
|
+
}): Promise<E | null>;
|
|
21
|
+
remove(owner: string, id: string): Promise<boolean>;
|
|
22
|
+
rotateSecret(owner: string, id: string): Promise<{
|
|
23
|
+
secret: string;
|
|
24
|
+
} | null>;
|
|
25
|
+
deliveries(owner: string, query: {
|
|
26
|
+
endpointId?: string;
|
|
27
|
+
status?: WebhookDeliveryStatus;
|
|
28
|
+
limit?: number;
|
|
29
|
+
before?: string;
|
|
30
|
+
}): Promise<D[]>;
|
|
31
|
+
redeliver(owner: string, id: string): Promise<D | null>;
|
|
32
|
+
};
|
|
33
|
+
export declare const WebhookEndpointInput: z.ZodObject<{
|
|
34
|
+
url: z.ZodURL;
|
|
35
|
+
events: z.ZodArray<z.ZodString>;
|
|
36
|
+
description: z.ZodOptional<z.ZodString>;
|
|
37
|
+
}, z.core.$strip>;
|
|
38
|
+
export declare const WebhookEndpointPatch: z.ZodObject<{
|
|
39
|
+
url: z.ZodOptional<z.ZodURL>;
|
|
40
|
+
events: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
41
|
+
description: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
42
|
+
enabled: z.ZodOptional<z.ZodBoolean>;
|
|
43
|
+
}, z.core.$strip>;
|
|
44
|
+
export declare const WebhookDeliveryQuery: z.ZodObject<{
|
|
45
|
+
endpointId: z.ZodOptional<z.ZodString>;
|
|
46
|
+
status: z.ZodOptional<z.ZodEnum<{
|
|
47
|
+
delivered: "delivered";
|
|
48
|
+
failed: "failed";
|
|
49
|
+
pending: "pending";
|
|
50
|
+
retrying: "retrying";
|
|
51
|
+
skipped: "skipped";
|
|
52
|
+
}>>;
|
|
53
|
+
limit: z.ZodOptional<z.ZodCoercedNumber<unknown>>;
|
|
54
|
+
before: z.ZodOptional<z.ZodString>;
|
|
55
|
+
}, z.core.$strip>;
|
|
56
|
+
export declare function webhookRoutes<E, D>(opts: {
|
|
57
|
+
webhooks: WebhookStore<E, D>;
|
|
58
|
+
owner: (c: Context) => string | Promise<string>;
|
|
59
|
+
}): import("hono/hono-base").HonoBase<import("hono/types").BlankEnv, {
|
|
60
|
+
"/endpoints": {
|
|
61
|
+
$get: {
|
|
62
|
+
output: import("hono/utils/types").JSONParsed<E extends import("hono/utils/types").InvalidJSONValue ? null : E, bigint | readonly bigint[]>[];
|
|
63
|
+
outputFormat: "json";
|
|
64
|
+
status: import("hono/utils/http-status").ContentfulStatusCode;
|
|
65
|
+
input: {};
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
} & {
|
|
69
|
+
"/endpoints": {
|
|
70
|
+
$post: {
|
|
71
|
+
output: unknown extends (string | E extends bigint | readonly bigint[] ? never : { [K in keyof {
|
|
72
|
+
endpoint: E;
|
|
73
|
+
secret: string;
|
|
74
|
+
} as ({
|
|
75
|
+
endpoint: E;
|
|
76
|
+
secret: string;
|
|
77
|
+
}[K] extends infer T ? T extends {
|
|
78
|
+
endpoint: E;
|
|
79
|
+
secret: string;
|
|
80
|
+
}[K] ? T extends import("hono/utils/types").InvalidJSONValue ? true : false : never : never) extends true ? never : K]: boolean extends ({
|
|
81
|
+
endpoint: E;
|
|
82
|
+
secret: string;
|
|
83
|
+
}[K] extends infer T ? T extends {
|
|
84
|
+
endpoint: E;
|
|
85
|
+
secret: string;
|
|
86
|
+
}[K] ? T extends import("hono/utils/types").InvalidJSONValue ? true : false : never : never) ? import("hono/utils/types").JSONParsed<{
|
|
87
|
+
endpoint: E;
|
|
88
|
+
secret: string;
|
|
89
|
+
}[K], bigint | readonly bigint[]> | undefined : import("hono/utils/types").JSONParsed<{
|
|
90
|
+
endpoint: E;
|
|
91
|
+
secret: string;
|
|
92
|
+
}[K], bigint | readonly bigint[]>; }) ? {} : string | E extends bigint | readonly bigint[] ? never : { [K in keyof {
|
|
93
|
+
endpoint: E;
|
|
94
|
+
secret: string;
|
|
95
|
+
} as ({
|
|
96
|
+
endpoint: E;
|
|
97
|
+
secret: string;
|
|
98
|
+
}[K] extends infer T ? T extends {
|
|
99
|
+
endpoint: E;
|
|
100
|
+
secret: string;
|
|
101
|
+
}[K] ? T extends import("hono/utils/types").InvalidJSONValue ? true : false : never : never) extends true ? never : K]: boolean extends ({
|
|
102
|
+
endpoint: E;
|
|
103
|
+
secret: string;
|
|
104
|
+
}[K] extends infer T ? T extends {
|
|
105
|
+
endpoint: E;
|
|
106
|
+
secret: string;
|
|
107
|
+
}[K] ? T extends import("hono/utils/types").InvalidJSONValue ? true : false : never : never) ? import("hono/utils/types").JSONParsed<{
|
|
108
|
+
endpoint: E;
|
|
109
|
+
secret: string;
|
|
110
|
+
}[K], bigint | readonly bigint[]> | undefined : import("hono/utils/types").JSONParsed<{
|
|
111
|
+
endpoint: E;
|
|
112
|
+
secret: string;
|
|
113
|
+
}[K], bigint | readonly bigint[]>; };
|
|
114
|
+
outputFormat: "json";
|
|
115
|
+
status: 201;
|
|
116
|
+
input: {
|
|
117
|
+
json: {
|
|
118
|
+
url: string;
|
|
119
|
+
events: string[];
|
|
120
|
+
description?: string | undefined;
|
|
121
|
+
};
|
|
122
|
+
};
|
|
123
|
+
};
|
|
124
|
+
};
|
|
125
|
+
} & {
|
|
126
|
+
"/endpoints/:id": {
|
|
127
|
+
$patch: {
|
|
128
|
+
output: unknown extends import("hono/utils/types").JSONParsed<NonNullable<Awaited<E>>, bigint | readonly bigint[]> ? {} : import("hono/utils/types").JSONParsed<NonNullable<Awaited<E>>, bigint | readonly bigint[]>;
|
|
129
|
+
outputFormat: "json";
|
|
130
|
+
status: import("hono/utils/http-status").ContentfulStatusCode;
|
|
131
|
+
input: {
|
|
132
|
+
param: {
|
|
133
|
+
id: string;
|
|
134
|
+
};
|
|
135
|
+
} & {
|
|
136
|
+
json: {
|
|
137
|
+
url?: string | undefined;
|
|
138
|
+
events?: string[] | undefined;
|
|
139
|
+
description?: string | null | undefined;
|
|
140
|
+
enabled?: boolean | undefined;
|
|
141
|
+
};
|
|
142
|
+
};
|
|
143
|
+
};
|
|
144
|
+
};
|
|
145
|
+
} & {
|
|
146
|
+
"/endpoints/:id": {
|
|
147
|
+
$delete: {
|
|
148
|
+
output: {
|
|
149
|
+
deleted: true;
|
|
150
|
+
};
|
|
151
|
+
outputFormat: "json";
|
|
152
|
+
status: import("hono/utils/http-status").ContentfulStatusCode;
|
|
153
|
+
input: {
|
|
154
|
+
param: {
|
|
155
|
+
id: string;
|
|
156
|
+
};
|
|
157
|
+
};
|
|
158
|
+
};
|
|
159
|
+
};
|
|
160
|
+
} & {
|
|
161
|
+
"/endpoints/:id/rotate-secret": {
|
|
162
|
+
$post: {
|
|
163
|
+
output: {
|
|
164
|
+
secret: string;
|
|
165
|
+
};
|
|
166
|
+
outputFormat: "json";
|
|
167
|
+
status: import("hono/utils/http-status").ContentfulStatusCode;
|
|
168
|
+
input: {
|
|
169
|
+
param: {
|
|
170
|
+
id: string;
|
|
171
|
+
};
|
|
172
|
+
};
|
|
173
|
+
};
|
|
174
|
+
};
|
|
175
|
+
} & {
|
|
176
|
+
"/deliveries": {
|
|
177
|
+
$get: {
|
|
178
|
+
output: import("hono/utils/types").JSONParsed<D extends import("hono/utils/types").InvalidJSONValue ? null : D, bigint | readonly bigint[]>[];
|
|
179
|
+
outputFormat: "json";
|
|
180
|
+
status: import("hono/utils/http-status").ContentfulStatusCode;
|
|
181
|
+
input: {
|
|
182
|
+
query: {
|
|
183
|
+
endpointId?: string | undefined;
|
|
184
|
+
status?: "delivered" | "failed" | "pending" | "retrying" | "skipped" | undefined;
|
|
185
|
+
limit?: string | string[] | undefined;
|
|
186
|
+
before?: string | undefined;
|
|
187
|
+
};
|
|
188
|
+
};
|
|
189
|
+
};
|
|
190
|
+
};
|
|
191
|
+
} & {
|
|
192
|
+
"/deliveries/:id/redeliver": {
|
|
193
|
+
$post: {
|
|
194
|
+
output: unknown extends import("hono/utils/types").JSONParsed<NonNullable<Awaited<D>>, bigint | readonly bigint[]> ? {} : import("hono/utils/types").JSONParsed<NonNullable<Awaited<D>>, bigint | readonly bigint[]>;
|
|
195
|
+
outputFormat: "json";
|
|
196
|
+
status: 201;
|
|
197
|
+
input: {
|
|
198
|
+
param: {
|
|
199
|
+
id: string;
|
|
200
|
+
};
|
|
201
|
+
};
|
|
202
|
+
};
|
|
203
|
+
};
|
|
204
|
+
}, "/", "/deliveries/:id/redeliver">;
|
|
205
|
+
export type WebhookRoutes<E, D> = ReturnType<typeof webhookRoutes<E, D>>;
|
|
206
|
+
//# sourceMappingURL=webhooks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webhooks.d.ts","sourceRoot":"","sources":["../../src/http/webhooks.ts"],"names":[],"mappings":"AAuBA,OAAO,EAAE,KAAK,OAAO,EAAQ,MAAM,MAAM,CAAA;AACzC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAKvB,MAAM,MAAM,qBAAqB,GAAG,SAAS,GAAG,UAAU,GAAG,WAAW,GAAG,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AM,EAAE,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC,CAAA;CACxD,CAAA;AAID,eAAO,MAAM,oBAAoB;;;;iBAI/B,CAAA;AACF,eAAO,MAAM,oBAAoB;;;;;iBAK/B,CAAA;AACF,eAAO,MAAM,oBAAoB;;;;;;;;;;;iBAK/B,CAAA;AAqBF,wBAAgB,aAAa,CAAC,CAAC,EAAE,CAAC,EAAE,IAAI,EAAE;IACxC,QAAQ,EAAE,YAAY,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;IAC5B,KAAK,EAAE,CAAC,CAAC,EAAE,OAAO,KAAK,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAA;CAChD;;;;;;;;;;;;;;wBAzDoC,MAAM;;;wBAAN,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBAOkB,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qCAsIlE;AAGD,MAAM,MAAM,aAAa,CAAC,CAAC,EAAE,CAAC,IAAI,UAAU,CAAC,OAAO,aAAa,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { Hono } from "hono";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { ApiException } from "./errors.js";
|
|
4
|
+
import { apiDoc } from "./openapi.js";
|
|
5
|
+
import { zValidator } from "./validate.js";
|
|
6
|
+
const Id = z.object({ id: z.string().min(1) });
|
|
7
|
+
const Events = z.array(z.string().min(1).max(200)).min(1).max(100);
|
|
8
|
+
export const WebhookEndpointInput = z.object({
|
|
9
|
+
url: z.url().max(2048).describe("Where deliveries are POSTed. https on a public host."),
|
|
10
|
+
events: Events.describe('Event types to receive, or ["*"] for all.'),
|
|
11
|
+
description: z.string().max(500).optional(),
|
|
12
|
+
});
|
|
13
|
+
export const WebhookEndpointPatch = z.object({
|
|
14
|
+
url: z.url().max(2048).optional(),
|
|
15
|
+
events: Events.optional(),
|
|
16
|
+
description: z.string().max(500).nullable().optional(),
|
|
17
|
+
enabled: z.boolean().optional().describe("true turns a disabled endpoint back on."),
|
|
18
|
+
});
|
|
19
|
+
export const WebhookDeliveryQuery = z.object({
|
|
20
|
+
endpointId: z.string().optional(),
|
|
21
|
+
status: z.enum(["pending", "retrying", "delivered", "failed", "skipped"]).optional(),
|
|
22
|
+
limit: z.coerce.number().int().min(1).max(200).optional(),
|
|
23
|
+
before: z.string().optional().describe("A delivery id: older deliveries than this."),
|
|
24
|
+
});
|
|
25
|
+
const missing = (what) => new ApiException(404, `No such ${what}`, "NOT_FOUND");
|
|
26
|
+
async function mapped(p) {
|
|
27
|
+
try {
|
|
28
|
+
return await p;
|
|
29
|
+
}
|
|
30
|
+
catch (e) {
|
|
31
|
+
const err = e;
|
|
32
|
+
if (err?.name === "SignetDbError" && err.code === "BAD_VALUE")
|
|
33
|
+
throw new ApiException(400, "Validation failed", "VALIDATION_FAILED", {
|
|
34
|
+
formErrors: [],
|
|
35
|
+
fieldErrors: { url: [err.message ?? "Invalid url"] },
|
|
36
|
+
});
|
|
37
|
+
if (err?.name === "SignetDbError" && err.code === "CONFLICT")
|
|
38
|
+
throw new ApiException(409, err.message ?? "Conflict", "CONFLICT");
|
|
39
|
+
throw e;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
export function webhookRoutes(opts) {
|
|
43
|
+
const { webhooks } = opts;
|
|
44
|
+
const tags = ["Webhooks"];
|
|
45
|
+
return new Hono()
|
|
46
|
+
.get("/endpoints", apiDoc({ summary: "List webhook endpoints", tags }), async (c) => c.json(await webhooks.list(await opts.owner(c))))
|
|
47
|
+
.post("/endpoints", apiDoc({
|
|
48
|
+
summary: "Register a webhook endpoint",
|
|
49
|
+
description: "The response holds the signing secret. It is not shown again.",
|
|
50
|
+
tags,
|
|
51
|
+
}), zValidator("json", WebhookEndpointInput), async (c) => {
|
|
52
|
+
const owner = await opts.owner(c);
|
|
53
|
+
const body = c.req.valid("json");
|
|
54
|
+
const res = await mapped(webhooks.register({
|
|
55
|
+
owner,
|
|
56
|
+
url: body.url,
|
|
57
|
+
events: body.events,
|
|
58
|
+
...(body.description !== undefined ? { description: body.description } : {}),
|
|
59
|
+
}));
|
|
60
|
+
return c.json(res, 201);
|
|
61
|
+
})
|
|
62
|
+
.patch("/endpoints/:id", apiDoc({ summary: "Update or re-enable a webhook endpoint", tags }), zValidator("param", Id), zValidator("json", WebhookEndpointPatch), async (c) => {
|
|
63
|
+
const patch = Object.fromEntries(Object.entries(c.req.valid("json")).filter(([, v]) => v !== undefined));
|
|
64
|
+
const e = await mapped(webhooks.update(await opts.owner(c), c.req.valid("param").id, patch));
|
|
65
|
+
if (!e)
|
|
66
|
+
throw missing("webhook endpoint");
|
|
67
|
+
return c.json(e);
|
|
68
|
+
})
|
|
69
|
+
.delete("/endpoints/:id", apiDoc({ summary: "Delete a webhook endpoint", tags }), zValidator("param", Id), async (c) => {
|
|
70
|
+
if (!(await webhooks.remove(await opts.owner(c), c.req.valid("param").id)))
|
|
71
|
+
throw missing("webhook endpoint");
|
|
72
|
+
return c.json({ deleted: true });
|
|
73
|
+
})
|
|
74
|
+
.post("/endpoints/:id/rotate-secret", apiDoc({ summary: "Rotate a webhook endpoint's signing secret", tags }), zValidator("param", Id), async (c) => {
|
|
75
|
+
const r = await webhooks.rotateSecret(await opts.owner(c), c.req.valid("param").id);
|
|
76
|
+
if (!r)
|
|
77
|
+
throw missing("webhook endpoint");
|
|
78
|
+
return c.json(r);
|
|
79
|
+
})
|
|
80
|
+
.get("/deliveries", apiDoc({ summary: "The webhook delivery log, newest first", tags }), zValidator("query", WebhookDeliveryQuery), async (c) => {
|
|
81
|
+
const q = Object.fromEntries(Object.entries(c.req.valid("query")).filter(([, v]) => v !== undefined));
|
|
82
|
+
return c.json(await webhooks.deliveries(await opts.owner(c), q));
|
|
83
|
+
})
|
|
84
|
+
.post("/deliveries/:id/redeliver", apiDoc({ summary: "Send a delivery again with the same event id", tags }), zValidator("param", Id), async (c) => {
|
|
85
|
+
const d = await mapped(webhooks.redeliver(await opts.owner(c), c.req.valid("param").id));
|
|
86
|
+
if (!d)
|
|
87
|
+
throw missing("webhook delivery");
|
|
88
|
+
return c.json(d, 201);
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
//# sourceMappingURL=webhooks.js.map
|