From 8e54ce054feb113337e4ea37433055b78d35ab7b Mon Sep 17 00:00:00 2001 From: almog8k Date: Wed, 19 Nov 2025 14:20:57 +0200 Subject: [PATCH 1/3] feat: feat: callback schemas and types --- src/schemas/core/callback.schema.ts | 32 ++++++++++++++++++++++++ src/schemas/core/callbackUrl.schema.ts | 5 ---- src/schemas/core/index.ts | 2 +- src/schemas/export/job.schema.ts | 2 +- src/schemas/ingestion/callback.schema.ts | 14 +++++++++++ src/schemas/ingestion/index.ts | 1 + src/schemas/ingestion/job.schema.ts | 2 +- src/types/core/callback.type.ts | 4 +++ src/types/export/export.type.ts | 2 +- src/types/ingestion/callback.type.ts | 4 +++ src/types/ingestion/index.ts | 1 + 11 files changed, 60 insertions(+), 9 deletions(-) create mode 100644 src/schemas/core/callback.schema.ts delete mode 100644 src/schemas/core/callbackUrl.schema.ts create mode 100644 src/schemas/ingestion/callback.schema.ts create mode 100644 src/types/core/callback.type.ts create mode 100644 src/types/ingestion/callback.type.ts diff --git a/src/schemas/core/callback.schema.ts b/src/schemas/core/callback.schema.ts new file mode 100644 index 0000000..69c6aec --- /dev/null +++ b/src/schemas/core/callback.schema.ts @@ -0,0 +1,32 @@ +import z from 'zod'; +import { OperationStatus } from '@map-colonies/mc-priority-queue'; +import { rasterProductTypeSchema, versionSchema } from './job.schema'; + +export const callbackUrlSchema = z.string().url(); + +export const callbackUrlsArraySchema = z.array(callbackUrlSchema); + +export const fileMetadataSchema = z.object({ + name: z.string(), + url: callbackUrlSchema, + size: z.number(), +}); + +// eslint-disable-next-line @typescript-eslint/explicit-function-return-type +export const createCallbackResponseSchema = (dataSchema?: z.ZodType) => { + return z.object({ + jobId: z.string().uuid(), + taskId: z.string().uuid(), + jobType: z.string(), + taskType: z.string(), + productId: z.string(), + productType: rasterProductTypeSchema, + version: versionSchema, + status: z.nativeEnum(OperationStatus), + // eslint-disable-next-line @typescript-eslint/no-magic-numbers + progress: z.number().min(0).max(100).optional(), + message: z.string().optional(), + error: z.string().optional(), + data: dataSchema ?? z.unknown(), + }); +}; diff --git a/src/schemas/core/callbackUrl.schema.ts b/src/schemas/core/callbackUrl.schema.ts deleted file mode 100644 index 00cf90b..0000000 --- a/src/schemas/core/callbackUrl.schema.ts +++ /dev/null @@ -1,5 +0,0 @@ -import z from 'zod'; - -export const callbackUrlSchema = z.string().url(); - -export const callbackUrlsArraySchema = z.array(callbackUrlSchema); diff --git a/src/schemas/core/index.ts b/src/schemas/core/index.ts index f4083f2..0ffd356 100644 --- a/src/schemas/core/index.ts +++ b/src/schemas/core/index.ts @@ -3,4 +3,4 @@ export * from './job.schema'; export * from './task.schema'; export * from './mime.schema'; export * from './aggregation.schema'; -export * from './callbackUrl.schema'; +export * from './callback.schema'; diff --git a/src/schemas/export/job.schema.ts b/src/schemas/export/job.schema.ts index 7bb71f7..aafd996 100644 --- a/src/schemas/export/job.schema.ts +++ b/src/schemas/export/job.schema.ts @@ -1,7 +1,7 @@ import { z } from 'zod'; import { CORE_VALIDATIONS, TileFormatStrategy, TileOutputFormat } from '../../constants'; import { polygonPartsEntityNameSchema } from '../ingestion'; -import { callbackUrlsArraySchema } from '../core/callbackUrl.schema'; +import { callbackUrlsArraySchema } from '../core/callback.schema'; import { callbackExportResponseSchema, cleanupDataSchema, roiFeatureCollectionSchema, fileNamesTemplatesSchema } from './export.schema'; export const exportInputParamsSchema = z.object({ diff --git a/src/schemas/ingestion/callback.schema.ts b/src/schemas/ingestion/callback.schema.ts new file mode 100644 index 0000000..a53090c --- /dev/null +++ b/src/schemas/ingestion/callback.schema.ts @@ -0,0 +1,14 @@ +import z from 'zod'; +import { fileMetadataSchema } from '../core'; + +//#region Validation + +export const validationCallbackDataSchema = z + .object({ + isValid: z.boolean(), + sourceName: z.string(), + links: fileMetadataSchema.array().optional(), + }) + .describe('validationCallbackDataSchema'); + +//#endregion Validation diff --git a/src/schemas/ingestion/index.ts b/src/schemas/ingestion/index.ts index ceb3365..ba8424a 100644 --- a/src/schemas/ingestion/index.ts +++ b/src/schemas/ingestion/index.ts @@ -5,3 +5,4 @@ export * from './polygonParts.schema'; export * from './job.schema'; export * from './task.schema'; export * from './layerNameFormats.schema'; +export * from './callback.schema'; diff --git a/src/schemas/ingestion/job.schema.ts b/src/schemas/ingestion/job.schema.ts index ac49eb5..edd1569 100644 --- a/src/schemas/ingestion/job.schema.ts +++ b/src/schemas/ingestion/job.schema.ts @@ -1,6 +1,6 @@ import z from 'zod'; import { CORE_VALIDATIONS } from '../../constants'; -import { callbackUrlsArraySchema } from '../core/callbackUrl.schema'; +import { callbackUrlsArraySchema } from '../core/callback.schema'; import { newAdditionalParamsSchema, swapUpdateAdditionalParamsSchema, updateAdditionalParamsSchema } from './additionalParams.schema'; import { inputFilesSchema } from './inputFiles.schema'; import { newRasterLayerMetadataSchema, updateRasterLayerMetadataSchema } from './metadata.schema'; diff --git a/src/types/core/callback.type.ts b/src/types/core/callback.type.ts new file mode 100644 index 0000000..4adb59b --- /dev/null +++ b/src/types/core/callback.type.ts @@ -0,0 +1,4 @@ +import z from 'zod'; +import { createCallbackResponseSchema } from '../../schemas'; + +export type CallbackResponse = z.infer>>; diff --git a/src/types/export/export.type.ts b/src/types/export/export.type.ts index e6bd03e..4028013 100644 --- a/src/types/export/export.type.ts +++ b/src/types/export/export.type.ts @@ -10,7 +10,7 @@ import { linksSchema, roiPropertiesSchema, } from '../../schemas/export/export.schema'; -import { callbackUrlsArraySchema, callbackUrlSchema } from '../../schemas/core/callbackUrl.schema'; +import { callbackUrlsArraySchema, callbackUrlSchema } from '../../schemas/core/callback.schema'; export type RoiProperties = z.infer; export type RoiFeature = Feature; diff --git a/src/types/ingestion/callback.type.ts b/src/types/ingestion/callback.type.ts new file mode 100644 index 0000000..9264138 --- /dev/null +++ b/src/types/ingestion/callback.type.ts @@ -0,0 +1,4 @@ +import z from 'zod'; +import { validationCallbackDataSchema } from '../../schemas/ingestion/callback.schema'; + +export type ValidationCallbackData = z.infer; diff --git a/src/types/ingestion/index.ts b/src/types/ingestion/index.ts index 0bd3c01..29713e7 100644 --- a/src/types/ingestion/index.ts +++ b/src/types/ingestion/index.ts @@ -3,3 +3,4 @@ export * from './job.type'; export * from './task.type'; export * from './polygonParts.type'; export * from './report.type'; +export * from './callback.type'; From c767b1cec4d5c285664c066daa066677dbed4ec4 Mon Sep 17 00:00:00 2001 From: almog8k Date: Wed, 19 Nov 2025 14:41:19 +0200 Subject: [PATCH 2/3] fix: rename validationCallbackDataSchema to validationTaskCallbackDataSchema for consistency --- src/schemas/ingestion/callback.schema.ts | 4 ++-- src/types/ingestion/callback.type.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/schemas/ingestion/callback.schema.ts b/src/schemas/ingestion/callback.schema.ts index a53090c..a2a40f0 100644 --- a/src/schemas/ingestion/callback.schema.ts +++ b/src/schemas/ingestion/callback.schema.ts @@ -3,12 +3,12 @@ import { fileMetadataSchema } from '../core'; //#region Validation -export const validationCallbackDataSchema = z +export const validationTaskCallbackDataSchema = z .object({ isValid: z.boolean(), sourceName: z.string(), links: fileMetadataSchema.array().optional(), }) - .describe('validationCallbackDataSchema'); + .describe('validationTaskCallbackDataSchema'); //#endregion Validation diff --git a/src/types/ingestion/callback.type.ts b/src/types/ingestion/callback.type.ts index 9264138..4a22125 100644 --- a/src/types/ingestion/callback.type.ts +++ b/src/types/ingestion/callback.type.ts @@ -1,4 +1,4 @@ import z from 'zod'; -import { validationCallbackDataSchema } from '../../schemas/ingestion/callback.schema'; +import { validationTaskCallbackDataSchema } from '../../schemas/ingestion/callback.schema'; -export type ValidationCallbackData = z.infer; +export type ValidationCallbackData = z.infer; From cc0ba94eb74e48e701232227c777ba950f585a22 Mon Sep 17 00:00:00 2001 From: almog8k Date: Wed, 19 Nov 2025 14:58:48 +0200 Subject: [PATCH 3/3] fix: add productId schema --- src/schemas/core/callback.schema.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/schemas/core/callback.schema.ts b/src/schemas/core/callback.schema.ts index 69c6aec..68f2b47 100644 --- a/src/schemas/core/callback.schema.ts +++ b/src/schemas/core/callback.schema.ts @@ -1,6 +1,6 @@ import z from 'zod'; import { OperationStatus } from '@map-colonies/mc-priority-queue'; -import { rasterProductTypeSchema, versionSchema } from './job.schema'; +import { rasterProductTypeSchema, resourceIdSchema, versionSchema } from './job.schema'; export const callbackUrlSchema = z.string().url(); @@ -19,7 +19,7 @@ export const createCallbackResponseSchema = (dataSchema?: z.ZodType) => { taskId: z.string().uuid(), jobType: z.string(), taskType: z.string(), - productId: z.string(), + productId: resourceIdSchema, productType: rasterProductTypeSchema, version: versionSchema, status: z.nativeEnum(OperationStatus),