@lcas58/esmi-api-types 1.0.19 → 1.0.20
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/src/routes/events/events.handlers.d.ts +2 -1
- package/dist/src/routes/events/events.handlers.js +39 -4
- package/dist/src/routes/events/events.index.d.ts +55 -3
- package/dist/src/routes/events/events.index.js +2 -1
- package/dist/src/routes/events/events.routes.d.ts +121 -1
- package/dist/src/routes/events/events.routes.js +19 -2
- package/dist/src/routes/events/schemas/event.schemas.d.ts +26 -0
- package/dist/src/routes/events/schemas/event.schemas.js +9 -0
- package/dist/src/routes/events/schemas/index.d.ts +1 -1
- package/dist/src/routes/events/schemas/index.js +1 -1
- package/package.json +1 -1
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { AppRouteHandler } from "../../lib/types.js";
|
|
2
|
-
import type { DiscoverExternalRoute, DiscoverRoute, GetOneRoute, ListRoute } from "./events.routes.js";
|
|
2
|
+
import type { DiscoverExternalRoute, DiscoverRoute, GetOneRoute, ListRoute, SaveExternalRoute } from "./events.routes.js";
|
|
3
3
|
export declare const list: AppRouteHandler<ListRoute>;
|
|
4
4
|
export declare const getOne: AppRouteHandler<GetOneRoute>;
|
|
5
5
|
export declare const discover: AppRouteHandler<DiscoverRoute>;
|
|
6
6
|
export declare const discoverExternal: AppRouteHandler<DiscoverExternalRoute>;
|
|
7
|
+
export declare const saveExternal: AppRouteHandler<SaveExternalRoute>;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { and, eq, gte, ilike, inArray, isNotNull, lte } from "drizzle-orm";
|
|
2
2
|
import * as HttpStatusCodes from "stoker/http-status-codes";
|
|
3
3
|
import * as HttpStatusPhrases from "stoker/http-status-phrases";
|
|
4
|
-
import { runExternalDiscoveryAgent } from "../../agent/runner.js";
|
|
5
|
-
import { searchLocalEvents } from "../../agent/tools.js";
|
|
4
|
+
import { agentEventsToRaw, runExternalDiscoveryAgent } from "../../agent/runner.js";
|
|
5
|
+
import { saveEvents, searchLocalEvents } from "../../agent/tools.js";
|
|
6
6
|
import { createDb } from "../../db/index.js";
|
|
7
7
|
import { event, location } from "../../db/schema/index.js";
|
|
8
8
|
export const list = async (c) => {
|
|
@@ -110,12 +110,47 @@ export const discover = async (c) => {
|
|
|
110
110
|
export const discoverExternal = async (c) => {
|
|
111
111
|
const body = c.req.valid("json");
|
|
112
112
|
const { db } = createDb(c.env);
|
|
113
|
-
const
|
|
113
|
+
const previews = await runExternalDiscoveryAgent(c.env, db, {
|
|
114
114
|
sportId: body.sportId,
|
|
115
115
|
city: body.city,
|
|
116
116
|
state: body.state,
|
|
117
117
|
from: body.from,
|
|
118
118
|
to: body.to,
|
|
119
119
|
});
|
|
120
|
-
return c.json(
|
|
120
|
+
return c.json(previews, HttpStatusCodes.OK);
|
|
121
|
+
};
|
|
122
|
+
export const saveExternal = async (c) => {
|
|
123
|
+
const { events: previews, city, state } = c.req.valid("json");
|
|
124
|
+
const { db } = createDb(c.env);
|
|
125
|
+
const rawEvents = agentEventsToRaw(previews, {
|
|
126
|
+
sportId: "",
|
|
127
|
+
city,
|
|
128
|
+
state,
|
|
129
|
+
});
|
|
130
|
+
if (rawEvents.length === 0) {
|
|
131
|
+
return c.json([], HttpStatusCodes.OK);
|
|
132
|
+
}
|
|
133
|
+
const saveResult = await saveEvents(db, rawEvents);
|
|
134
|
+
if (saveResult.savedIds.length === 0) {
|
|
135
|
+
return c.json([], HttpStatusCodes.OK);
|
|
136
|
+
}
|
|
137
|
+
const savedEvents = await db.query.event.findMany({
|
|
138
|
+
where: inArray(event.id, saveResult.savedIds),
|
|
139
|
+
with: {
|
|
140
|
+
sport: true,
|
|
141
|
+
location: true,
|
|
142
|
+
externalLink: true,
|
|
143
|
+
creator: {
|
|
144
|
+
columns: {
|
|
145
|
+
id: true,
|
|
146
|
+
name: true,
|
|
147
|
+
image: true,
|
|
148
|
+
homeCity: true,
|
|
149
|
+
homeState: true,
|
|
150
|
+
},
|
|
151
|
+
},
|
|
152
|
+
},
|
|
153
|
+
orderBy: (event, { asc }) => [asc(event.startsAt)],
|
|
154
|
+
});
|
|
155
|
+
return c.json(savedEvents, HttpStatusCodes.OK);
|
|
121
156
|
};
|
|
@@ -200,6 +200,52 @@ declare const router: import("@hono/zod-openapi").OpenAPIHono<import("../../shar
|
|
|
200
200
|
to?: string | undefined;
|
|
201
201
|
};
|
|
202
202
|
};
|
|
203
|
+
output: {
|
|
204
|
+
message: string;
|
|
205
|
+
};
|
|
206
|
+
outputFormat: "text" | "json";
|
|
207
|
+
status: 401;
|
|
208
|
+
} | {
|
|
209
|
+
input: {
|
|
210
|
+
json: {
|
|
211
|
+
sportId: string;
|
|
212
|
+
city: string;
|
|
213
|
+
state: string;
|
|
214
|
+
from?: string | undefined;
|
|
215
|
+
to?: string | undefined;
|
|
216
|
+
};
|
|
217
|
+
};
|
|
218
|
+
output: {
|
|
219
|
+
url: string;
|
|
220
|
+
title: string;
|
|
221
|
+
sport: string;
|
|
222
|
+
startsAt: string;
|
|
223
|
+
timezone: string;
|
|
224
|
+
formattedAddress: string;
|
|
225
|
+
venueName: string;
|
|
226
|
+
}[];
|
|
227
|
+
outputFormat: "text" | "json";
|
|
228
|
+
status: 200;
|
|
229
|
+
};
|
|
230
|
+
};
|
|
231
|
+
} & {
|
|
232
|
+
"/events/save-external": {
|
|
233
|
+
$post: {
|
|
234
|
+
input: {
|
|
235
|
+
json: {
|
|
236
|
+
events: {
|
|
237
|
+
url: string;
|
|
238
|
+
title: string;
|
|
239
|
+
sport: string;
|
|
240
|
+
startsAt: string;
|
|
241
|
+
timezone: string;
|
|
242
|
+
formattedAddress: string;
|
|
243
|
+
venueName: string;
|
|
244
|
+
}[];
|
|
245
|
+
city: string;
|
|
246
|
+
state: string;
|
|
247
|
+
};
|
|
248
|
+
};
|
|
203
249
|
output: {
|
|
204
250
|
metadata: any;
|
|
205
251
|
id: string;
|
|
@@ -244,11 +290,17 @@ declare const router: import("@hono/zod-openapi").OpenAPIHono<import("../../shar
|
|
|
244
290
|
} | {
|
|
245
291
|
input: {
|
|
246
292
|
json: {
|
|
247
|
-
|
|
293
|
+
events: {
|
|
294
|
+
url: string;
|
|
295
|
+
title: string;
|
|
296
|
+
sport: string;
|
|
297
|
+
startsAt: string;
|
|
298
|
+
timezone: string;
|
|
299
|
+
formattedAddress: string;
|
|
300
|
+
venueName: string;
|
|
301
|
+
}[];
|
|
248
302
|
city: string;
|
|
249
303
|
state: string;
|
|
250
|
-
from?: string | undefined;
|
|
251
|
-
to?: string | undefined;
|
|
252
304
|
};
|
|
253
305
|
};
|
|
254
306
|
output: {
|
|
@@ -5,5 +5,6 @@ const router = createRouter()
|
|
|
5
5
|
.openapi(routes.list, handlers.list)
|
|
6
6
|
.openapi(routes.getOne, handlers.getOne)
|
|
7
7
|
.openapi(routes.discover, handlers.discover)
|
|
8
|
-
.openapi(routes.discoverExternal, handlers.discoverExternal)
|
|
8
|
+
.openapi(routes.discoverExternal, handlers.discoverExternal)
|
|
9
|
+
.openapi(routes.saveExternal, handlers.saveExternal);
|
|
9
10
|
export default router;
|
|
@@ -953,6 +953,125 @@ export declare const discoverExternal: {
|
|
|
953
953
|
description: string;
|
|
954
954
|
};
|
|
955
955
|
};
|
|
956
|
+
responses: {
|
|
957
|
+
200: {
|
|
958
|
+
content: {
|
|
959
|
+
"application/json": {
|
|
960
|
+
schema: z.ZodArray<z.ZodObject<{
|
|
961
|
+
title: z.ZodString;
|
|
962
|
+
sport: z.ZodString;
|
|
963
|
+
startsAt: z.ZodString;
|
|
964
|
+
timezone: z.ZodString;
|
|
965
|
+
url: z.ZodString;
|
|
966
|
+
venueName: z.ZodString;
|
|
967
|
+
formattedAddress: z.ZodString;
|
|
968
|
+
}, "strip", z.ZodTypeAny, {
|
|
969
|
+
url: string;
|
|
970
|
+
title: string;
|
|
971
|
+
sport: string;
|
|
972
|
+
startsAt: string;
|
|
973
|
+
timezone: string;
|
|
974
|
+
formattedAddress: string;
|
|
975
|
+
venueName: string;
|
|
976
|
+
}, {
|
|
977
|
+
url: string;
|
|
978
|
+
title: string;
|
|
979
|
+
sport: string;
|
|
980
|
+
startsAt: string;
|
|
981
|
+
timezone: string;
|
|
982
|
+
formattedAddress: string;
|
|
983
|
+
venueName: string;
|
|
984
|
+
}>, "many">;
|
|
985
|
+
};
|
|
986
|
+
};
|
|
987
|
+
description: string;
|
|
988
|
+
};
|
|
989
|
+
401: {
|
|
990
|
+
content: {
|
|
991
|
+
"application/json": {
|
|
992
|
+
schema: z.ZodObject<{
|
|
993
|
+
message: z.ZodString;
|
|
994
|
+
}, "strip", z.ZodTypeAny, {
|
|
995
|
+
message: string;
|
|
996
|
+
}, {
|
|
997
|
+
message: string;
|
|
998
|
+
}>;
|
|
999
|
+
};
|
|
1000
|
+
};
|
|
1001
|
+
description: string;
|
|
1002
|
+
};
|
|
1003
|
+
};
|
|
1004
|
+
} & {
|
|
1005
|
+
getRoutingPath(): "/events/discover/external";
|
|
1006
|
+
};
|
|
1007
|
+
export declare const saveExternal: {
|
|
1008
|
+
path: "/events/save-external";
|
|
1009
|
+
method: "post";
|
|
1010
|
+
tags: string[];
|
|
1011
|
+
middleware: [import("hono").MiddlewareHandler];
|
|
1012
|
+
request: {
|
|
1013
|
+
body: {
|
|
1014
|
+
required: boolean;
|
|
1015
|
+
content: {
|
|
1016
|
+
"application/json": {
|
|
1017
|
+
schema: z.ZodObject<{
|
|
1018
|
+
events: z.ZodArray<z.ZodObject<{
|
|
1019
|
+
title: z.ZodString;
|
|
1020
|
+
sport: z.ZodString;
|
|
1021
|
+
startsAt: z.ZodString;
|
|
1022
|
+
timezone: z.ZodString;
|
|
1023
|
+
url: z.ZodString;
|
|
1024
|
+
venueName: z.ZodString;
|
|
1025
|
+
formattedAddress: z.ZodString;
|
|
1026
|
+
}, "strip", z.ZodTypeAny, {
|
|
1027
|
+
url: string;
|
|
1028
|
+
title: string;
|
|
1029
|
+
sport: string;
|
|
1030
|
+
startsAt: string;
|
|
1031
|
+
timezone: string;
|
|
1032
|
+
formattedAddress: string;
|
|
1033
|
+
venueName: string;
|
|
1034
|
+
}, {
|
|
1035
|
+
url: string;
|
|
1036
|
+
title: string;
|
|
1037
|
+
sport: string;
|
|
1038
|
+
startsAt: string;
|
|
1039
|
+
timezone: string;
|
|
1040
|
+
formattedAddress: string;
|
|
1041
|
+
venueName: string;
|
|
1042
|
+
}>, "many">;
|
|
1043
|
+
city: z.ZodString;
|
|
1044
|
+
state: z.ZodString;
|
|
1045
|
+
}, "strip", z.ZodTypeAny, {
|
|
1046
|
+
events: {
|
|
1047
|
+
url: string;
|
|
1048
|
+
title: string;
|
|
1049
|
+
sport: string;
|
|
1050
|
+
startsAt: string;
|
|
1051
|
+
timezone: string;
|
|
1052
|
+
formattedAddress: string;
|
|
1053
|
+
venueName: string;
|
|
1054
|
+
}[];
|
|
1055
|
+
city: string;
|
|
1056
|
+
state: string;
|
|
1057
|
+
}, {
|
|
1058
|
+
events: {
|
|
1059
|
+
url: string;
|
|
1060
|
+
title: string;
|
|
1061
|
+
sport: string;
|
|
1062
|
+
startsAt: string;
|
|
1063
|
+
timezone: string;
|
|
1064
|
+
formattedAddress: string;
|
|
1065
|
+
venueName: string;
|
|
1066
|
+
}[];
|
|
1067
|
+
city: string;
|
|
1068
|
+
state: string;
|
|
1069
|
+
}>;
|
|
1070
|
+
};
|
|
1071
|
+
};
|
|
1072
|
+
description: string;
|
|
1073
|
+
};
|
|
1074
|
+
};
|
|
956
1075
|
responses: {
|
|
957
1076
|
200: {
|
|
958
1077
|
content: {
|
|
@@ -1229,9 +1348,10 @@ export declare const discoverExternal: {
|
|
|
1229
1348
|
};
|
|
1230
1349
|
};
|
|
1231
1350
|
} & {
|
|
1232
|
-
getRoutingPath(): "/events/
|
|
1351
|
+
getRoutingPath(): "/events/save-external";
|
|
1233
1352
|
};
|
|
1234
1353
|
export type ListRoute = typeof list;
|
|
1235
1354
|
export type GetOneRoute = typeof getOne;
|
|
1236
1355
|
export type DiscoverRoute = typeof discover;
|
|
1237
1356
|
export type DiscoverExternalRoute = typeof discoverExternal;
|
|
1357
|
+
export type SaveExternalRoute = typeof saveExternal;
|
|
@@ -3,7 +3,7 @@ import * as HttpStatusCodes from "stoker/http-status-codes";
|
|
|
3
3
|
import { jsonContent, jsonContentRequired } from "stoker/openapi/helpers";
|
|
4
4
|
import { notFoundSchema, unauthorizedSchema } from "../../lib/constants.js";
|
|
5
5
|
import { isAuth } from "../../middlewares/is-auth.js";
|
|
6
|
-
import { eventWithRelationsSchema, listEventsQuerySchema } from "./schemas/index.js";
|
|
6
|
+
import { eventWithRelationsSchema, externalEventPreviewSchema, listEventsQuerySchema } from "./schemas/index.js";
|
|
7
7
|
export const list = createRoute({
|
|
8
8
|
path: "/events",
|
|
9
9
|
method: "get",
|
|
@@ -58,7 +58,24 @@ export const discoverExternal = createRoute({
|
|
|
58
58
|
body: jsonContentRequired(discoverRequestSchema, "External event discovery criteria"),
|
|
59
59
|
},
|
|
60
60
|
responses: {
|
|
61
|
-
[HttpStatusCodes.OK]: jsonContent(z.array(
|
|
61
|
+
[HttpStatusCodes.OK]: jsonContent(z.array(externalEventPreviewSchema), "External event previews (not yet saved)"),
|
|
62
|
+
[HttpStatusCodes.UNAUTHORIZED]: jsonContent(unauthorizedSchema, "Unauthorized"),
|
|
63
|
+
},
|
|
64
|
+
});
|
|
65
|
+
export const saveExternal = createRoute({
|
|
66
|
+
path: "/events/save-external",
|
|
67
|
+
method: "post",
|
|
68
|
+
tags: ["Events"],
|
|
69
|
+
middleware: [isAuth()],
|
|
70
|
+
request: {
|
|
71
|
+
body: jsonContentRequired(z.object({
|
|
72
|
+
events: z.array(externalEventPreviewSchema),
|
|
73
|
+
city: z.string().min(1),
|
|
74
|
+
state: z.string().min(1),
|
|
75
|
+
}), "Selected event previews to save"),
|
|
76
|
+
},
|
|
77
|
+
responses: {
|
|
78
|
+
[HttpStatusCodes.OK]: jsonContent(z.array(eventWithRelationsSchema), "Saved events with full relations"),
|
|
62
79
|
[HttpStatusCodes.UNAUTHORIZED]: jsonContent(unauthorizedSchema, "Unauthorized"),
|
|
63
80
|
},
|
|
64
81
|
});
|
|
@@ -279,5 +279,31 @@ export declare const listEventsQuerySchema: z.ZodObject<{
|
|
|
279
279
|
limit?: number | undefined;
|
|
280
280
|
offset?: number | undefined;
|
|
281
281
|
}>;
|
|
282
|
+
export declare const externalEventPreviewSchema: z.ZodObject<{
|
|
283
|
+
title: z.ZodString;
|
|
284
|
+
sport: z.ZodString;
|
|
285
|
+
startsAt: z.ZodString;
|
|
286
|
+
timezone: z.ZodString;
|
|
287
|
+
url: z.ZodString;
|
|
288
|
+
venueName: z.ZodString;
|
|
289
|
+
formattedAddress: z.ZodString;
|
|
290
|
+
}, "strip", z.ZodTypeAny, {
|
|
291
|
+
url: string;
|
|
292
|
+
title: string;
|
|
293
|
+
sport: string;
|
|
294
|
+
startsAt: string;
|
|
295
|
+
timezone: string;
|
|
296
|
+
formattedAddress: string;
|
|
297
|
+
venueName: string;
|
|
298
|
+
}, {
|
|
299
|
+
url: string;
|
|
300
|
+
title: string;
|
|
301
|
+
sport: string;
|
|
302
|
+
startsAt: string;
|
|
303
|
+
timezone: string;
|
|
304
|
+
formattedAddress: string;
|
|
305
|
+
venueName: string;
|
|
306
|
+
}>;
|
|
307
|
+
export type ExternalEventPreview = z.infer<typeof externalEventPreviewSchema>;
|
|
282
308
|
export type EventWithRelations = z.infer<typeof eventWithRelationsSchema>;
|
|
283
309
|
export type ListEventsQuery = z.infer<typeof listEventsQuerySchema>;
|
|
@@ -36,3 +36,12 @@ export const listEventsQuerySchema = z.object({
|
|
|
36
36
|
limit: z.coerce.number().min(1).max(100).optional().default(20),
|
|
37
37
|
offset: z.coerce.number().min(0).optional().default(0),
|
|
38
38
|
});
|
|
39
|
+
export const externalEventPreviewSchema = z.object({
|
|
40
|
+
title: z.string(),
|
|
41
|
+
sport: z.string(),
|
|
42
|
+
startsAt: z.string(),
|
|
43
|
+
timezone: z.string(),
|
|
44
|
+
url: z.string(),
|
|
45
|
+
venueName: z.string(),
|
|
46
|
+
formattedAddress: z.string(),
|
|
47
|
+
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { type EventWithRelations, eventWithRelationsSchema, type ListEventsQuery, listEventsQuerySchema, } from "./event.schemas.js";
|
|
1
|
+
export { type EventWithRelations, eventWithRelationsSchema, type ExternalEventPreview, externalEventPreviewSchema, type ListEventsQuery, listEventsQuerySchema, } from "./event.schemas.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { eventWithRelationsSchema, listEventsQuerySchema, } from "./event.schemas.js";
|
|
1
|
+
export { eventWithRelationsSchema, externalEventPreviewSchema, listEventsQuerySchema, } from "./event.schemas.js";
|