@voyant-travel/distribution 0.126.2 → 0.127.1

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.
Files changed (45) hide show
  1. package/dist/booking-extension.d.ts +6 -6
  2. package/dist/booking-extension.js +1 -1
  3. package/dist/external-refs/index.js +1 -1
  4. package/dist/external-refs/routes.d.ts +200 -39
  5. package/dist/external-refs/routes.d.ts.map +1 -1
  6. package/dist/external-refs/routes.js +160 -41
  7. package/dist/external-refs/service.d.ts +6 -6
  8. package/dist/external-refs/validation.d.ts +2 -2
  9. package/dist/index.js +1 -1
  10. package/dist/routes/batch.d.ts +5 -5
  11. package/dist/routes/inventory.d.ts +565 -142
  12. package/dist/routes/inventory.d.ts.map +1 -1
  13. package/dist/routes/inventory.js +395 -104
  14. package/dist/routes/openapi-schemas.d.ts +482 -0
  15. package/dist/routes/openapi-schemas.d.ts.map +1 -0
  16. package/dist/routes/openapi-schemas.js +377 -0
  17. package/dist/routes/settlements.d.ts +1427 -498
  18. package/dist/routes/settlements.d.ts.map +1 -1
  19. package/dist/routes/settlements.js +952 -262
  20. package/dist/routes.d.ts +4007 -1698
  21. package/dist/routes.d.ts.map +1 -1
  22. package/dist/routes.js +831 -253
  23. package/dist/schema-core.d.ts +5 -5
  24. package/dist/schema-finance.d.ts +3 -3
  25. package/dist/schema-inventory.d.ts +1 -1
  26. package/dist/service/channels.d.ts +21 -21
  27. package/dist/service/commercial.d.ts +29 -29
  28. package/dist/service/inventory.d.ts +4 -4
  29. package/dist/service/settlement-policies.d.ts +16 -16
  30. package/dist/service/settlements.d.ts +31 -31
  31. package/dist/service.d.ts +101 -101
  32. package/dist/suppliers/index.d.ts.map +1 -1
  33. package/dist/suppliers/index.js +2 -3
  34. package/dist/suppliers/routes-contract.test.d.ts +2 -0
  35. package/dist/suppliers/routes-contract.test.d.ts.map +1 -0
  36. package/dist/suppliers/routes-contract.test.js +205 -0
  37. package/dist/suppliers/routes.d.ts +1296 -456
  38. package/dist/suppliers/routes.d.ts.map +1 -1
  39. package/dist/suppliers/routes.js +997 -249
  40. package/dist/suppliers/schema.d.ts +2 -2
  41. package/dist/suppliers/service-core.d.ts +8 -8
  42. package/dist/suppliers/service-identity.d.ts +25 -25
  43. package/dist/suppliers/service-operations.d.ts +20 -20
  44. package/dist/validation.d.ts +61 -61
  45. package/package.json +9 -8
@@ -79,7 +79,7 @@ export declare const bookingDistributionDetails: import("drizzle-orm/pg-core").P
79
79
  tableName: "booking_distribution_details";
80
80
  dataType: "string";
81
81
  columnType: "PgEnumColumn";
82
- data: "split" | "operator" | "channel";
82
+ data: "operator" | "channel" | "split";
83
83
  driverParam: string;
84
84
  notNull: true;
85
85
  hasDefault: true;
@@ -135,9 +135,9 @@ declare const bookingDistributionDetailSchema: z.ZodObject<{
135
135
  sourceChannelId: z.ZodNullable<z.ZodOptional<z.ZodString>>;
136
136
  fxRateSetId: z.ZodNullable<z.ZodOptional<z.ZodString>>;
137
137
  paymentOwner: z.ZodDefault<z.ZodEnum<{
138
- split: "split";
139
138
  operator: "operator";
140
139
  channel: "channel";
140
+ split: "split";
141
141
  }>>;
142
142
  }, z.core.$strip>;
