From b13f0174cb3f1a4d3e7e3a03cca2c40b506f2608 Mon Sep 17 00:00:00 2001 From: Chandra shekar Varkala Date: Mon, 5 Feb 2024 11:56:49 -0600 Subject: [PATCH] chore: 1 --- package-lock.json | 11 +++- package.json | 3 +- test/integrations/testTypes.ts | 99 ++++++++++++++++++++++++++++++++++ 3 files changed, 111 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index 7fbf47bab5..644e13a09e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -68,7 +68,8 @@ "ua-parser-js": "^1.0.37", "unset-value": "^2.0.1", "uuid": "^9.0.0", - "valid-url": "^1.0.9" + "valid-url": "^1.0.9", + "zod": "^3.22.4" }, "devDependencies": { "@commitlint/config-conventional": "^17.6.3", @@ -21108,6 +21109,14 @@ "funding": { "url": "https://github.com/sponsors/sindresorhus" } + }, + "node_modules/zod": { + "version": "3.22.4", + "resolved": "https://registry.npmjs.org/zod/-/zod-3.22.4.tgz", + "integrity": "sha512-iC+8Io04lddc+mVqQ9AZ7OQ2MrUKGN+oIQyq1vemgt46jwCwLfhq7/pwnBnNXXXZb8VTVLKwp9EDkx+ryxIWmg==", + "funding": { + "url": "https://github.com/sponsors/colinhacks" + } } } } diff --git a/package.json b/package.json index 13aaecb000..62027c70b3 100644 --- a/package.json +++ b/package.json @@ -113,7 +113,8 @@ "ua-parser-js": "^1.0.37", "unset-value": "^2.0.1", "uuid": "^9.0.0", - "valid-url": "^1.0.9" + "valid-url": "^1.0.9", + "zod": "^3.22.4" }, "devDependencies": { "@commitlint/config-conventional": "^17.6.3", diff --git a/test/integrations/testTypes.ts b/test/integrations/testTypes.ts index 51667e8044..ecca49124c 100644 --- a/test/integrations/testTypes.ts +++ b/test/integrations/testTypes.ts @@ -1,5 +1,7 @@ import { AxiosResponse } from 'axios'; +import { ZodTypeAny, z } from 'zod'; import MockAdapter from 'axios-mock-adapter'; +import { FEATURES } from '../../src/v0/util/tags'; export interface requestType { method: string; @@ -44,3 +46,100 @@ export type MockHttpCallsData = { httpReq: Record; httpRes: Partial; }; + +export const arrayOrSingleElement = (schema: ZodTypeAny) => z.union([z.array(schema), schema]); + +export const formElementSchema = arrayOrSingleElement( + z.union([z.string(), z.number(), z.boolean()]), +); + +export const eventResponseSchema = z.union([ + z.object({ + error: z.string(), + statTags: z + .object({ + destType: z.string().optional(), + errorCategory: z.string().optional(), + errorType: z.string().optional(), + feature: z.nativeEnum(FEATURES).optional(), + implementation: z.string().optional(), + module: z.string().optional(), + }) + .optional(), + statusCode: z.number().optional(), + }), + z.object({ + output: z + .object({ + version: z.string().optional(), + type: z.string().optional(), + method: z.string().optional(), + endpoint: z.string().optional(), + headers: z.record(z.string(), z.string()).optional(), + params: z.record(z.string(), z.any()).optional(), + body: z + .object({ + JSON: z.record(z.string(), z.any()).optional(), + XML: z + .object({ + payload: z.string().optional(), + }) + .optional(), + JSON_ARRAY: z + .object({ + batch: z.any().optional(), + }) + .optional(), + FORM: z.record(z.string(), formElementSchema).optional(), + GZIP: z + .object({ + payload: z.string().optional(), + }) + .optional(), + }) + .optional(), + files: z.record(z.string(), z.any()).optional(), + userId: z.string().optional(), + }) + .optional(), + metadata: z.record(z.string(), z.any()).optional(), + statusCode: z.number().optional(), + }), +]); + +export const batchTransformSchema = z.array( + z.object({ + batchedRequest: arrayOrSingleElement(eventResponseSchema).optional(), + metadata: z.array(z.record(z.string(), z.any())).optional(), + destination: z + .object({ + ID: z.string().optional(), + Name: z.string().optional(), + DestinationDefinition: z + .object({ + ID: z.string().optional(), + Name: z.string().optional(), + DisplayName: z.string().optional(), + Config: z.any().optional(), + ResponseRules: z.any().optional(), + }) + .optional(), + Config: z.any().optional(), + Enabled: z.boolean().optional(), + WorkspaceID: z.string().optional(), + Transformations: z.any().optional(), + IsProcessorEnabled: z.boolean().optional(), + RevisionID: z.string().optional(), + }) + .optional(), + batched: z.boolean().optional(), + statusCode: z.number().optional(), + error: z.string().optional(), + }), +); + +export const routerTransformSchema = z.object({ + output: batchTransformSchema, +}); + +export const processorTransformSchema = z.array(eventResponseSchema);