@lcas58/esmi-api-types 1.0.19 → 1.0.21

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.
@@ -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 events = await runExternalDiscoveryAgent(c.env, db, {
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(events, HttpStatusCodes.OK);
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,58 @@ 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
+ id: string;
221
+ title: string;
222
+ sport: string;
223
+ startsAt: string;
224
+ timezone: string;
225
+ formattedAddress: string;
226
+ venueName: string;
227
+ description?: string | undefined;
228
+ endsAt?: string | undefined;
229
+ }[];
230
+ outputFormat: "text" | "json";
231
+ status: 200;
232
+ };
233
+ };
234
+ } & {
235
+ "/events/save-external": {
236
+ $post: {
237
+ input: {
238
+ json: {
239
+ events: {
240
+ url: string;
241
+ id: string;
242
+ title: string;
243
+ sport: string;
244
+ startsAt: string;
245
+ timezone: string;
246
+ formattedAddress: string;
247
+ venueName: string;
248
+ description?: string | undefined;
249
+ endsAt?: string | undefined;
250
+ }[];
251
+ city: string;
252
+ state: string;
253
+ };
254
+ };
203
255
  output: {
204
256
  metadata: any;
205
257
  id: string;
@@ -244,11 +296,20 @@ declare const router: import("@hono/zod-openapi").OpenAPIHono<import("../../shar
244
296
  } | {
245
297
  input: {
246
298
  json: {
247
- sportId: string;
299
+ events: {
300
+ url: string;
301
+ id: string;
302
+ title: string;
303
+ sport: string;
304
+ startsAt: string;
305
+ timezone: string;
306
+ formattedAddress: string;
307
+ venueName: string;
308
+ description?: string | undefined;
309
+ endsAt?: string | undefined;
310
+ }[];
248
311
  city: string;
249
312
  state: string;
250
- from?: string | undefined;
251
- to?: string | undefined;
252
313
  };
253
314
  };
254
315
  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,149 @@ 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
+ id: z.ZodString;
962
+ title: z.ZodString;
963
+ sport: z.ZodString;
964
+ startsAt: z.ZodString;
965
+ timezone: z.ZodString;
966
+ url: z.ZodString;
967
+ venueName: z.ZodString;
968
+ formattedAddress: z.ZodString;
969
+ description: z.ZodOptional<z.ZodString>;
970
+ endsAt: z.ZodOptional<z.ZodString>;
971
+ }, "strip", z.ZodTypeAny, {
972
+ url: string;
973
+ id: string;
974
+ title: string;
975
+ sport: string;
976
+ startsAt: string;
977
+ timezone: string;
978
+ formattedAddress: string;
979
+ venueName: string;
980
+ description?: string | undefined;
981
+ endsAt?: string | undefined;
982
+ }, {
983
+ url: string;
984
+ id: string;
985
+ title: string;
986
+ sport: string;
987
+ startsAt: string;
988
+ timezone: string;
989
+ formattedAddress: string;
990
+ venueName: string;
991
+ description?: string | undefined;
992
+ endsAt?: string | undefined;
993
+ }>, "many">;
994
+ };
995
+ };
996
+ description: string;
997
+ };
998
+ 401: {
999
+ content: {
1000
+ "application/json": {
1001
+ schema: z.ZodObject<{
1002
+ message: z.ZodString;
1003
+ }, "strip", z.ZodTypeAny, {
1004
+ message: string;
1005
+ }, {
1006
+ message: string;
1007
+ }>;
1008
+ };
1009
+ };
1010
+ description: string;
1011
+ };
1012
+ };
1013
+ } & {
1014
+ getRoutingPath(): "/events/discover/external";
1015
+ };
1016
+ export declare const saveExternal: {
1017
+ path: "/events/save-external";
1018
+ method: "post";
1019
+ tags: string[];
1020
+ middleware: [import("hono").MiddlewareHandler];
1021
+ request: {
1022
+ body: {
1023
+ required: boolean;
1024
+ content: {
1025
+ "application/json": {
1026
+ schema: z.ZodObject<{
1027
+ events: z.ZodArray<z.ZodObject<{
1028
+ id: z.ZodString;
1029
+ title: z.ZodString;
1030
+ sport: z.ZodString;
1031
+ startsAt: z.ZodString;
1032
+ timezone: z.ZodString;
1033
+ url: z.ZodString;
1034
+ venueName: z.ZodString;
1035
+ formattedAddress: z.ZodString;
1036
+ description: z.ZodOptional<z.ZodString>;
1037
+ endsAt: z.ZodOptional<z.ZodString>;
1038
+ }, "strip", z.ZodTypeAny, {
1039
+ url: string;
1040
+ id: string;
1041
+ title: string;
1042
+ sport: string;
1043
+ startsAt: string;
1044
+ timezone: string;
1045
+ formattedAddress: string;
1046
+ venueName: string;
1047
+ description?: string | undefined;
1048
+ endsAt?: string | undefined;
1049
+ }, {
1050
+ url: string;
1051
+ id: string;
1052
+ title: string;
1053
+ sport: string;
1054
+ startsAt: string;
1055
+ timezone: string;
1056
+ formattedAddress: string;
1057
+ venueName: string;
1058
+ description?: string | undefined;
1059
+ endsAt?: string | undefined;
1060
+ }>, "many">;
1061
+ city: z.ZodString;
1062
+ state: z.ZodString;
1063
+ }, "strip", z.ZodTypeAny, {
1064
+ events: {
1065
+ url: string;
1066
+ id: string;
1067
+ title: string;
1068
+ sport: string;
1069
+ startsAt: string;
1070
+ timezone: string;
1071
+ formattedAddress: string;
1072
+ venueName: string;
1073
+ description?: string | undefined;
1074
+ endsAt?: string | undefined;
1075
+ }[];
1076
+ city: string;
1077
+ state: string;
1078
+ }, {
1079
+ events: {
1080
+ url: string;
1081
+ id: string;
1082
+ title: string;
1083
+ sport: string;
1084
+ startsAt: string;
1085
+ timezone: string;
1086
+ formattedAddress: string;
1087
+ venueName: string;
1088
+ description?: string | undefined;
1089
+ endsAt?: string | undefined;
1090
+ }[];
1091
+ city: string;
1092
+ state: string;
1093
+ }>;
1094
+ };
1095
+ };
1096
+ description: string;
1097
+ };
1098
+ };
956
1099
  responses: {
957
1100
  200: {
958
1101
  content: {
@@ -1229,9 +1372,10 @@ export declare const discoverExternal: {
1229
1372
  };
1230
1373
  };
1231
1374
  } & {
1232
- getRoutingPath(): "/events/discover/external";
1375
+ getRoutingPath(): "/events/save-external";
1233
1376
  };
1234
1377
  export type ListRoute = typeof list;
1235
1378
  export type GetOneRoute = typeof getOne;
1236
1379
  export type DiscoverRoute = typeof discover;
1237
1380
  export type DiscoverExternalRoute = typeof discoverExternal;
1381
+ 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(eventWithRelationsSchema), "Externally discovered events"),
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,40 @@ 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
+ id: z.ZodString;
284
+ title: z.ZodString;
285
+ sport: z.ZodString;
286
+ startsAt: z.ZodString;
287
+ timezone: z.ZodString;
288
+ url: z.ZodString;
289
+ venueName: z.ZodString;
290
+ formattedAddress: z.ZodString;
291
+ description: z.ZodOptional<z.ZodString>;
292
+ endsAt: z.ZodOptional<z.ZodString>;
293
+ }, "strip", z.ZodTypeAny, {
294
+ url: string;
295
+ id: string;
296
+ title: string;
297
+ sport: string;
298
+ startsAt: string;
299
+ timezone: string;
300
+ formattedAddress: string;
301
+ venueName: string;
302
+ description?: string | undefined;
303
+ endsAt?: string | undefined;
304
+ }, {
305
+ url: string;
306
+ id: string;
307
+ title: string;
308
+ sport: string;
309
+ startsAt: string;
310
+ timezone: string;
311
+ formattedAddress: string;
312
+ venueName: string;
313
+ description?: string | undefined;
314
+ endsAt?: string | undefined;
315
+ }>;
316
+ export type ExternalEventPreview = z.infer<typeof externalEventPreviewSchema>;
282
317
  export type EventWithRelations = z.infer<typeof eventWithRelationsSchema>;
283
318
  export type ListEventsQuery = z.infer<typeof listEventsQuerySchema>;
@@ -36,3 +36,15 @@ 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
+ id: z.string(),
41
+ title: z.string(),
42
+ sport: z.string(),
43
+ startsAt: z.string(),
44
+ timezone: z.string(),
45
+ url: z.string(),
46
+ venueName: z.string(),
47
+ formattedAddress: z.string(),
48
+ description: z.string().optional(),
49
+ endsAt: z.string().optional(),
50
+ });
@@ -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";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@lcas58/esmi-api-types",
3
3
  "type": "module",
4
- "version": "1.0.19",
4
+ "version": "1.0.21",
5
5
  "license": "MIT",
6
6
  "exports": {
7
7
  ".": {