143
143
  export declare const bookingDistributionExtensionService: {
@@ -146,18 +146,18 @@ export declare const bookingDistributionExtensionService: {
146
146
  marketId: string | null;
147
147
  sourceChannelId: string | null;
148
148
  fxRateSetId: string | null;
149
- paymentOwner: "split" | "operator" | "channel";
149
+ paymentOwner: "operator" | "channel" | "split";
150
150
  createdAt: Date;
151
151
  updatedAt: Date;
152
152
  } | null>;
153
153
  upsert(db: PostgresJsDatabase, bookingId: string, data: z.infer<typeof bookingDistributionDetailSchema>): Promise<{
154
- createdAt: Date;
155
- updatedAt: Date;
156
154
  bookingId: string;
157
155
  marketId: string | null;
158
156
  sourceChannelId: string | null;
159
157
  fxRateSetId: string | null;
160
- paymentOwner: "split" | "operator" | "channel";
158
+ paymentOwner: "operator" | "channel" | "split";
159
+ createdAt: Date;
160
+ updatedAt: Date;
161
161
  } | null>;
162
162
  remove(db: PostgresJsDatabase, bookingId: string): Promise<{
163
163
  bookingId: string;
@@ -98,5 +98,5 @@ const distributionBookingExtensionDef = {
98
98
  };
99
99
  export const distributionBookingExtension = {
100
100
  extension: distributionBookingExtensionDef,
101
- routes: bookingDistributionExtensionRoutes,
101
+ adminRoutes: bookingDistributionExtensionRoutes,
102
102
  };
@@ -5,7 +5,7 @@ export const externalRefsModule = {
5
5
  };
6
6
  export const externalRefsHonoModule = {
7
7
  module: externalRefsModule,
8
- routes: externalRefsRoutes,
8
+ adminRoutes: externalRefsRoutes,
9
9
  };
10
10
  export { externalRefStatusEnum, externalRefs } from "./schema.js";
11
11
  export { externalRefListQuerySchema, externalRefStatusSchema, insertExternalRefForEntitySchema, insertExternalRefSchema, selectExternalRefSchema, updateExternalRefSchema, } from "./validation.js";
@@ -1,3 +1,18 @@
1
+ /**
2
+ * External-reference admin routes — the cross-system id mapping registry
3
+ * (`external_refs`): list/create/get/patch/delete plus the entity-scoped
4
+ * list/create legs. Migrated to `@hono/zod-openapi` for the OpenAPI admin
5
+ * backfill (voyant#2114 — distribution sub-batch) via the same NON-BREAKING
6
+ * dual-mount: the exported `externalRefsRoutes` `OpenAPIHono` instance is
7
+ * mounted by the framework on BOTH the legacy `/v1/external-refs/*` surface (the
8
+ * dashboard still calls those paths) AND the documented staff surface at
9
+ * `/v1/admin/external-refs/*` (see `external-refs/index.ts`). Request schemas
10
+ * reuse the exported `validation.ts` schemas; the response row schema is
11
+ * authored from the Drizzle `$inferSelect` shape (§17 timestamps → strings).
12
+ * Handlers read `c.req.valid(...)`; the entity-scoped list still re-parses the
13
+ * merged params via the full list-query schema.
14
+ */
15
+ import { OpenAPIHono } from "@hono/zod-openapi";
1
16
  import type { PostgresJsDatabase } from "drizzle-orm/postgres-js";
2
17
  type Env = {
3
18
  Variables: {
@@ -5,10 +20,22 @@ type Env = {
5
20
  userId?: string;
6
21
  };
7
22
  };
8
- export declare const externalRefsRoutes: import("hono/hono-base").HonoBase<Env, {
23
+ export declare const externalRefsRoutes: OpenAPIHono<Env, {
9
24
  "/refs": {
10
25
  $get: {
11
- input: {};
26
+ input: {
27
+ query: {
28
+ limit?: unknown;
29
+ offset?: unknown;
30
+ entityType?: string | undefined;
31
+ entityId?: string | undefined;
32
+ sourceSystem?: string | undefined;
33
+ objectType?: string | undefined;
34
+ namespace?: string | undefined;
35
+ status?: "active" | "inactive" | "archived" | undefined;
36
+ search?: string | undefined;
37
+ };
38
+ };
12
39
  output: {
13
40
  data: {
14
41
  id: string;
@@ -33,51 +60,75 @@ export declare const externalRefsRoutes: import("hono/hono-base").HonoBase<Env,
33
60
  offset: number;
34
61
  };
35
62
  outputFormat: "json";
36
- status: import("hono/utils/http-status").ContentfulStatusCode;
63
+ status: 200;
37
64
  };
38
65
  };
39
66
  } & {
40
67
  "/refs": {
41
68
  $post: {
42
- input: {};
69
+ input: {
70
+ json: {
71
+ entityType: string;
72
+ entityId: string;
73
+ sourceSystem: string;
74
+ objectType: string;
75
+ externalId: string;
76
+ namespace?: string | undefined;
77
+ externalParentId?: string | null | undefined;
78
+ isPrimary?: boolean | undefined;
79
+ status?: "active" | "inactive" | "archived" | undefined;
80
+ lastSyncedAt?: string | null | undefined;
81
+ metadata?: Record<string, unknown> | null | undefined;
82
+ };
83
+ };
43
84
  output: {
44
85
  data: {
86
+ id: string;
87
+ entityType: string;
88
+ entityId: string;
89
+ sourceSystem: string;
90
+ objectType: string;
45
91
  namespace: string;
92
+ externalId: string;
93
+ externalParentId: string | null;
94
+ isPrimary: boolean;
95
+ status: "active" | "inactive" | "archived";
96
+ lastSyncedAt: string | null;
46
97
  metadata: {
47
98
  [x: string]: import("hono/utils/types").JSONValue;
48
99
  } | null;
49
- status: "active" | "inactive" | "archived";
50
- id: string;
51
100
  createdAt: string;
52
101
  updatedAt: string;
102
+ };
103
+ };
104
+ outputFormat: "json";
105
+ status: 201;
106
+ } | {
107
+ input: {
108
+ json: {
53
109
  entityType: string;
54
110
  entityId: string;
55
- isPrimary: boolean;
56
- lastSyncedAt: string | null;
57
111
  sourceSystem: string;
58
112
  objectType: string;
59
113
  externalId: string;
60
- externalParentId: string | null;
61
- } | null;
114
+ namespace?: string | undefined;
115
+ externalParentId?: string | null | undefined;
116
+ isPrimary?: boolean | undefined;
117
+ status?: "active" | "inactive" | "archived" | undefined;
118
+ lastSyncedAt?: string | null | undefined;
119
+ metadata?: Record<string, unknown> | null | undefined;
120
+ };
121
+ };
122
+ output: {
123
+ error: string;
62
124
  };
63
125
  outputFormat: "json";
64
- status: 201;
126
+ status: 400;
65
127
  };
66
128
  };
67
129
  } & {
68
130
  "/refs/:id": {
69
131
  $get: {
70
- input: {
71
- param: {
72
- id: string;
73
- };
74
- };
75
- output: {
76
- error: string;
77
- };
78
- outputFormat: "json";
79
- status: 404;
80
- } | {
81
132
  input: {
82
133
  param: {
83
134
  id: string;
@@ -104,7 +155,18 @@ export declare const externalRefsRoutes: import("hono/hono-base").HonoBase<Env,
104
155
  };
105
156
  };
106
157
  outputFormat: "json";
107
- status: import("hono/utils/http-status").ContentfulStatusCode;
158
+ status: 200;
159
+ } | {
160
+ input: {
161
+ param: {
162
+ id: string;
163
+ };
164
+ };
165
+ output: {
166
+ error: string;
167
+ };
168
+ outputFormat: "json";
169
+ status: 404;
108
170
  };
109
171
  };
110
172
  } & {
@@ -114,6 +176,45 @@ export declare const externalRefsRoutes: import("hono/hono-base").HonoBase<Env,
114
176
  param: {
115
177
  id: string;
116
178
  };
179
+ } & {
180
+ json: {
181
+ entityType?: string | undefined;
182
+ entityId?: string | undefined;
183
+ sourceSystem?: string | undefined;
184
+ objectType?: string | undefined;
185
+ namespace?: string | undefined;
186
+ externalId?: string | undefined;
187
+ externalParentId?: string | null | undefined;
188
+ isPrimary?: boolean | undefined;
189
+ status?: "active" | "inactive" | "archived" | undefined;
190
+ lastSyncedAt?: string | null | undefined;
191
+ metadata?: Record<string, unknown> | null | undefined;
192
+ };
193
+ };
194
+ output: {
195
+ error: string;
196
+ };
197
+ outputFormat: "json";
198
+ status: 400;
199
+ } | {
200
+ input: {
201
+ param: {
202
+ id: string;
203
+ };
204
+ } & {
205
+ json: {
206
+ entityType?: string | undefined;
207
+ entityId?: string | undefined;
208
+ sourceSystem?: string | undefined;
209
+ objectType?: string | undefined;
210
+ namespace?: string | undefined;
211
+ externalId?: string | undefined;
212
+ externalParentId?: string | null | undefined;
213
+ isPrimary?: boolean | undefined;
214
+ status?: "active" | "inactive" | "archived" | undefined;
215
+ lastSyncedAt?: string | null | undefined;
216
+ metadata?: Record<string, unknown> | null | undefined;
217
+ };
117
218
  };
118
219
  output: {
119
220
  error: string;
@@ -125,6 +226,20 @@ export declare const externalRefsRoutes: import("hono/hono-base").HonoBase<Env,
125
226
  param: {
126
227
  id: string;
127
228
  };
229
+ } & {
230
+ json: {
231
+ entityType?: string | undefined;
232
+ entityId?: string | undefined;
233
+ sourceSystem?: string | undefined;
234
+ objectType?: string | undefined;
235
+ namespace?: string | undefined;
236
+ externalId?: string | undefined;
237
+ externalParentId?: string | null | undefined;
238
+ isPrimary?: boolean | undefined;
239
+ status?: "active" | "inactive" | "archived" | undefined;
240
+ lastSyncedAt?: string | null | undefined;
241
+ metadata?: Record<string, unknown> | null | undefined;
242
+ };
128
243
  };
129
244
  output: {
130
245
  data: {
@@ -147,7 +262,7 @@ export declare const externalRefsRoutes: import("hono/hono-base").HonoBase<Env,
147
262
  };
148
263
  };
149
264
  outputFormat: "json";
150
- status: import("hono/utils/http-status").ContentfulStatusCode;
265
+ status: 200;
151
266
  };
152
267
  };
153
268
  } & {
@@ -173,7 +288,7 @@ export declare const externalRefsRoutes: import("hono/hono-base").HonoBase<Env,
173
288
  success: true;
174
289
  };
175
290
  outputFormat: "json";
176
- status: import("hono/utils/http-status").ContentfulStatusCode;
291
+ status: 200;
177
292
  };
