|
|
|
|
@@ -1,5 +1,3 @@
|
|
|
|
|
import { z } from 'zod';
|
|
|
|
|
|
|
|
|
|
import {
|
|
|
|
|
chartSegments,
|
|
|
|
|
chartTypes,
|
|
|
|
|
@@ -9,9 +7,10 @@ import {
|
|
|
|
|
operators,
|
|
|
|
|
timeWindows,
|
|
|
|
|
} from '@openpanel/constants';
|
|
|
|
|
import { z } from 'zod';
|
|
|
|
|
|
|
|
|
|
export function objectToZodEnums<K extends string>(
|
|
|
|
|
obj: Record<K, any>,
|
|
|
|
|
obj: Record<K, any>
|
|
|
|
|
): [K, ...K[]] {
|
|
|
|
|
const [firstKey, ...otherKeys] = Object.keys(obj) as K[];
|
|
|
|
|
return [firstKey!, ...otherKeys];
|
|
|
|
|
@@ -49,7 +48,7 @@ export const zChartEvent = z.object({
|
|
|
|
|
.string()
|
|
|
|
|
.optional()
|
|
|
|
|
.describe(
|
|
|
|
|
'Optional property of the event used for specific segment calculations (e.g., value for property_sum/average)',
|
|
|
|
|
'Optional property of the event used for specific segment calculations (e.g., value for property_sum/average)'
|
|
|
|
|
),
|
|
|
|
|
segment: zChartEventSegment,
|
|
|
|
|
filters: z
|
|
|
|
|
@@ -89,7 +88,7 @@ export const zChartBreakdown = z.object({
|
|
|
|
|
export const zChartSeries = z
|
|
|
|
|
.array(zChartEventItem)
|
|
|
|
|
.describe(
|
|
|
|
|
'Array of series (events or formulas) to be tracked and displayed in the chart',
|
|
|
|
|
'Array of series (events or formulas) to be tracked and displayed in the chart'
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
export const zChartBreakdowns = z.array(zChartBreakdown);
|
|
|
|
|
@@ -174,10 +173,10 @@ export const zReportInput = z.object({
|
|
|
|
|
interval: zTimeInterval
|
|
|
|
|
.default('day')
|
|
|
|
|
.describe(
|
|
|
|
|
'The time interval for data aggregation (e.g., day, week, month)',
|
|
|
|
|
'The time interval for data aggregation (e.g., day, week, month)'
|
|
|
|
|
),
|
|
|
|
|
series: zChartSeries.describe(
|
|
|
|
|
'Array of series (events or formulas) to be tracked and displayed in the chart',
|
|
|
|
|
'Array of series (events or formulas) to be tracked and displayed in the chart'
|
|
|
|
|
),
|
|
|
|
|
breakdowns: zChartBreakdowns
|
|
|
|
|
.default([])
|
|
|
|
|
@@ -189,13 +188,13 @@ export const zReportInput = z.object({
|
|
|
|
|
.string()
|
|
|
|
|
.nullish()
|
|
|
|
|
.describe(
|
|
|
|
|
'Custom start date for the data range (overrides range if provided)',
|
|
|
|
|
'Custom start date for the data range (overrides range if provided)'
|
|
|
|
|
),
|
|
|
|
|
endDate: z
|
|
|
|
|
.string()
|
|
|
|
|
.nullish()
|
|
|
|
|
.describe(
|
|
|
|
|
'Custom end date for the data range (overrides range if provided)',
|
|
|
|
|
'Custom end date for the data range (overrides range if provided)'
|
|
|
|
|
),
|
|
|
|
|
previous: z
|
|
|
|
|
.boolean()
|
|
|
|
|
@@ -208,7 +207,7 @@ export const zReportInput = z.object({
|
|
|
|
|
metric: zMetric
|
|
|
|
|
.default('sum')
|
|
|
|
|
.describe(
|
|
|
|
|
'The aggregation method for the metric (e.g., sum, count, average)',
|
|
|
|
|
'The aggregation method for the metric (e.g., sum, count, average)'
|
|
|
|
|
),
|
|
|
|
|
limit: z
|
|
|
|
|
.number()
|
|
|
|
|
@@ -230,7 +229,7 @@ export const zReportInput = z.object({
|
|
|
|
|
.string()
|
|
|
|
|
.optional()
|
|
|
|
|
.describe(
|
|
|
|
|
"Optional unit of measurement for the chart's Y-axis (e.g., $, %, users)",
|
|
|
|
|
"Optional unit of measurement for the chart's Y-axis (e.g., $, %, users)"
|
|
|
|
|
),
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
@@ -298,7 +297,7 @@ export const zOnboardingProject = z
|
|
|
|
|
timezone: z.string().optional(),
|
|
|
|
|
})
|
|
|
|
|
.superRefine((data, ctx) => {
|
|
|
|
|
if (!data.organization && !data.organizationId) {
|
|
|
|
|
if (!(data.organization || data.organizationId)) {
|
|
|
|
|
ctx.addIssue({
|
|
|
|
|
code: 'custom',
|
|
|
|
|
message: 'Organization is required',
|
|
|
|
|
@@ -408,13 +407,13 @@ export const zCreateSlackIntegration = zCreateIntegration;
|
|
|
|
|
export const zCreateWebhookIntegration = zCreateIntegration.merge(
|
|
|
|
|
z.object({
|
|
|
|
|
config: zWebhookConfig,
|
|
|
|
|
}),
|
|
|
|
|
})
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
export const zCreateDiscordIntegration = zCreateIntegration.merge(
|
|
|
|
|
z.object({
|
|
|
|
|
config: zDiscordConfig,
|
|
|
|
|
}),
|
|
|
|
|
})
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
export const zNotificationRuleEventConfig = z.object({
|
|
|
|
|
@@ -545,7 +544,7 @@ export const zGroupId = z
|
|
|
|
|
.min(1)
|
|
|
|
|
.regex(
|
|
|
|
|
/^[a-z0-9_-]+$/,
|
|
|
|
|
'ID must only contain lowercase letters, digits, hyphens, or underscores',
|
|
|
|
|
'ID must only contain lowercase letters, digits, hyphens, or underscores'
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
export const zCreateGroup = z.object({
|
|
|
|
|
@@ -623,6 +622,6 @@ export const zCreateImport = z.object({
|
|
|
|
|
|
|
|
|
|
export type ICreateImport = z.infer<typeof zCreateImport>;
|
|
|
|
|
|
|
|
|
|
export * from './types.insights';
|
|
|
|
|
export * from './track.validation';
|
|
|
|
|
export * from './event-blocklist';
|
|
|
|
|
export * from './track.validation';
|
|
|
|
|
export * from './types.insights';
|
|
|
|
|
|