@teardown/schemas 0.1.0
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.
- package/dist/common/index.d.ts +3 -0
- package/dist/common/index.js +3 -0
- package/dist/common/primitives.d.ts +11 -0
- package/dist/common/primitives.js +9 -0
- package/dist/common/responses.d.ts +27 -0
- package/dist/common/responses.js +13 -0
- package/dist/common/type-checks.d.ts +58 -0
- package/dist/common/type-checks.js +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +14 -0
- package/dist/modules/analytics/index.d.ts +1 -0
- package/dist/modules/analytics/index.js +1 -0
- package/dist/modules/analytics/schemas.d.ts +239 -0
- package/dist/modules/analytics/schemas.js +136 -0
- package/dist/modules/builds/index.d.ts +1 -0
- package/dist/modules/builds/index.js +1 -0
- package/dist/modules/builds/schemas.d.ts +248 -0
- package/dist/modules/builds/schemas.js +137 -0
- package/dist/modules/devices/index.d.ts +1 -0
- package/dist/modules/devices/index.js +1 -0
- package/dist/modules/devices/schemas.d.ts +207 -0
- package/dist/modules/devices/schemas.js +165 -0
- package/dist/modules/environment/index.d.ts +1 -0
- package/dist/modules/environment/index.js +1 -0
- package/dist/modules/environment/schemas.d.ts +56 -0
- package/dist/modules/environment/schemas.js +57 -0
- package/dist/modules/events/index.d.ts +1 -0
- package/dist/modules/events/index.js +1 -0
- package/dist/modules/events/schemas.d.ts +138 -0
- package/dist/modules/events/schemas.js +116 -0
- package/dist/modules/identify/index.d.ts +1 -0
- package/dist/modules/identify/index.js +1 -0
- package/dist/modules/identify/schemas.d.ts +377 -0
- package/dist/modules/identify/schemas.js +221 -0
- package/dist/modules/index.d.ts +12 -0
- package/dist/modules/index.js +12 -0
- package/dist/modules/me/index.d.ts +1 -0
- package/dist/modules/me/index.js +1 -0
- package/dist/modules/me/schemas.d.ts +75 -0
- package/dist/modules/me/schemas.js +76 -0
- package/dist/modules/orgs/index.d.ts +1 -0
- package/dist/modules/orgs/index.js +1 -0
- package/dist/modules/orgs/schemas.d.ts +308 -0
- package/dist/modules/orgs/schemas.js +214 -0
- package/dist/modules/personas/index.d.ts +1 -0
- package/dist/modules/personas/index.js +1 -0
- package/dist/modules/personas/schemas.d.ts +170 -0
- package/dist/modules/personas/schemas.js +100 -0
- package/dist/modules/projects/index.d.ts +1 -0
- package/dist/modules/projects/index.js +1 -0
- package/dist/modules/projects/schemas.d.ts +222 -0
- package/dist/modules/projects/schemas.js +145 -0
- package/dist/modules/sessions/index.d.ts +1 -0
- package/dist/modules/sessions/index.js +1 -0
- package/dist/modules/sessions/schemas.d.ts +258 -0
- package/dist/modules/sessions/schemas.js +128 -0
- package/dist/modules/versions/index.d.ts +1 -0
- package/dist/modules/versions/index.js +1 -0
- package/dist/modules/versions/schemas.d.ts +248 -0
- package/dist/modules/versions/schemas.js +155 -0
- package/package.json +106 -0
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { DevicePlatformEnum } from "@teardown/types";
|
|
2
|
+
import { t } from "elysia";
|
|
3
|
+
/**
|
|
4
|
+
* Device platform enum matching database
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Device platform
|
|
8
|
+
*/
|
|
9
|
+
export const DevicePlatformSchema = t.Enum(DevicePlatformEnum, { error: "platform is required" });
|
|
10
|
+
/**
|
|
11
|
+
* Parse and validate a DevicePlatformEnum value
|
|
12
|
+
* Uses a switch statement to ensure type safety and runtime validation
|
|
13
|
+
* @param value - The value to parse
|
|
14
|
+
* @returns The validated DevicePlatformEnum value or null
|
|
15
|
+
* @throws Error if the value is not a valid DevicePlatformEnum and not null
|
|
16
|
+
*/
|
|
17
|
+
export function parseDevicePlatformEnum(value) {
|
|
18
|
+
if (value === null || value === undefined) {
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
switch (value) {
|
|
22
|
+
case DevicePlatformEnum.IOS:
|
|
23
|
+
return DevicePlatformEnum.IOS;
|
|
24
|
+
case DevicePlatformEnum.ANDROID:
|
|
25
|
+
return DevicePlatformEnum.ANDROID;
|
|
26
|
+
case DevicePlatformEnum.WEB:
|
|
27
|
+
return DevicePlatformEnum.WEB;
|
|
28
|
+
case DevicePlatformEnum.WINDOWS:
|
|
29
|
+
return DevicePlatformEnum.WINDOWS;
|
|
30
|
+
case DevicePlatformEnum.MACOS:
|
|
31
|
+
return DevicePlatformEnum.MACOS;
|
|
32
|
+
case DevicePlatformEnum.LINUX:
|
|
33
|
+
return DevicePlatformEnum.LINUX;
|
|
34
|
+
case DevicePlatformEnum.PHONE:
|
|
35
|
+
return DevicePlatformEnum.PHONE;
|
|
36
|
+
case DevicePlatformEnum.TABLET:
|
|
37
|
+
return DevicePlatformEnum.TABLET;
|
|
38
|
+
case DevicePlatformEnum.DESKTOP:
|
|
39
|
+
return DevicePlatformEnum.DESKTOP;
|
|
40
|
+
case DevicePlatformEnum.CONSOLE:
|
|
41
|
+
return DevicePlatformEnum.CONSOLE;
|
|
42
|
+
case DevicePlatformEnum.TV:
|
|
43
|
+
return DevicePlatformEnum.TV;
|
|
44
|
+
case DevicePlatformEnum.WEARABLE:
|
|
45
|
+
return DevicePlatformEnum.WEARABLE;
|
|
46
|
+
case DevicePlatformEnum.GAME_CONSOLE:
|
|
47
|
+
return DevicePlatformEnum.GAME_CONSOLE;
|
|
48
|
+
case DevicePlatformEnum.VR:
|
|
49
|
+
return DevicePlatformEnum.VR;
|
|
50
|
+
case DevicePlatformEnum.UNKNOWN:
|
|
51
|
+
return DevicePlatformEnum.UNKNOWN;
|
|
52
|
+
case DevicePlatformEnum.OTHER:
|
|
53
|
+
return DevicePlatformEnum.OTHER;
|
|
54
|
+
default:
|
|
55
|
+
throw new Error(`Invalid DevicePlatformEnum value: ${value}. Expected one of: ${Object.values(DevicePlatformEnum).join(", ")}`);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Base device schema
|
|
60
|
+
* Represents devices table structure
|
|
61
|
+
*/
|
|
62
|
+
export const DeviceSchema = t.Object({
|
|
63
|
+
id: t.String({ format: "uuid" }),
|
|
64
|
+
persona_id: t.String({ format: "uuid" }),
|
|
65
|
+
environment_id: t.Union([t.String({ format: "uuid" }), t.Null()]),
|
|
66
|
+
device_id: t.String(),
|
|
67
|
+
platform: t.Union([DevicePlatformSchema, t.Null()]),
|
|
68
|
+
os_type: t.Union([t.String(), t.Null()]),
|
|
69
|
+
os_name: t.Union([t.String(), t.Null()]),
|
|
70
|
+
device_name: t.Union([t.String(), t.Null()]),
|
|
71
|
+
device_brand: t.Union([t.String(), t.Null()]),
|
|
72
|
+
metadata: t.Union([t.Record(t.String(), t.Unknown()), t.Null()]),
|
|
73
|
+
created_at: t.String(),
|
|
74
|
+
updated_at: t.String(),
|
|
75
|
+
});
|
|
76
|
+
/**
|
|
77
|
+
* Device params schema
|
|
78
|
+
*/
|
|
79
|
+
export const DeviceParamsSchema = t.Object({
|
|
80
|
+
device_id: t.String({ format: "uuid" }),
|
|
81
|
+
});
|
|
82
|
+
/**
|
|
83
|
+
* Search devices query schema
|
|
84
|
+
* Supports pagination, search, and sorting
|
|
85
|
+
*/
|
|
86
|
+
export const SearchDevicesQuerySchema = t.Object({
|
|
87
|
+
project_id: t.String({ format: "uuid" }),
|
|
88
|
+
page: t.Numeric({ minimum: 1, default: 1 }),
|
|
89
|
+
limit: t.Numeric({ minimum: 1, maximum: 100, default: 20 }),
|
|
90
|
+
search: t.Optional(t.String()),
|
|
91
|
+
sort_by: t.Union([
|
|
92
|
+
t.Literal("created_at"),
|
|
93
|
+
t.Literal("updated_at"),
|
|
94
|
+
t.Literal("device_name"),
|
|
95
|
+
t.Literal("platform"),
|
|
96
|
+
t.Literal("os_name"),
|
|
97
|
+
], { default: "created_at" }),
|
|
98
|
+
sort_order: t.Union([t.Literal("asc"), t.Literal("desc")], { default: "desc" }),
|
|
99
|
+
});
|
|
100
|
+
/**
|
|
101
|
+
* Search devices query schema without project_id (injected from headers)
|
|
102
|
+
*/
|
|
103
|
+
export const SearchDevicesQueryParamsSchema = t.Omit(SearchDevicesQuerySchema, ["project_id"]);
|
|
104
|
+
/**
|
|
105
|
+
* Devices by IDs request schema
|
|
106
|
+
*/
|
|
107
|
+
export const DevicesByIdsSchema = t.Object({
|
|
108
|
+
device_ids: t.Array(t.String({ format: "uuid" }), { minItems: 1, maxItems: 100 }),
|
|
109
|
+
});
|
|
110
|
+
/**
|
|
111
|
+
* Paginated devices response schema
|
|
112
|
+
*/
|
|
113
|
+
export const DevicesResponseSchema = t.Object({
|
|
114
|
+
devices: t.Array(DeviceSchema),
|
|
115
|
+
pagination: t.Object({
|
|
116
|
+
page: t.Integer({ minimum: 1 }),
|
|
117
|
+
limit: t.Integer({ minimum: 1 }),
|
|
118
|
+
total: t.Integer({ minimum: 0 }),
|
|
119
|
+
total_pages: t.Integer({ minimum: 0 }),
|
|
120
|
+
}),
|
|
121
|
+
});
|
|
122
|
+
/**
|
|
123
|
+
* Single device response schema
|
|
124
|
+
*/
|
|
125
|
+
export const DeviceResponseSchema = t.Object({
|
|
126
|
+
success: t.Literal(true),
|
|
127
|
+
data: DeviceSchema,
|
|
128
|
+
});
|
|
129
|
+
/**
|
|
130
|
+
* Device error response schema
|
|
131
|
+
* Discriminated union by error code
|
|
132
|
+
*/
|
|
133
|
+
export const DeviceErrorSchema = t.Union([
|
|
134
|
+
t.Object({
|
|
135
|
+
code: t.Literal("DEVICE_NOT_FOUND"),
|
|
136
|
+
message: t.String(),
|
|
137
|
+
}),
|
|
138
|
+
t.Object({
|
|
139
|
+
code: t.Literal("PROJECT_NOT_FOUND"),
|
|
140
|
+
message: t.String(),
|
|
141
|
+
}),
|
|
142
|
+
t.Object({
|
|
143
|
+
code: t.Literal("FORBIDDEN"),
|
|
144
|
+
message: t.String(),
|
|
145
|
+
}),
|
|
146
|
+
t.Object({
|
|
147
|
+
code: t.Literal("FETCH_FAILED"),
|
|
148
|
+
message: t.String(),
|
|
149
|
+
}),
|
|
150
|
+
t.Object({
|
|
151
|
+
code: t.Literal("INVALID_PARAMS"),
|
|
152
|
+
message: t.String(),
|
|
153
|
+
}),
|
|
154
|
+
]);
|
|
155
|
+
/**
|
|
156
|
+
* Device error response wrapper
|
|
157
|
+
*/
|
|
158
|
+
export const DeviceErrorResponseSchema = t.Object({
|
|
159
|
+
success: t.Literal(false),
|
|
160
|
+
error: DeviceErrorSchema,
|
|
161
|
+
});
|
|
162
|
+
/**
|
|
163
|
+
* Device request response schema
|
|
164
|
+
*/
|
|
165
|
+
export const DeviceRequestResponseSchema = t.Union([DeviceResponseSchema, DeviceErrorResponseSchema]);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./schemas";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./schemas";
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { EnvironmentTypeEnum } from "@teardown/types";
|
|
2
|
+
import { type Static } from "elysia";
|
|
3
|
+
import type { AssertSchemaCompatibleWithInsert, AssertSchemaCompatibleWithRow, AssertSchemaCompatibleWithUpdate, AssertTrue } from "../../common";
|
|
4
|
+
/**
|
|
5
|
+
* Environment type enum (re-exported for backward compatibility)
|
|
6
|
+
* @deprecated Use EnvironmentTypeEnum from @teardown/types instead
|
|
7
|
+
*/
|
|
8
|
+
export { EnvironmentTypeEnum as EnvironmentType };
|
|
9
|
+
/**
|
|
10
|
+
* Environment schema
|
|
11
|
+
* Represents an environment within a project
|
|
12
|
+
*/
|
|
13
|
+
export declare const EnvironmentSchema: import("@sinclair/typebox").TObject<{
|
|
14
|
+
id: import("@sinclair/typebox").TString;
|
|
15
|
+
project_id: import("@sinclair/typebox").TString;
|
|
16
|
+
name: import("@sinclair/typebox").TString;
|
|
17
|
+
slug: import("@sinclair/typebox").TString;
|
|
18
|
+
type: import("@sinclair/typebox").TEnum<typeof EnvironmentTypeEnum>;
|
|
19
|
+
created_at: import("@sinclair/typebox").TString;
|
|
20
|
+
updated_at: import("@sinclair/typebox").TString;
|
|
21
|
+
}>;
|
|
22
|
+
/**
|
|
23
|
+
* Parse and validate an EnvironmentTypeEnum value
|
|
24
|
+
* Uses a switch statement to ensure type safety and runtime validation
|
|
25
|
+
* @param value - The value to parse
|
|
26
|
+
* @returns The validated EnvironmentTypeEnum value
|
|
27
|
+
* @throws Error if the value is not a valid EnvironmentTypeEnum
|
|
28
|
+
*/
|
|
29
|
+
export declare function parseEnvironmentTypeEnum(value: unknown): EnvironmentTypeEnum;
|
|
30
|
+
/**
|
|
31
|
+
* Create environment schema
|
|
32
|
+
* Used for creating new environments
|
|
33
|
+
*/
|
|
34
|
+
export declare const CreateEnvironmentSchema: import("@sinclair/typebox").TObject<{
|
|
35
|
+
project_id: import("@sinclair/typebox").TString;
|
|
36
|
+
name: import("@sinclair/typebox").TString;
|
|
37
|
+
slug: import("@sinclair/typebox").TString;
|
|
38
|
+
type: import("@sinclair/typebox").TEnum<typeof EnvironmentTypeEnum>;
|
|
39
|
+
}>;
|
|
40
|
+
/**
|
|
41
|
+
* Update environment schema
|
|
42
|
+
* Used for updating existing environments
|
|
43
|
+
*/
|
|
44
|
+
export declare const UpdateEnvironmentSchema: import("@sinclair/typebox").TObject<{
|
|
45
|
+
name: import("@sinclair/typebox").TString;
|
|
46
|
+
type: import("@sinclair/typebox").TEnum<typeof EnvironmentTypeEnum>;
|
|
47
|
+
}>;
|
|
48
|
+
/**
|
|
49
|
+
* TypeScript types inferred from schemas
|
|
50
|
+
*/
|
|
51
|
+
export type Environment = Static<typeof EnvironmentSchema>;
|
|
52
|
+
export type CreateEnvironment = Static<typeof CreateEnvironmentSchema>;
|
|
53
|
+
export type UpdateEnvironment = Static<typeof UpdateEnvironmentSchema>;
|
|
54
|
+
export type _CheckEnvironmentRow = AssertTrue<AssertSchemaCompatibleWithRow<Environment, "environments">>;
|
|
55
|
+
export type _CheckCreateEnvironment = AssertTrue<AssertSchemaCompatibleWithInsert<CreateEnvironment, "environments">>;
|
|
56
|
+
export type _CheckUpdateEnvironment = AssertTrue<AssertSchemaCompatibleWithUpdate<UpdateEnvironment, "environments">>;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { EnvironmentTypeEnum } from "@teardown/types";
|
|
2
|
+
import { t } from "elysia";
|
|
3
|
+
/**
|
|
4
|
+
* Environment type enum (re-exported for backward compatibility)
|
|
5
|
+
* @deprecated Use EnvironmentTypeEnum from @teardown/types instead
|
|
6
|
+
*/
|
|
7
|
+
export { EnvironmentTypeEnum as EnvironmentType };
|
|
8
|
+
/**
|
|
9
|
+
* Environment schema
|
|
10
|
+
* Represents an environment within a project
|
|
11
|
+
*/
|
|
12
|
+
export const EnvironmentSchema = t.Object({
|
|
13
|
+
id: t.String({ format: "uuid" }),
|
|
14
|
+
project_id: t.String({ format: "uuid" }),
|
|
15
|
+
name: t.String({ minLength: 1 }),
|
|
16
|
+
slug: t.String({ minLength: 1 }),
|
|
17
|
+
type: t.Enum(EnvironmentTypeEnum),
|
|
18
|
+
created_at: t.String(),
|
|
19
|
+
updated_at: t.String(),
|
|
20
|
+
});
|
|
21
|
+
/**
|
|
22
|
+
* Parse and validate an EnvironmentTypeEnum value
|
|
23
|
+
* Uses a switch statement to ensure type safety and runtime validation
|
|
24
|
+
* @param value - The value to parse
|
|
25
|
+
* @returns The validated EnvironmentTypeEnum value
|
|
26
|
+
* @throws Error if the value is not a valid EnvironmentTypeEnum
|
|
27
|
+
*/
|
|
28
|
+
export function parseEnvironmentTypeEnum(value) {
|
|
29
|
+
switch (value) {
|
|
30
|
+
case EnvironmentTypeEnum.DEVELOPMENT:
|
|
31
|
+
return EnvironmentTypeEnum.DEVELOPMENT;
|
|
32
|
+
case EnvironmentTypeEnum.STAGING:
|
|
33
|
+
return EnvironmentTypeEnum.STAGING;
|
|
34
|
+
case EnvironmentTypeEnum.PRODUCTION:
|
|
35
|
+
return EnvironmentTypeEnum.PRODUCTION;
|
|
36
|
+
default:
|
|
37
|
+
throw new Error(`Invalid EnvironmentTypeEnum value: ${value}. Expected one of: ${Object.values(EnvironmentTypeEnum).join(", ")}`);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Create environment schema
|
|
42
|
+
* Used for creating new environments
|
|
43
|
+
*/
|
|
44
|
+
export const CreateEnvironmentSchema = t.Object({
|
|
45
|
+
project_id: t.String({ format: "uuid" }),
|
|
46
|
+
name: t.String({ minLength: 1 }),
|
|
47
|
+
slug: t.String({ minLength: 1 }),
|
|
48
|
+
type: t.Enum(EnvironmentTypeEnum),
|
|
49
|
+
});
|
|
50
|
+
/**
|
|
51
|
+
* Update environment schema
|
|
52
|
+
* Used for updating existing environments
|
|
53
|
+
*/
|
|
54
|
+
export const UpdateEnvironmentSchema = t.Object({
|
|
55
|
+
name: t.String({ minLength: 1 }),
|
|
56
|
+
type: t.Enum(EnvironmentTypeEnum),
|
|
57
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./schemas";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./schemas";
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { type Static } from "elysia";
|
|
2
|
+
import type { AssertSchemaCompatibleWithRow, AssertTrue } from "../../common";
|
|
3
|
+
/**
|
|
4
|
+
* Event type enum
|
|
5
|
+
*/
|
|
6
|
+
export declare const EventTypeEnum: readonly ["action", "screen_view", "custom"];
|
|
7
|
+
export type EventType = (typeof EventTypeEnum)[number];
|
|
8
|
+
/**
|
|
9
|
+
* Single event schema
|
|
10
|
+
*/
|
|
11
|
+
export declare const EventSchema: import("@sinclair/typebox").TObject<{
|
|
12
|
+
/**
|
|
13
|
+
* Name of the event (required)
|
|
14
|
+
*/
|
|
15
|
+
event_name: import("@sinclair/typebox").TString;
|
|
16
|
+
/**
|
|
17
|
+
* Type of event
|
|
18
|
+
*/
|
|
19
|
+
event_type: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TLiteral<"action">, import("@sinclair/typebox").TLiteral<"screen_view">, import("@sinclair/typebox").TLiteral<"custom">]>;
|
|
20
|
+
/**
|
|
21
|
+
* Custom properties for the event (optional)
|
|
22
|
+
*/
|
|
23
|
+
properties: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TRecord<import("@sinclair/typebox").TString, import("@sinclair/typebox").TUnknown>>;
|
|
24
|
+
/**
|
|
25
|
+
* Client-side timestamp (optional, defaults to server time)
|
|
26
|
+
*/
|
|
27
|
+
timestamp: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
28
|
+
/**
|
|
29
|
+
* Session ID (optional, can come from header)
|
|
30
|
+
*/
|
|
31
|
+
session_id: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
32
|
+
/**
|
|
33
|
+
* Device ID (optional, can come from header)
|
|
34
|
+
*/
|
|
35
|
+
device_id: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
36
|
+
}>;
|
|
37
|
+
export type Event = Static<typeof EventSchema>;
|
|
38
|
+
/**
|
|
39
|
+
* Batch events request schema
|
|
40
|
+
* Accepts 1-100 events per request
|
|
41
|
+
*/
|
|
42
|
+
export declare const EventsRequestSchema: import("@sinclair/typebox").TObject<{
|
|
43
|
+
/**
|
|
44
|
+
* Array of events to ingest (1-100)
|
|
45
|
+
*/
|
|
46
|
+
events: import("@sinclair/typebox").TArray<import("@sinclair/typebox").TObject<{
|
|
47
|
+
/**
|
|
48
|
+
* Name of the event (required)
|
|
49
|
+
*/
|
|
50
|
+
event_name: import("@sinclair/typebox").TString;
|
|
51
|
+
/**
|
|
52
|
+
* Type of event
|
|
53
|
+
*/
|
|
54
|
+
event_type: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TLiteral<"action">, import("@sinclair/typebox").TLiteral<"screen_view">, import("@sinclair/typebox").TLiteral<"custom">]>;
|
|
55
|
+
/**
|
|
56
|
+
* Custom properties for the event (optional)
|
|
57
|
+
*/
|
|
58
|
+
properties: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TRecord<import("@sinclair/typebox").TString, import("@sinclair/typebox").TUnknown>>;
|
|
59
|
+
/**
|
|
60
|
+
* Client-side timestamp (optional, defaults to server time)
|
|
61
|
+
*/
|
|
62
|
+
timestamp: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
63
|
+
/**
|
|
64
|
+
* Session ID (optional, can come from header)
|
|
65
|
+
*/
|
|
66
|
+
session_id: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
67
|
+
/**
|
|
68
|
+
* Device ID (optional, can come from header)
|
|
69
|
+
*/
|
|
70
|
+
device_id: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
71
|
+
}>>;
|
|
72
|
+
/**
|
|
73
|
+
* Session ID (optional, applies to all events if not specified per-event)
|
|
74
|
+
*/
|
|
75
|
+
session_id: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
76
|
+
/**
|
|
77
|
+
* Device ID (optional, applies to all events if not specified per-event)
|
|
78
|
+
*/
|
|
79
|
+
device_id: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
80
|
+
}>;
|
|
81
|
+
export type EventsRequest = Static<typeof EventsRequestSchema>;
|
|
82
|
+
/**
|
|
83
|
+
* Events response schema
|
|
84
|
+
*/
|
|
85
|
+
export declare const EventsResponseSchema: import("@sinclair/typebox").TObject<{
|
|
86
|
+
success: import("@sinclair/typebox").TLiteral<true>;
|
|
87
|
+
data: import("@sinclair/typebox").TObject<{
|
|
88
|
+
/**
|
|
89
|
+
* IDs of created events
|
|
90
|
+
*/
|
|
91
|
+
event_ids: import("@sinclair/typebox").TArray<import("@sinclair/typebox").TString>;
|
|
92
|
+
/**
|
|
93
|
+
* Number of successfully processed events
|
|
94
|
+
*/
|
|
95
|
+
processed_count: import("@sinclair/typebox").TNumber;
|
|
96
|
+
/**
|
|
97
|
+
* Number of failed events
|
|
98
|
+
*/
|
|
99
|
+
failed_count: import("@sinclair/typebox").TNumber;
|
|
100
|
+
}>;
|
|
101
|
+
}>;
|
|
102
|
+
export type EventsResponse = Static<typeof EventsResponseSchema>;
|
|
103
|
+
/**
|
|
104
|
+
* Events error response schema
|
|
105
|
+
*/
|
|
106
|
+
export declare const EventsErrorResponseSchema: import("@sinclair/typebox").TObject<{
|
|
107
|
+
success: import("@sinclair/typebox").TLiteral<false>;
|
|
108
|
+
error: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TObject<{
|
|
109
|
+
code: import("@sinclair/typebox").TLiteral<"MISSING_ORG_ID">;
|
|
110
|
+
message: import("@sinclair/typebox").TString;
|
|
111
|
+
}>, import("@sinclair/typebox").TObject<{
|
|
112
|
+
code: import("@sinclair/typebox").TLiteral<"MISSING_PROJECT_ID">;
|
|
113
|
+
message: import("@sinclair/typebox").TString;
|
|
114
|
+
}>, import("@sinclair/typebox").TObject<{
|
|
115
|
+
code: import("@sinclair/typebox").TLiteral<"MISSING_ENVIRONMENT_SLUG">;
|
|
116
|
+
message: import("@sinclair/typebox").TString;
|
|
117
|
+
}>, import("@sinclair/typebox").TObject<{
|
|
118
|
+
code: import("@sinclair/typebox").TLiteral<"MISSING_DEVICE_ID">;
|
|
119
|
+
message: import("@sinclair/typebox").TString;
|
|
120
|
+
}>, import("@sinclair/typebox").TObject<{
|
|
121
|
+
code: import("@sinclair/typebox").TLiteral<"EVENTS_PROCESSING_FAILED">;
|
|
122
|
+
message: import("@sinclair/typebox").TString;
|
|
123
|
+
}>, import("@sinclair/typebox").TObject<{
|
|
124
|
+
code: import("@sinclair/typebox").TLiteral<"INVALID_SESSION">;
|
|
125
|
+
message: import("@sinclair/typebox").TString;
|
|
126
|
+
}>, import("@sinclair/typebox").TObject<{
|
|
127
|
+
code: import("@sinclair/typebox").TLiteral<"INVALID_DEVICE">;
|
|
128
|
+
message: import("@sinclair/typebox").TString;
|
|
129
|
+
}>, import("@sinclair/typebox").TObject<{
|
|
130
|
+
code: import("@sinclair/typebox").TLiteral<"BATCH_SIZE_EXCEEDED">;
|
|
131
|
+
message: import("@sinclair/typebox").TString;
|
|
132
|
+
}>, import("@sinclair/typebox").TObject<{
|
|
133
|
+
code: import("@sinclair/typebox").TLiteral<"VALIDATION_ERROR">;
|
|
134
|
+
message: import("@sinclair/typebox").TString;
|
|
135
|
+
}>]>;
|
|
136
|
+
}>;
|
|
137
|
+
export type EventsErrorResponse = Static<typeof EventsErrorResponseSchema>;
|
|
138
|
+
export type _CheckEventRow = AssertTrue<AssertSchemaCompatibleWithRow<Event, "events">>;
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { t } from "elysia";
|
|
2
|
+
/**
|
|
3
|
+
* Event type enum
|
|
4
|
+
*/
|
|
5
|
+
export const EventTypeEnum = ["action", "screen_view", "custom"];
|
|
6
|
+
/**
|
|
7
|
+
* Single event schema
|
|
8
|
+
*/
|
|
9
|
+
export const EventSchema = t.Object({
|
|
10
|
+
/**
|
|
11
|
+
* Name of the event (required)
|
|
12
|
+
*/
|
|
13
|
+
event_name: t.String({ minLength: 1, error: "event_name is required" }),
|
|
14
|
+
/**
|
|
15
|
+
* Type of event
|
|
16
|
+
*/
|
|
17
|
+
event_type: t.Union([t.Literal("action"), t.Literal("screen_view"), t.Literal("custom")], { default: "custom" }),
|
|
18
|
+
/**
|
|
19
|
+
* Custom properties for the event (optional)
|
|
20
|
+
*/
|
|
21
|
+
properties: t.Optional(t.Record(t.String(), t.Unknown())),
|
|
22
|
+
/**
|
|
23
|
+
* Client-side timestamp (optional, defaults to server time)
|
|
24
|
+
*/
|
|
25
|
+
timestamp: t.Optional(t.String()),
|
|
26
|
+
/**
|
|
27
|
+
* Session ID (optional, can come from header)
|
|
28
|
+
*/
|
|
29
|
+
session_id: t.Optional(t.String({ format: "uuid" })),
|
|
30
|
+
/**
|
|
31
|
+
* Device ID (optional, can come from header)
|
|
32
|
+
*/
|
|
33
|
+
device_id: t.Optional(t.String()),
|
|
34
|
+
});
|
|
35
|
+
/**
|
|
36
|
+
* Batch events request schema
|
|
37
|
+
* Accepts 1-100 events per request
|
|
38
|
+
*/
|
|
39
|
+
export const EventsRequestSchema = t.Object({
|
|
40
|
+
/**
|
|
41
|
+
* Array of events to ingest (1-100)
|
|
42
|
+
*/
|
|
43
|
+
events: t.Array(EventSchema, { minItems: 1, maxItems: 100, error: "At least one event is required, maximum 100" }),
|
|
44
|
+
/**
|
|
45
|
+
* Session ID (optional, applies to all events if not specified per-event)
|
|
46
|
+
*/
|
|
47
|
+
session_id: t.Optional(t.String({ format: "uuid" })),
|
|
48
|
+
/**
|
|
49
|
+
* Device ID (optional, applies to all events if not specified per-event)
|
|
50
|
+
*/
|
|
51
|
+
device_id: t.Optional(t.String()),
|
|
52
|
+
});
|
|
53
|
+
/**
|
|
54
|
+
* Events response schema
|
|
55
|
+
*/
|
|
56
|
+
export const EventsResponseSchema = t.Object({
|
|
57
|
+
success: t.Literal(true),
|
|
58
|
+
data: t.Object({
|
|
59
|
+
/**
|
|
60
|
+
* IDs of created events
|
|
61
|
+
*/
|
|
62
|
+
event_ids: t.Array(t.String()),
|
|
63
|
+
/**
|
|
64
|
+
* Number of successfully processed events
|
|
65
|
+
*/
|
|
66
|
+
processed_count: t.Number(),
|
|
67
|
+
/**
|
|
68
|
+
* Number of failed events
|
|
69
|
+
*/
|
|
70
|
+
failed_count: t.Number(),
|
|
71
|
+
}),
|
|
72
|
+
});
|
|
73
|
+
/**
|
|
74
|
+
* Events error response schema
|
|
75
|
+
*/
|
|
76
|
+
export const EventsErrorResponseSchema = t.Object({
|
|
77
|
+
success: t.Literal(false),
|
|
78
|
+
error: t.Union([
|
|
79
|
+
t.Object({
|
|
80
|
+
code: t.Literal("MISSING_ORG_ID"),
|
|
81
|
+
message: t.String(),
|
|
82
|
+
}),
|
|
83
|
+
t.Object({
|
|
84
|
+
code: t.Literal("MISSING_PROJECT_ID"),
|
|
85
|
+
message: t.String(),
|
|
86
|
+
}),
|
|
87
|
+
t.Object({
|
|
88
|
+
code: t.Literal("MISSING_ENVIRONMENT_SLUG"),
|
|
89
|
+
message: t.String(),
|
|
90
|
+
}),
|
|
91
|
+
t.Object({
|
|
92
|
+
code: t.Literal("MISSING_DEVICE_ID"),
|
|
93
|
+
message: t.String(),
|
|
94
|
+
}),
|
|
95
|
+
t.Object({
|
|
96
|
+
code: t.Literal("EVENTS_PROCESSING_FAILED"),
|
|
97
|
+
message: t.String(),
|
|
98
|
+
}),
|
|
99
|
+
t.Object({
|
|
100
|
+
code: t.Literal("INVALID_SESSION"),
|
|
101
|
+
message: t.String(),
|
|
102
|
+
}),
|
|
103
|
+
t.Object({
|
|
104
|
+
code: t.Literal("INVALID_DEVICE"),
|
|
105
|
+
message: t.String(),
|
|
106
|
+
}),
|
|
107
|
+
t.Object({
|
|
108
|
+
code: t.Literal("BATCH_SIZE_EXCEEDED"),
|
|
109
|
+
message: t.String(),
|
|
110
|
+
}),
|
|
111
|
+
t.Object({
|
|
112
|
+
code: t.Literal("VALIDATION_ERROR"),
|
|
113
|
+
message: t.String(),
|
|
114
|
+
}),
|
|
115
|
+
]),
|
|
116
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./schemas";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./schemas";
|