178
293
  };
179
294
  } & {
@@ -182,9 +297,20 @@ export declare const externalRefsRoutes: import("hono/hono-base").HonoBase<Env,
182
297
  input: {
183
298
  param: {
184
299
  entityType: string;
185
- } & {
186
300
  entityId: string;
187
301
  };
302
+ } & {
303
+ query: {
304
+ limit?: unknown;
305
+ offset?: unknown;
306
+ entityType?: string | undefined;
307
+ entityId?: string | undefined;
308
+ sourceSystem?: string | undefined;
309
+ objectType?: string | undefined;
310
+ namespace?: string | undefined;
311
+ status?: "active" | "inactive" | "archived" | undefined;
312
+ search?: string | undefined;
313
+ };
188
314
  };
189
315
  output: {
190
316
  data: {
@@ -210,7 +336,7 @@ export declare const externalRefsRoutes: import("hono/hono-base").HonoBase<Env,
210
336
  offset: number;
211
337
  };
212
338
  outputFormat: "json";
213
- status: import("hono/utils/http-status").ContentfulStatusCode;
339
+ status: 200;
214
340
  };
215
341
  };
216
342
  } & {
@@ -219,35 +345,70 @@ export declare const externalRefsRoutes: import("hono/hono-base").HonoBase<Env,
219
345
  input: {
220
346
  param: {
221
347
  entityType: string;
222
- } & {
223
348
  entityId: string;
224
349
  };
350
+ } & {
351
+ json: {
352
+ sourceSystem: string;
353
+ objectType: string;
354
+ externalId: string;
355
+ metadata?: Record<string, unknown> | null | undefined;
356
+ status?: "active" | "inactive" | "archived" | undefined;
357
+ lastSyncedAt?: string | null | undefined;
358
+ namespace?: string | undefined;
359
+ externalParentId?: string | null | undefined;
360
+ isPrimary?: boolean | undefined;
361
+ };
362
+ };
363
+ output: {
364
+ error: string;
365
+ };
366
+ outputFormat: "json";
367
+ status: 400;
368
+ } | {
369
+ input: {
370
+ param: {
371
+ entityType: string;
372
+ entityId: string;
373
+ };
374
+ } & {
375
+ json: {
376
+ sourceSystem: string;
377
+ objectType: string;
378
+ externalId: string;
379
+ metadata?: Record<string, unknown> | null | undefined;
380
+ status?: "active" | "inactive" | "archived" | undefined;
381
+ lastSyncedAt?: string | null | undefined;
382
+ namespace?: string | undefined;
383
+ externalParentId?: string | null | undefined;
384
+ isPrimary?: boolean | undefined;
385
+ };
225
386
  };
226
387
  output: {
227
388
  data: {
228
- namespace: string;
229
- metadata: {
230
- [x: string]: import("hono/utils/types").JSONValue;
231
- } | null;
232
- status: "active" | "inactive" | "archived";
233
389
  id: string;
234
- createdAt: string;
235
- updatedAt: string;
236
390
  entityType: string;
237
391
  entityId: string;
238
- isPrimary: boolean;
239
- lastSyncedAt: string | null;
240
392
  sourceSystem: string;
241
393
  objectType: string;
394
+ namespace: string;
242
395
  externalId: string;
243
396
  externalParentId: string | null;
244
- } | null;
397
+ isPrimary: boolean;
398
+ status: "active" | "inactive" | "archived";
399
+ lastSyncedAt: string | null;
400
+ metadata: {
401
+ [x: string]: import("hono/utils/types").JSONValue;
402
+ } | null;
403
+ createdAt: string;
404
+ updatedAt: string;
405
+ };
245
406
  };
