@teardown/schemas 0.1.0 → 0.1.2

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.
@@ -1,87 +1,87 @@
1
+ import { Type } from "@sinclair/typebox";
1
2
  import { DevicePlatformEnum } from "@teardown/types";
2
- import { t } from "elysia";
3
3
  import { EmailSchema } from "../../common";
4
4
  export { DevicePlatformEnum };
5
5
  /**
6
6
  * Application info schema
7
7
  */
8
- export const ApplicationInfoSchema = t.Object({
9
- version: t.String({ error: "version is required" }),
10
- build_number: t.String({ error: "build_number is required" }),
8
+ export const ApplicationInfoSchema = Type.Object({
9
+ version: Type.String({ error: "version is required" }),
10
+ build_number: Type.String({ error: "build_number is required" }),
11
11
  });
12
12
  /**
13
13
  * OS info schema
14
14
  */
15
- export const OSInfoSchema = t.Object({
15
+ export const OSInfoSchema = Type.Object({
16
16
  /**
17
17
  * Device platform
18
18
  */
19
- platform: t.Enum(DevicePlatformEnum, { error: "platform is required" }),
19
+ platform: Type.Enum(DevicePlatformEnum, { error: "platform is required" }),
20
20
  /**
21
21
  * OS name
22
22
  */
23
- name: t.String({ error: "name is required" }),
23
+ name: Type.String({ error: "name is required" }),
24
24
  /**
25
25
  * OS version
26
26
  */
27
- version: t.String({ error: "version is required" }),
27
+ version: Type.String({ error: "version is required" }),
28
28
  });
29
29
  /**
30
30
  * Hardware info schema
31
31
  */
32
- export const HardwareInfoSchema = t.Object({
33
- device_name: t.String({ error: "device_name is required" }),
34
- device_type: t.String({ error: "device_type is required" }),
35
- device_brand: t.String({ error: "device_brand is required" }),
36
- });
37
- export const EmergencyLaunchSchema = t.Union([
38
- t.Object({
39
- is_emergency_launch: t.Literal(true),
40
- reason: t.String({ error: "reason is required when is_emergency_launch is true" }),
32
+ export const HardwareInfoSchema = Type.Object({
33
+ device_name: Type.String({ error: "device_name is required" }),
34
+ device_type: Type.String({ error: "device_type is required" }),
35
+ device_brand: Type.String({ error: "device_brand is required" }),
36
+ });
37
+ export const EmergencyLaunchSchema = Type.Union([
38
+ Type.Object({
39
+ is_emergency_launch: Type.Literal(true),
40
+ reason: Type.String({ error: "reason is required when is_emergency_launch is true" }),
41
41
  }),
42
- t.Object({
43
- is_emergency_launch: t.Literal(false),
44
- reason: t.Optional(t.Never()),
42
+ Type.Object({
43
+ is_emergency_launch: Type.Literal(false),
44
+ reason: Type.Optional(Type.Never()),
45
45
  }),
46
46
  ]);
47
47
  /**
48
48
  * Update info schema
49
49
  */
50
- export const DeviceUpdateInfoSchema = t.Object({
51
- is_enabled: t.Boolean(),
52
- update_id: t.String({ error: "update_id is required" }),
53
- update_channel: t.String({ error: "update_channel is required" }),
54
- runtime_version: t.String({ error: "runtime_version is required" }),
50
+ export const DeviceUpdateInfoSchema = Type.Object({
51
+ is_enabled: Type.Boolean(),
52
+ update_id: Type.String({ error: "update_id is required" }),
53
+ update_channel: Type.String({ error: "update_channel is required" }),
54
+ runtime_version: Type.String({ error: "runtime_version is required" }),
55
55
  emergency_launch: EmergencyLaunchSchema,
56
- is_embedded_launch: t.Boolean({ error: "is_embedded_launch is required" }),
57
- created_at: t.String(),
58
- });
59
- export var NotificationPlatform;
60
- (function (NotificationPlatform) {
61
- NotificationPlatform["APNS"] = "APNS";
62
- NotificationPlatform["FCM"] = "FCM";
63
- NotificationPlatform["EXPO"] = "EXPO";
64
- })(NotificationPlatform || (NotificationPlatform = {}));
56
+ is_embedded_launch: Type.Boolean({ error: "is_embedded_launch is required" }),
57
+ created_at: Type.String(),
58
+ });
59
+ export var NotificationPlatformEnum;
60
+ (function (NotificationPlatformEnum) {
61
+ NotificationPlatformEnum["APNS"] = "APNS";
62
+ NotificationPlatformEnum["FCM"] = "FCM";
63
+ NotificationPlatformEnum["EXPO"] = "EXPO";
64
+ })(NotificationPlatformEnum || (NotificationPlatformEnum = {}));
65
65
  /**
66
66
  * Push notification info schema
67
67
  */
68
- export const PushNotificationInfoSchema = t.Object({
69
- enabled: t.Boolean({ error: "enabled is required" }),
70
- granted: t.Boolean({ error: "granted is required" }),
71
- token: t.Union([t.String({ error: "token is required" }), t.Null()]),
72
- platform: t.Enum(NotificationPlatform, { error: "platform is required" }),
68
+ export const PushNotificationInfoSchema = Type.Object({
69
+ enabled: Type.Boolean({ error: "enabled is required" }),
70
+ granted: Type.Boolean({ error: "granted is required" }),
71
+ token: Type.Union([Type.String({ error: "token is required" }), Type.Null()]),
72
+ platform: Type.Enum(NotificationPlatformEnum, { error: "platform is required" }),
73
73
  });
74
- export const NotificationsInfoSchema = t.Object({
74
+ export const NotificationsInfoSchema = Type.Object({
75
75
  push: PushNotificationInfoSchema,
76
76
  });
77
77
  /**
78
78
  * Device info schema
79
79
  */
80
- export const DeviceInfoSchema = t.Object({
80
+ export const DeviceInfoSchema = Type.Object({
81
81
  /**
82
82
  * Timestamp of collection on device (optional, generated server-side if not provided)
83
83
  */
84
- timestamp: t.Optional(t.Date({ error: "timestamp is required" })),
84
+ timestamp: Type.Optional(Type.Date({ error: "timestamp is required" })),
85
85
  /**
86
86
  * Application info, required
87
87
  */
@@ -89,7 +89,7 @@ export const DeviceInfoSchema = t.Object({
89
89
  /**
90
90
  * Update info (optional) - not all builds will have an update
91
91
  */
92
- update: t.Union([DeviceUpdateInfoSchema, t.Null()]),
92
+ update: Type.Union([DeviceUpdateInfoSchema, Type.Null()]),
93
93
  /**
94
94
  * Hardware info, required
95
95
  */
@@ -107,18 +107,18 @@ export const DeviceInfoSchema = t.Object({
107
107
  * Persona info schema (optional fields)
108
108
  * Matches personas table structure
109
109
  */
110
- export const PersonaInfoSchema = t.Object({
111
- user_id: t.Optional(t.String({ error: "user_id is required" })),
112
- email: t.Optional(EmailSchema),
113
- name: t.Optional(t.String({ error: "name is required" })),
110
+ export const PersonaInfoSchema = Type.Object({
111
+ user_id: Type.Optional(Type.String({ error: "user_id is required" })),
112
+ email: Type.Optional(EmailSchema),
113
+ name: Type.Optional(Type.String({ error: "name is required" })),
114
114
  });
115
115
  /**
116
116
  * Identify request schema
117
117
  * Ties a device to a persona with optional persona data
118
118
  */
119
- export const IdentifyRequestSchema = t.Object({
119
+ export const IdentifyRequestSchema = Type.Object({
120
120
  device: DeviceInfoSchema,
121
- persona: t.Optional(PersonaInfoSchema),
121
+ persona: Type.Optional(PersonaInfoSchema),
122
122
  });
123
123
  export var IdentifyVersionStatusEnum;
124
124
  (function (IdentifyVersionStatusEnum) {
@@ -139,83 +139,83 @@ export var IdentifyVersionStatusEnum;
139
139
  */
140
140
  IdentifyVersionStatusEnum["DISABLED"] = "DISABLED";
141
141
  })(IdentifyVersionStatusEnum || (IdentifyVersionStatusEnum = {}));
142
- export const UpdateInfoSchema = t.Object({
143
- version: t.String({ error: "version is required" }),
144
- build: t.String({ error: "build is required" }),
145
- update_id: t.String({ error: "update_id is required" }),
146
- effective_date: t.Date({ error: "effective_date is required" }),
147
- });
148
- export const UpToDateInfoSchema = t.Object({
149
- status: t.Literal(IdentifyVersionStatusEnum.UP_TO_DATE),
150
- update: t.Null(),
151
- });
152
- export const UpdateRequiredInfoSchema = t.Object({
153
- status: t.Literal(IdentifyVersionStatusEnum.UPDATE_REQUIRED),
142
+ export const UpdateInfoSchema = Type.Object({
143
+ version: Type.String({ error: "version is required" }),
144
+ build: Type.String({ error: "build is required" }),
145
+ update_id: Type.String({ error: "update_id is required" }),
146
+ effective_date: Type.Date({ error: "effective_date is required" }),
147
+ });
148
+ export const UpToDateInfoSchema = Type.Object({
149
+ status: Type.Literal(IdentifyVersionStatusEnum.UP_TO_DATE),
150
+ update: Type.Null(),
151
+ });
152
+ export const UpdateRequiredInfoSchema = Type.Object({
153
+ status: Type.Literal(IdentifyVersionStatusEnum.UPDATE_REQUIRED),
154
154
  update: UpdateInfoSchema,
155
155
  });
156
- export const UpdateAvailableInfoSchema = t.Object({
157
- status: t.Literal(IdentifyVersionStatusEnum.UPDATE_AVAILABLE),
156
+ export const UpdateAvailableInfoSchema = Type.Object({
157
+ status: Type.Literal(IdentifyVersionStatusEnum.UPDATE_AVAILABLE),
158
158
  update: UpdateInfoSchema,
159
159
  });
160
- export const VersionInfoSchema = t.Object({
160
+ export const VersionInfoSchema = Type.Object({
161
161
  /**
162
162
  * The status of the version
163
163
  */
164
- status: t.Enum(IdentifyVersionStatusEnum, { error: "status is required" }),
165
- update: t.Optional(t.Union([UpdateAvailableInfoSchema, t.Null()])),
164
+ status: Type.Enum(IdentifyVersionStatusEnum, { error: "status is required" }),
165
+ update: Type.Optional(Type.Union([UpdateAvailableInfoSchema, Type.Null()])),
166
166
  });
167
167
  /**
168
168
  * Identify response schema
169
169
  */
170
- export const IdentifyResponseSchema = t.Object({
171
- success: t.Literal(true),
172
- data: t.Object({
173
- session_id: t.String({ error: "session_id is required" }),
174
- device_id: t.String({ error: "device_id is required" }),
175
- persona_id: t.String({ error: "persona_id is required" }),
176
- token: t.String({ error: "token is required" }), // JWT token for session authentication
170
+ export const IdentifyResponseSchema = Type.Object({
171
+ success: Type.Literal(true),
172
+ data: Type.Object({
173
+ session_id: Type.String({ error: "session_id is required" }),
174
+ device_id: Type.String({ error: "device_id is required" }),
175
+ persona_id: Type.String({ error: "persona_id is required" }),
176
+ token: Type.String({ error: "token is required" }), // JWT token for session authentication
177
177
  version_info: VersionInfoSchema,
178
178
  }),
179
179
  });
180
- export const IdentifyErrorResponseSchema = t.Object({
181
- success: t.Literal(false),
182
- error: t.Union([
183
- t.Object({
184
- code: t.Literal("MISSING_ORG_ID"),
185
- message: t.String(),
180
+ export const IdentifyErrorResponseSchema = Type.Object({
181
+ success: Type.Literal(false),
182
+ error: Type.Union([
183
+ Type.Object({
184
+ code: Type.Literal("MISSING_ORG_ID"),
185
+ message: Type.String(),
186
186
  }),
187
- t.Object({
188
- code: t.Literal("MISSING_PROJECT_ID"),
189
- message: t.String(),
187
+ Type.Object({
188
+ code: Type.Literal("MISSING_PROJECT_ID"),
189
+ message: Type.String(),
190
190
  }),
191
- t.Object({
192
- code: t.Literal("MISSING_ENVIRONMENT_SLUG"),
193
- message: t.String(),
191
+ Type.Object({
192
+ code: Type.Literal("MISSING_ENVIRONMENT_SLUG"),
193
+ message: Type.String(),
194
194
  }),
195
- t.Object({
196
- code: t.Literal("MISSING_DEVICE_ID"),
197
- message: t.String(),
195
+ Type.Object({
196
+ code: Type.Literal("MISSING_DEVICE_ID"),
197
+ message: Type.String(),
198
198
  }),
199
- t.Object({
200
- code: t.Literal("IDENTIFY_FAILED"),
201
- message: t.String(),
199
+ Type.Object({
200
+ code: Type.Literal("IDENTIFY_FAILED"),
201
+ message: Type.String(),
202
202
  }),
203
- t.Object({
204
- code: t.Literal("NO_SESSION_ID_GENERATED"),
205
- message: t.String(),
203
+ Type.Object({
204
+ code: Type.Literal("NO_SESSION_ID_GENERATED"),
205
+ message: Type.String(),
206
206
  }),
207
- t.Object({
208
- code: t.Literal("NO_DEVICE_ID_GENERATED"),
209
- message: t.String(),
207
+ Type.Object({
208
+ code: Type.Literal("NO_DEVICE_ID_GENERATED"),
209
+ message: Type.String(),
210
210
  }),
211
- t.Object({
212
- code: t.Literal("NO_PERSONA_ID_GENERATED"),
213
- message: t.String(),
211
+ Type.Object({
212
+ code: Type.Literal("NO_PERSONA_ID_GENERATED"),
213
+ message: Type.String(),
214
214
  }),
215
215
  ]),
216
216
  });
217
- export const ValidationErrorSchema = t.Object({
218
- success: t.Literal(false),
219
- error: t.Literal("VALIDATION"),
220
- message: t.String(),
217
+ export const ValidationErrorSchema = Type.Object({
218
+ success: Type.Literal(false),
219
+ error: Type.Literal("VALIDATION"),
220
+ message: Type.String(),
221
221
  });
@@ -1,4 +1,4 @@
1
- import { type Static } from "elysia";
1
+ import { type Static } from "@sinclair/typebox";
2
2
  /**
3
3
  * User schema
4
4
  * Represents Supabase Auth user structure
@@ -31,10 +31,10 @@ export type MeResponse = Static<typeof MeResponseSchema>;
31
31
  export declare const MeOrgsResponseSchema: import("@sinclair/typebox").TObject<{
32
32
  orgs: import("@sinclair/typebox").TArray<import("@sinclair/typebox").TObject<{
33
33
  id: import("@sinclair/typebox").TString;
34
- org_id: import("@sinclair/typebox").TIntersect<[import("@sinclair/typebox").TString, import("@sinclair/typebox").TString]>;
35
34
  user_id: import("@sinclair/typebox").TString;
36
35
  created_at: import("@sinclair/typebox").TString;
37
36
  updated_at: import("@sinclair/typebox").TString;
37
+ org_id: import("@sinclair/typebox").TIntersect<[import("@sinclair/typebox").TString, import("@sinclair/typebox").TString]>;
38
38
  role: import("@sinclair/typebox").TEnum<typeof import("@teardown/types").OrgRoleTypeEnum>;
39
39
  org_name: import("@sinclair/typebox").TString;
40
40
  org_slug: import("@sinclair/typebox").TString;
@@ -1,15 +1,15 @@
1
- import { t } from "elysia";
1
+ import { Type } from "@sinclair/typebox";
2
2
  import { OrgRoleWithOrgSchema } from "../orgs/schemas";
3
3
  /**
4
4
  * User schema
5
5
  * Represents Supabase Auth user structure
6
6
  */
7
- export const UserSchema = t.Object({
8
- id: t.String({ format: "uuid" }),
9
- email: t.Optional(t.String({ format: "email" })),
10
- app_metadata: t.Record(t.String(), t.Unknown()),
11
- user_metadata: t.Record(t.String(), t.Unknown()),
12
- created_at: t.String(),
7
+ export const UserSchema = Type.Object({
8
+ id: Type.String({ format: "uuid" }),
9
+ email: Type.Optional(Type.String({ format: "email" })),
10
+ app_metadata: Type.Record(Type.String(), Type.Unknown()),
11
+ user_metadata: Type.Record(Type.String(), Type.Unknown()),
12
+ created_at: Type.String(),
13
13
  // id: string
14
14
  // app_metadata: UserAppMetadata
15
15
  // user_metadata: UserMetadata
@@ -39,38 +39,38 @@ export const UserSchema = t.Object({
39
39
  /**
40
40
  * Me response schema
41
41
  */
42
- export const MeResponseSchema = t.Object({
42
+ export const MeResponseSchema = Type.Object({
43
43
  user: UserSchema,
44
44
  });
45
45
  /**
46
46
  * Me orgs response schema
47
47
  * Reuses OrgRoleWithOrgSchema from orgs module
48
48
  */
49
- export const MeOrgsResponseSchema = t.Object({
50
- orgs: t.Array(OrgRoleWithOrgSchema),
49
+ export const MeOrgsResponseSchema = Type.Object({
50
+ orgs: Type.Array(OrgRoleWithOrgSchema),
51
51
  });
52
52
  /**
53
53
  * Me error response schema
54
54
  * Discriminated union by error code
55
55
  */
56
- export const MeErrorSchema = t.Union([
57
- t.Object({
58
- code: t.Literal("UNAUTHORIZED"),
59
- message: t.String(),
56
+ export const MeErrorSchema = Type.Union([
57
+ Type.Object({
58
+ code: Type.Literal("UNAUTHORIZED"),
59
+ message: Type.String(),
60
60
  }),
61
- t.Object({
62
- code: t.Literal("USER_NOT_FOUND"),
63
- message: t.String(),
61
+ Type.Object({
62
+ code: Type.Literal("USER_NOT_FOUND"),
63
+ message: Type.String(),
64
64
  }),
65
- t.Object({
66
- code: t.Literal("FETCH_FAILED"),
67
- message: t.String(),
65
+ Type.Object({
66
+ code: Type.Literal("FETCH_FAILED"),
67
+ message: Type.String(),
68
68
  }),
69
69
  ]);
70
70
  /**
71
71
  * Me error response wrapper
72
72
  */
73
- export const MeErrorResponseSchema = t.Object({
74
- success: t.Literal(false),
73
+ export const MeErrorResponseSchema = Type.Object({
74
+ success: Type.Literal(false),
75
75
  error: MeErrorSchema,
76
76
  });
@@ -1,5 +1,5 @@
1
+ import { type Static } from "@sinclair/typebox";
1
2
  import { OrgRoleTypeEnum, OrgTypeEnum } from "@teardown/types";
2
- import { type Static } from "elysia";
3
3
  import { type AssertSchemaCompatibleWithInsert, type AssertSchemaCompatibleWithRow, type AssertSchemaCompatibleWithUpdate, type AssertTrue } from "../../common";
4
4
  export declare const OrgHeadersSchema: import("@sinclair/typebox").TObject<{
5
5
  "td-org-id": import("@sinclair/typebox").TString;
@@ -71,10 +71,10 @@ export type OrgRole = Static<typeof OrgRoleSchema>;
71
71
  */
72
72
  export declare const OrgRoleWithOrgSchema: import("@sinclair/typebox").TObject<{
73
73
  id: import("@sinclair/typebox").TString;
74
- org_id: import("@sinclair/typebox").TIntersect<[import("@sinclair/typebox").TString, import("@sinclair/typebox").TString]>;
75
74
  user_id: import("@sinclair/typebox").TString;
76
75
  created_at: import("@sinclair/typebox").TString;
77
76
  updated_at: import("@sinclair/typebox").TString;
77
+ org_id: import("@sinclair/typebox").TIntersect<[import("@sinclair/typebox").TString, import("@sinclair/typebox").TString]>;
78
78
  role: import("@sinclair/typebox").TEnum<typeof OrgRoleTypeEnum>;
79
79
  org_name: import("@sinclair/typebox").TString;
80
80
  org_slug: import("@sinclair/typebox").TString;
@@ -113,10 +113,10 @@ export declare const OrgResponseSchema: import("@sinclair/typebox").TObject<{
113
113
  data: import("@sinclair/typebox").TObject<{
114
114
  org: import("@sinclair/typebox").TObject<{
115
115
  id: import("@sinclair/typebox").TString;
116
- org_id: import("@sinclair/typebox").TIntersect<[import("@sinclair/typebox").TString, import("@sinclair/typebox").TString]>;
117
116
  user_id: import("@sinclair/typebox").TString;
118
117
  created_at: import("@sinclair/typebox").TString;
119
118
  updated_at: import("@sinclair/typebox").TString;
119
+ org_id: import("@sinclair/typebox").TIntersect<[import("@sinclair/typebox").TString, import("@sinclair/typebox").TString]>;
120
120
  role: import("@sinclair/typebox").TEnum<typeof OrgRoleTypeEnum>;
121
121
  org_name: import("@sinclair/typebox").TString;
122
122
  org_slug: import("@sinclair/typebox").TString;
@@ -239,10 +239,10 @@ export declare const OrgRequestResponseSchema: import("@sinclair/typebox").TUnio
239
239
  data: import("@sinclair/typebox").TObject<{
240
240
  org: import("@sinclair/typebox").TObject<{
241
241
  id: import("@sinclair/typebox").TString;
242
- org_id: import("@sinclair/typebox").TIntersect<[import("@sinclair/typebox").TString, import("@sinclair/typebox").TString]>;
243
242
  user_id: import("@sinclair/typebox").TString;
244
243
  created_at: import("@sinclair/typebox").TString;
245
244
  updated_at: import("@sinclair/typebox").TString;
245
+ org_id: import("@sinclair/typebox").TIntersect<[import("@sinclair/typebox").TString, import("@sinclair/typebox").TString]>;
246
246
  role: import("@sinclair/typebox").TEnum<typeof OrgRoleTypeEnum>;
247
247
  org_name: import("@sinclair/typebox").TString;
248
248
  org_slug: import("@sinclair/typebox").TString;