246
407
  outputFormat: "json";
247
408
  status: 201;
248
409
  };
249
410
  };
250
- }, "/", "/entities/:entityType/:entityId/refs">;
411
+ }, "/">;
251
412
  export type ExternalRefsRoutes = typeof externalRefsRoutes;
252
413
  export {};
253
414
  //# sourceMappingURL=routes.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"routes.d.ts","sourceRoot":"","sources":["../../src/external-refs/routes.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAA;AAWjE,KAAK,GAAG,GAAG;IACT,SAAS,EAAE;QACT,EAAE,EAAE,kBAAkB,CAAA;QACtB,MAAM,CAAC,EAAE,MAAM,CAAA;KAChB,CAAA;CACF,CAAA;AAED,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;+CAyD3B,CAAA;AAEJ,MAAM,MAAM,kBAAkB,GAAG,OAAO,kBAAkB,CAAA"}
1
+ {"version":3,"file":"routes.d.ts","sourceRoot":"","sources":["../../src/external-refs/routes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAe,WAAW,EAAK,MAAM,mBAAmB,CAAA;AAG/D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAA;AAWjE,KAAK,GAAG,GAAG;IACT,SAAS,EAAE;QACT,EAAE,EAAE,kBAAkB,CAAA;QACtB,MAAM,CAAC,EAAE,MAAM,CAAA;KAChB,CAAA;CACF,CAAA;AA8HD,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA4C3B,CAAA;AAEJ,MAAM,MAAM,kBAAkB,GAAG,OAAO,kBAAkB,CAAA"}
@@ -1,52 +1,171 @@
1
- import { parseJsonBody, parseQuery } from "@voyant-travel/hono";
2
- import { Hono } from "hono";
1
+ /**
2
+ * External-reference admin routes — the cross-system id mapping registry
3
+ * (`external_refs`): list/create/get/patch/delete plus the entity-scoped
4
+ * list/create legs. Migrated to `@hono/zod-openapi` for the OpenAPI admin
5
+ * backfill (voyant#2114 — distribution sub-batch) via the same NON-BREAKING
6
+ * dual-mount: the exported `externalRefsRoutes` `OpenAPIHono` instance is
7
+ * mounted by the framework on BOTH the legacy `/v1/external-refs/*` surface (the
8
+ * dashboard still calls those paths) AND the documented staff surface at
9
+ * `/v1/admin/external-refs/*` (see `external-refs/index.ts`). Request schemas
10
+ * reuse the exported `validation.ts` schemas; the response row schema is
11
+ * authored from the Drizzle `$inferSelect` shape (§17 timestamps → strings).
12
+ * Handlers read `c.req.valid(...)`; the entity-scoped list still re-parses the
13
+ * merged params via the full list-query schema.
14
+ */
15
+ import { createRoute, OpenAPIHono, z } from "@hono/zod-openapi";
16
+ import { openApiValidationHook } from "@voyant-travel/hono";
17
+ import { listResponseSchema } from "@voyant-travel/types";
3
18
  import { externalRefsService } from "./service.js";
4
- import { externalRefListQuerySchema, insertExternalRefForEntitySchema, insertExternalRefSchema, updateExternalRefSchema, } from "./validation.js";
5
- export const externalRefsRoutes = new Hono()
6
- .get("/refs", async (c) => {
7
- const query = await parseQuery(c, externalRefListQuerySchema);
8
- return c.json(await externalRefsService.listExternalRefs(c.get("db"), query));
9
- })
10
- .post("/refs", async (c) => {
11
- return c.json({
12
- data: await externalRefsService.createExternalRef(c.get("db"), await parseJsonBody(c, insertExternalRefSchema)),
13
- }, 201);
19
+ import { externalRefListQuerySchema, externalRefStatusSchema, insertExternalRefForEntitySchema, insertExternalRefSchema, updateExternalRefSchema, } from "./validation.js";
20
+ const jsonContent = (schema) => ({
21
+ content: { "application/json": { schema } },
22
+ });
23
+ const requiredJsonBody = (schema) => ({
24
+ body: { required: true, content: { "application/json": { schema } } },
25
+ });
26
+ const errorResponseSchema = z.object({ error: z.string() });
27
+ const successResponseSchema = z.object({ success: z.literal(true) });
28
+ const idParamSchema = z.object({ id: z.string() });
29
+ const entityParamSchema = z.object({ entityType: z.string(), entityId: z.string() });
30
+ // §17: `timestamp` columns are serialized to ISO strings over the wire.
31
+ const externalRefSchema = z.object({
32
+ id: z.string(),
33
+ entityType: z.string(),
34
+ entityId: z.string(),
35
+ sourceSystem: z.string(),
36
+ objectType: z.string(),
37
+ namespace: z.string(),
38
+ externalId: z.string(),
39
+ externalParentId: z.string().nullable(),
40
+ isPrimary: z.boolean(),
41
+ status: externalRefStatusSchema,
42
+ lastSyncedAt: z.string().nullable(),
43
+ metadata: z.record(z.string(), z.unknown()).nullable(),
44
+ createdAt: z.string(),
45
+ updatedAt: z.string(),
46
+ });
47
+ const listExternalRefsRoute = createRoute({
48
+ method: "get",
49
+ path: "/refs",
50
+ request: { query: externalRefListQuerySchema },
51
+ responses: {
52
+ 200: {
53
+ description: "Paginated external references",
54
+ ...jsonContent(listResponseSchema(externalRefSchema)),
55
+ },
56
+ },
57
+ });
58
+ const createExternalRefRoute = createRoute({
59
+ method: "post",
60
+ path: "/refs",
61
+ request: requiredJsonBody(insertExternalRefSchema),
62
+ responses: {
63
+ 201: {
64
+ description: "The created external reference",
65
+ ...jsonContent(z.object({ data: externalRefSchema })),
66
+ },
67
+ 400: { description: "invalid_request", ...jsonContent(errorResponseSchema) },
68
+ },
69
+ });
70
+ const getExternalRefRoute = createRoute({
71
+ method: "get",
72
+ path: "/refs/{id}",
73
+ request: { params: idParamSchema },
74
+ responses: {
75
+ 200: {
76
+ description: "An external reference by id",
77
+ ...jsonContent(z.object({ data: externalRefSchema })),
78
+ },
79
+ 404: { description: "External reference not found", ...jsonContent(errorResponseSchema) },
80
+ },
81
+ });
82
+ const updateExternalRefRoute = createRoute({
83
+ method: "patch",
84
+ path: "/refs/{id}",
85
+ request: { params: idParamSchema, ...requiredJsonBody(updateExternalRefSchema) },
86
+ responses: {
87
+ 200: {
88
+ description: "The updated external reference",
89
+ ...jsonContent(z.object({ data: externalRefSchema })),
90
+ },
91
+ 400: { description: "invalid_request", ...jsonContent(errorResponseSchema) },
92
+ 404: { description: "External reference not found", ...jsonContent(errorResponseSchema) },
93
+ },
94
+ });
95
+ const deleteExternalRefRoute = createRoute({
96
+ method: "delete",
97
+ path: "/refs/{id}",
98
+ request: { params: idParamSchema },
99
+ responses: {
100
+ 200: { description: "External reference deleted", ...jsonContent(successResponseSchema) },
101
+ 404: { description: "External reference not found", ...jsonContent(errorResponseSchema) },
102
+ },
103
+ });
104
+ const listEntityExternalRefsRoute = createRoute({
105
+ method: "get",
106
+ path: "/entities/{entityType}/{entityId}/refs",
107
+ request: {
108
+ params: entityParamSchema,
109
+ query: externalRefListQuerySchema.partial(),
110
+ },
111
+ responses: {
112
+ 200: {
113
+ description: "Paginated external references for an entity",
114
+ ...jsonContent(listResponseSchema(externalRefSchema)),
115
+ },
116
+ },
117
+ });
118
+ const createEntityExternalRefRoute = createRoute({
119
+ method: "post",
120
+ path: "/entities/{entityType}/{entityId}/refs",
121
+ request: {
122
+ params: entityParamSchema,
123
+ ...requiredJsonBody(insertExternalRefForEntitySchema),
124
+ },
125
+ responses: {
126
+ 201: {
127
+ description: "The created external reference for an entity",
128
+ ...jsonContent(z.object({ data: externalRefSchema })),
129
+ },
130
+ 400: { description: "invalid_request", ...jsonContent(errorResponseSchema) },
131
+ },
132
+ });
133
+ export const externalRefsRoutes = new OpenAPIHono({ defaultHook: openApiValidationHook })
134
+ .openapi(listExternalRefsRoute, async (c) => c.json(await externalRefsService.listExternalRefs(c.get("db"), c.req.valid("query")), 200))
135
+ .openapi(createExternalRefRoute, async (c) => {
136
+ const row = await externalRefsService.createExternalRef(c.get("db"), c.req.valid("json"));
137
+ return c.json({ data: row }, 201);
14
138
  })
15
- .get("/refs/:id", async (c) => {
16
- const row = await externalRefsService.getExternalRefById(c.get("db"), c.req.param("id"));
17
- if (!row)
18
- return c.json({ error: "External reference not found" }, 404);
19
- return c.json({ data: row });
139
+ .openapi(getExternalRefRoute, async (c) => {
140
+ const row = await externalRefsService.getExternalRefById(c.get("db"), c.req.valid("param").id);
141
+ return row ? c.json({ data: row }, 200) : c.json({ error: "External reference not found" }, 404);
20
142
  })
21
- .patch("/refs/:id", async (c) => {
22
- const row = await externalRefsService.updateExternalRef(c.get("db"), c.req.param("id"), await parseJsonBody(c, updateExternalRefSchema));
23
- if (!row)
24
- return c.json({ error: "External reference not found" }, 404);
25
- return c.json({ data: row });
143
+ .openapi(updateExternalRefRoute, async (c) => {
144
+ const row = await externalRefsService.updateExternalRef(c.get("db"), c.req.valid("param").id, c.req.valid("json"));
145
+ return row ? c.json({ data: row }, 200) : c.json({ error: "External reference not found" }, 404);
26
146
  })
27
- .delete("/refs/:id", async (c) => {
28
- const row = await externalRefsService.deleteExternalRef(c.get("db"), c.req.param("id"));
29
- if (!row)
30
- return c.json({ error: "External reference not found" }, 404);
31
- return c.json({ success: true });
147
+ .openapi(deleteExternalRefRoute, async (c) => {
148
+ const row = await externalRefsService.deleteExternalRef(c.get("db"), c.req.valid("param").id);
149
+ return row
150
+ ? c.json({ success: true }, 200)
151
+ : c.json({ error: "External reference not found" }, 404);
32
152
  })
33
- .get("/entities/:entityType/:entityId/refs", async (c) => {
34
- const params = c.req.param();
153
+ .openapi(listEntityExternalRefsRoute, async (c) => {
154
+ const params = c.req.valid("param");
35
155
  const query = externalRefListQuerySchema.parse({
36
- ...(await parseQuery(c, externalRefListQuerySchema.partial())),
156
+ ...c.req.valid("query"),
37
157
  entityType: params.entityType,
38
158
  entityId: params.entityId,
39
159
  });
40
- return c.json(await externalRefsService.listExternalRefs(c.get("db"), query));
160
+ return c.json(await externalRefsService.listExternalRefs(c.get("db"), query), 200);
41
161
  })
42
- .post("/entities/:entityType/:entityId/refs", async (c) => {
43
- const params = c.req.param();
44
- const body = await parseJsonBody(c, insertExternalRefForEntitySchema);
45
- return c.json({
46
- data: await externalRefsService.createExternalRef(c.get("db"), {
47
- ...body,
48
- entityType: params.entityType,
49
- entityId: params.entityId,
50
- }),
51
- }, 201);
162
+ .openapi(createEntityExternalRefRoute, async (c) => {
163
+ const params = c.req.valid("param");
164
+ const body = c.req.valid("json");
165
+ const row = await externalRefsService.createExternalRef(c.get("db"), {
166
+ ...body,
167
+ entityType: params.entityType,
168
+ entityId: params.entityId,
169
+ });
170
+ return c.json({ data: row }, 201);
52
171
  });
@@ -43,20 +43,20 @@ export declare const externalRefsService: {
43
43
  updatedAt: Date;
44
44
  } | null>;
45
45
  createExternalRef(db: PostgresJsDatabase, data: CreateExternalRefInput): Promise<{
46
- namespace: string;
47
- metadata: Record<string, unknown> | null;
48
- status: "active" | "inactive" | "archived";
49
- id: string;
50
46
  createdAt: Date;
51
47
  updatedAt: Date;
48
+ metadata: Record<string, unknown> | null;
49
+ id: string;
50
+ status: "active" | "inactive" | "archived";
51
+ lastSyncedAt: Date | null;
52
52
  entityType: string;
53
53
  entityId: string;
54
- isPrimary: boolean;
55
- lastSyncedAt: Date | null;
56
54
  sourceSystem: string;
57
55
  objectType: string;
56
+ namespace: string;
58
57
  externalId: string;
59
58
  externalParentId: string | null;
59
+ isPrimary: boolean;
60
60
  } | null>;
61
61
  updateExternalRef(db: PostgresJsDatabase, id: string, data: UpdateExternalRefInput): Promise<{
62
62
  id: string;