@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.
Files changed (61) hide show
  1. package/dist/common/index.d.ts +3 -0
  2. package/dist/common/index.js +3 -0
  3. package/dist/common/primitives.d.ts +11 -0
  4. package/dist/common/primitives.js +9 -0
  5. package/dist/common/responses.d.ts +27 -0
  6. package/dist/common/responses.js +13 -0
  7. package/dist/common/type-checks.d.ts +58 -0
  8. package/dist/common/type-checks.js +1 -0
  9. package/dist/index.d.ts +13 -0
  10. package/dist/index.js +14 -0
  11. package/dist/modules/analytics/index.d.ts +1 -0
  12. package/dist/modules/analytics/index.js +1 -0
  13. package/dist/modules/analytics/schemas.d.ts +239 -0
  14. package/dist/modules/analytics/schemas.js +136 -0
  15. package/dist/modules/builds/index.d.ts +1 -0
  16. package/dist/modules/builds/index.js +1 -0
  17. package/dist/modules/builds/schemas.d.ts +248 -0
  18. package/dist/modules/builds/schemas.js +137 -0
  19. package/dist/modules/devices/index.d.ts +1 -0
  20. package/dist/modules/devices/index.js +1 -0
  21. package/dist/modules/devices/schemas.d.ts +207 -0
  22. package/dist/modules/devices/schemas.js +165 -0
  23. package/dist/modules/environment/index.d.ts +1 -0
  24. package/dist/modules/environment/index.js +1 -0
  25. package/dist/modules/environment/schemas.d.ts +56 -0
  26. package/dist/modules/environment/schemas.js +57 -0
  27. package/dist/modules/events/index.d.ts +1 -0
  28. package/dist/modules/events/index.js +1 -0
  29. package/dist/modules/events/schemas.d.ts +138 -0
  30. package/dist/modules/events/schemas.js +116 -0
  31. package/dist/modules/identify/index.d.ts +1 -0
  32. package/dist/modules/identify/index.js +1 -0
  33. package/dist/modules/identify/schemas.d.ts +377 -0
  34. package/dist/modules/identify/schemas.js +221 -0
  35. package/dist/modules/index.d.ts +12 -0
  36. package/dist/modules/index.js +12 -0
  37. package/dist/modules/me/index.d.ts +1 -0
  38. package/dist/modules/me/index.js +1 -0
  39. package/dist/modules/me/schemas.d.ts +75 -0
  40. package/dist/modules/me/schemas.js +76 -0
  41. package/dist/modules/orgs/index.d.ts +1 -0
  42. package/dist/modules/orgs/index.js +1 -0
  43. package/dist/modules/orgs/schemas.d.ts +308 -0
  44. package/dist/modules/orgs/schemas.js +214 -0
  45. package/dist/modules/personas/index.d.ts +1 -0
  46. package/dist/modules/personas/index.js +1 -0
  47. package/dist/modules/personas/schemas.d.ts +170 -0
  48. package/dist/modules/personas/schemas.js +100 -0
  49. package/dist/modules/projects/index.d.ts +1 -0
  50. package/dist/modules/projects/index.js +1 -0
  51. package/dist/modules/projects/schemas.d.ts +222 -0
  52. package/dist/modules/projects/schemas.js +145 -0
  53. package/dist/modules/sessions/index.d.ts +1 -0
  54. package/dist/modules/sessions/index.js +1 -0
  55. package/dist/modules/sessions/schemas.d.ts +258 -0
  56. package/dist/modules/sessions/schemas.js +128 -0
  57. package/dist/modules/versions/index.d.ts +1 -0
  58. package/dist/modules/versions/index.js +1 -0
  59. package/dist/modules/versions/schemas.d.ts +248 -0
  60. package/dist/modules/versions/schemas.js +155 -0
  61. package/package.json +106 -0
@@ -0,0 +1,75 @@
1
+ import { type Static } from "elysia";
2
+ /**
3
+ * User schema
4
+ * Represents Supabase Auth user structure
5
+ */
6
+ export declare const UserSchema: import("@sinclair/typebox").TObject<{
7
+ id: import("@sinclair/typebox").TString;
8
+ email: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
9
+ app_metadata: import("@sinclair/typebox").TRecord<import("@sinclair/typebox").TString, import("@sinclair/typebox").TUnknown>;
10
+ user_metadata: import("@sinclair/typebox").TRecord<import("@sinclair/typebox").TString, import("@sinclair/typebox").TUnknown>;
11
+ created_at: import("@sinclair/typebox").TString;
12
+ }>;
13
+ export type User = Static<typeof UserSchema>;
14
+ /**
15
+ * Me response schema
16
+ */
17
+ export declare const MeResponseSchema: import("@sinclair/typebox").TObject<{
18
+ user: import("@sinclair/typebox").TObject<{
19
+ id: import("@sinclair/typebox").TString;
20
+ email: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
21
+ app_metadata: import("@sinclair/typebox").TRecord<import("@sinclair/typebox").TString, import("@sinclair/typebox").TUnknown>;
22
+ user_metadata: import("@sinclair/typebox").TRecord<import("@sinclair/typebox").TString, import("@sinclair/typebox").TUnknown>;
23
+ created_at: import("@sinclair/typebox").TString;
24
+ }>;
25
+ }>;
26
+ export type MeResponse = Static<typeof MeResponseSchema>;
27
+ /**
28
+ * Me orgs response schema
29
+ * Reuses OrgRoleWithOrgSchema from orgs module
30
+ */
31
+ export declare const MeOrgsResponseSchema: import("@sinclair/typebox").TObject<{
32
+ orgs: import("@sinclair/typebox").TArray<import("@sinclair/typebox").TObject<{
33
+ id: import("@sinclair/typebox").TString;
34
+ org_id: import("@sinclair/typebox").TIntersect<[import("@sinclair/typebox").TString, import("@sinclair/typebox").TString]>;
35
+ user_id: import("@sinclair/typebox").TString;
36
+ created_at: import("@sinclair/typebox").TString;
37
+ updated_at: import("@sinclair/typebox").TString;
38
+ role: import("@sinclair/typebox").TEnum<typeof import("@teardown/types").OrgRoleTypeEnum>;
39
+ org_name: import("@sinclair/typebox").TString;
40
+ org_slug: import("@sinclair/typebox").TString;
41
+ }>>;
42
+ }>;
43
+ export type MeOrgsResponse = Static<typeof MeOrgsResponseSchema>;
44
+ /**
45
+ * Me error response schema
46
+ * Discriminated union by error code
47
+ */
48
+ export declare const MeErrorSchema: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TObject<{
49
+ code: import("@sinclair/typebox").TLiteral<"UNAUTHORIZED">;
50
+ message: import("@sinclair/typebox").TString;
51
+ }>, import("@sinclair/typebox").TObject<{
52
+ code: import("@sinclair/typebox").TLiteral<"USER_NOT_FOUND">;
53
+ message: import("@sinclair/typebox").TString;
54
+ }>, import("@sinclair/typebox").TObject<{
55
+ code: import("@sinclair/typebox").TLiteral<"FETCH_FAILED">;
56
+ message: import("@sinclair/typebox").TString;
57
+ }>]>;
58
+ export type MeError = Static<typeof MeErrorSchema>;
59
+ /**
60
+ * Me error response wrapper
61
+ */
62
+ export declare const MeErrorResponseSchema: import("@sinclair/typebox").TObject<{
63
+ success: import("@sinclair/typebox").TLiteral<false>;
64
+ error: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TObject<{
65
+ code: import("@sinclair/typebox").TLiteral<"UNAUTHORIZED">;
66
+ message: import("@sinclair/typebox").TString;
67
+ }>, import("@sinclair/typebox").TObject<{
68
+ code: import("@sinclair/typebox").TLiteral<"USER_NOT_FOUND">;
69
+ message: import("@sinclair/typebox").TString;
70
+ }>, import("@sinclair/typebox").TObject<{
71
+ code: import("@sinclair/typebox").TLiteral<"FETCH_FAILED">;
72
+ message: import("@sinclair/typebox").TString;
73
+ }>]>;
74
+ }>;
75
+ export type MeErrorResponse = Static<typeof MeErrorResponseSchema>;
@@ -0,0 +1,76 @@
1
+ import { t } from "elysia";
2
+ import { OrgRoleWithOrgSchema } from "../orgs/schemas";
3
+ /**
4
+ * User schema
5
+ * Represents Supabase Auth user structure
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(),
13
+ // id: string
14
+ // app_metadata: UserAppMetadata
15
+ // user_metadata: UserMetadata
16
+ // aud: string
17
+ // confirmation_sent_at?: string
18
+ // recovery_sent_at?: string
19
+ // email_change_sent_at?: string
20
+ // new_email?: string
21
+ // new_phone?: string
22
+ // invited_at?: string
23
+ // action_link?: string
24
+ // email?: string
25
+ // phone?: string
26
+ // created_at: string
27
+ // confirmed_at?: string
28
+ // email_confirmed_at?: string
29
+ // phone_confirmed_at?: string
30
+ // last_sign_in_at?: string
31
+ // role?: string
32
+ // updated_at?: string
33
+ // identities?: UserIdentity[]
34
+ // is_anonymous?: boolean
35
+ // is_sso_user?: boolean
36
+ // factors?: (Factor<FactorType, 'verified'> | Factor<FactorType, 'unverified'>)[]
37
+ // deleted_at?: string
38
+ });
39
+ /**
40
+ * Me response schema
41
+ */
42
+ export const MeResponseSchema = t.Object({
43
+ user: UserSchema,
44
+ });
45
+ /**
46
+ * Me orgs response schema
47
+ * Reuses OrgRoleWithOrgSchema from orgs module
48
+ */
49
+ export const MeOrgsResponseSchema = t.Object({
50
+ orgs: t.Array(OrgRoleWithOrgSchema),
51
+ });
52
+ /**
53
+ * Me error response schema
54
+ * Discriminated union by error code
55
+ */
56
+ export const MeErrorSchema = t.Union([
57
+ t.Object({
58
+ code: t.Literal("UNAUTHORIZED"),
59
+ message: t.String(),
60
+ }),
61
+ t.Object({
62
+ code: t.Literal("USER_NOT_FOUND"),
63
+ message: t.String(),
64
+ }),
65
+ t.Object({
66
+ code: t.Literal("FETCH_FAILED"),
67
+ message: t.String(),
68
+ }),
69
+ ]);
70
+ /**
71
+ * Me error response wrapper
72
+ */
73
+ export const MeErrorResponseSchema = t.Object({
74
+ success: t.Literal(false),
75
+ error: MeErrorSchema,
76
+ });
@@ -0,0 +1 @@
1
+ export * from "./schemas";
@@ -0,0 +1 @@
1
+ export * from "./schemas";
@@ -0,0 +1,308 @@
1
+ import { OrgRoleTypeEnum, OrgTypeEnum } from "@teardown/types";
2
+ import { type Static } from "elysia";
3
+ import { type AssertSchemaCompatibleWithInsert, type AssertSchemaCompatibleWithRow, type AssertSchemaCompatibleWithUpdate, type AssertTrue } from "../../common";
4
+ export declare const OrgHeadersSchema: import("@sinclair/typebox").TObject<{
5
+ "td-org-id": import("@sinclair/typebox").TString;
6
+ }>;
7
+ export type OrgHeaders = Static<typeof OrgHeadersSchema>;
8
+ /**
9
+ * Helper to check if role is admin or owner
10
+ */
11
+ export declare function isAdminRole(role: string): boolean;
12
+ /**
13
+ * Helper to check if role is owner
14
+ */
15
+ export declare function isOwnerRole(role: string): boolean;
16
+ /**
17
+ * Parse and validate an OrgRoleTypeEnum value
18
+ * Uses a switch statement to ensure type safety and runtime validation
19
+ * @param value - The value to parse
20
+ * @returns The validated OrgRoleTypeEnum value
21
+ * @throws Error if the value is not a valid OrgRoleTypeEnum
22
+ */
23
+ export declare function parseOrgRoleTypeEnum(value: unknown): OrgRoleTypeEnum;
24
+ /**
25
+ * Parse and validate an OrgTypeEnum value
26
+ * Uses a switch statement to ensure type safety and runtime validation
27
+ * @param value - The value to parse
28
+ * @returns The validated OrgTypeEnum value
29
+ * @throws Error if the value is not a valid OrgTypeEnum
30
+ */
31
+ export declare function parseOrgTypeEnum(value: unknown): OrgTypeEnum;
32
+ export declare const OrgSlugOrIdParamsSchema: import("@sinclair/typebox").TObject<{
33
+ org_id_or_slug: import("@sinclair/typebox").TString;
34
+ }>;
35
+ export type OrgSlugOrIdParams = Static<typeof OrgSlugOrIdParamsSchema>;
36
+ export declare const OrgIdParamsSchema: import("@sinclair/typebox").TObject<{
37
+ org_id: import("@sinclair/typebox").TString;
38
+ }>;
39
+ export type OrgIdParams = Static<typeof OrgIdParamsSchema>;
40
+ export declare const OrgSlugParamsSchema: import("@sinclair/typebox").TObject<{}>;
41
+ export type OrgSlugParams = Static<typeof OrgSlugParamsSchema>;
42
+ /**
43
+ * Base org schema
44
+ * Represents organisation table structure
45
+ */
46
+ export declare const OrgSchema: import("@sinclair/typebox").TObject<{
47
+ id: import("@sinclair/typebox").TString;
48
+ name: import("@sinclair/typebox").TString;
49
+ slug: import("@sinclair/typebox").TString;
50
+ type: import("@sinclair/typebox").TEnum<typeof OrgTypeEnum>;
51
+ created_at: import("@sinclair/typebox").TString;
52
+ updated_at: import("@sinclair/typebox").TString;
53
+ }>;
54
+ export type Org = Static<typeof OrgSchema>;
55
+ /**
56
+ * Org role schema
57
+ * Represents organisation_role table structure
58
+ */
59
+ export declare const OrgRoleSchema: import("@sinclair/typebox").TObject<{
60
+ id: import("@sinclair/typebox").TString;
61
+ org_id: import("@sinclair/typebox").TString;
62
+ user_id: import("@sinclair/typebox").TString;
63
+ role: import("@sinclair/typebox").TEnum<typeof OrgRoleTypeEnum>;
64
+ created_at: import("@sinclair/typebox").TString;
65
+ updated_at: import("@sinclair/typebox").TString;
66
+ }>;
67
+ export type OrgRole = Static<typeof OrgRoleSchema>;
68
+ /**
69
+ * Extended org role with org name
70
+ * Used for user's org list
71
+ */
72
+ export declare const OrgRoleWithOrgSchema: import("@sinclair/typebox").TObject<{
73
+ id: import("@sinclair/typebox").TString;
74
+ org_id: import("@sinclair/typebox").TIntersect<[import("@sinclair/typebox").TString, import("@sinclair/typebox").TString]>;
75
+ user_id: import("@sinclair/typebox").TString;
76
+ created_at: import("@sinclair/typebox").TString;
77
+ updated_at: import("@sinclair/typebox").TString;
78
+ role: import("@sinclair/typebox").TEnum<typeof OrgRoleTypeEnum>;
79
+ org_name: import("@sinclair/typebox").TString;
80
+ org_slug: import("@sinclair/typebox").TString;
81
+ }>;
82
+ export type OrgRoleWithOrg = Static<typeof OrgRoleWithOrgSchema>;
83
+ /**
84
+ * Create org request schema
85
+ */
86
+ export declare const CreateOrgSchema: import("@sinclair/typebox").TObject<{
87
+ name: import("@sinclair/typebox").TString;
88
+ slug: import("@sinclair/typebox").TString;
89
+ type: import("@sinclair/typebox").TEnum<typeof OrgTypeEnum>;
90
+ }>;
91
+ export type CreateOrg = Static<typeof CreateOrgSchema>;
92
+ /**
93
+ * Update org request schema
94
+ */
95
+ export declare const UpdateOrgSchema: import("@sinclair/typebox").TObject<{
96
+ name: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
97
+ }>;
98
+ export type UpdateOrg = Static<typeof UpdateOrgSchema>;
99
+ /**
100
+ * Add org role request schema
101
+ */
102
+ export declare const AddOrgRoleSchema: import("@sinclair/typebox").TObject<{
103
+ org_id: import("@sinclair/typebox").TString;
104
+ user_id: import("@sinclair/typebox").TString;
105
+ role: import("@sinclair/typebox").TEnum<typeof OrgRoleTypeEnum>;
106
+ }>;
107
+ export type AddOrgRole = Static<typeof AddOrgRoleSchema>;
108
+ /**
109
+ * Single org response schema
110
+ */
111
+ export declare const OrgResponseSchema: import("@sinclair/typebox").TObject<{
112
+ success: import("@sinclair/typebox").TLiteral<true>;
113
+ data: import("@sinclair/typebox").TObject<{
114
+ org: import("@sinclair/typebox").TObject<{
115
+ id: import("@sinclair/typebox").TString;
116
+ org_id: import("@sinclair/typebox").TIntersect<[import("@sinclair/typebox").TString, import("@sinclair/typebox").TString]>;
117
+ user_id: import("@sinclair/typebox").TString;
118
+ created_at: import("@sinclair/typebox").TString;
119
+ updated_at: import("@sinclair/typebox").TString;
120
+ role: import("@sinclair/typebox").TEnum<typeof OrgRoleTypeEnum>;
121
+ org_name: import("@sinclair/typebox").TString;
122
+ org_slug: import("@sinclair/typebox").TString;
123
+ }>;
124
+ }>;
125
+ }>;
126
+ export type OrgResponse = Static<typeof OrgResponseSchema>;
127
+ /**
128
+ * Org error response schema
129
+ * Discriminated union by error code
130
+ */
131
+ export declare const OrgErrorSchema: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TObject<{
132
+ code: import("@sinclair/typebox").TLiteral<"UNKNOWN_ERROR">;
133
+ message: import("@sinclair/typebox").TString;
134
+ }>, import("@sinclair/typebox").TObject<{
135
+ code: import("@sinclair/typebox").TLiteral<"VALIDATION_ERROR">;
136
+ message: import("@sinclair/typebox").TString;
137
+ }>, import("@sinclair/typebox").TObject<{
138
+ code: import("@sinclair/typebox").TLiteral<"ORG_ID_MISMATCH">;
139
+ message: import("@sinclair/typebox").TString;
140
+ }>, import("@sinclair/typebox").TObject<{
141
+ code: import("@sinclair/typebox").TLiteral<"ORG_NOT_FOUND">;
142
+ message: import("@sinclair/typebox").TString;
143
+ }>, import("@sinclair/typebox").TObject<{
144
+ code: import("@sinclair/typebox").TLiteral<"ORG_ROLE_NOT_FOUND">;
145
+ message: import("@sinclair/typebox").TString;
146
+ }>, import("@sinclair/typebox").TObject<{
147
+ code: import("@sinclair/typebox").TLiteral<"USER_NOT_IN_ORG">;
148
+ message: import("@sinclair/typebox").TString;
149
+ }>, import("@sinclair/typebox").TObject<{
150
+ code: import("@sinclair/typebox").TLiteral<"FORBIDDEN">;
151
+ message: import("@sinclair/typebox").TString;
152
+ }>, import("@sinclair/typebox").TObject<{
153
+ code: import("@sinclair/typebox").TLiteral<"UNAUTHORIZED">;
154
+ message: import("@sinclair/typebox").TString;
155
+ }>, import("@sinclair/typebox").TObject<{
156
+ code: import("@sinclair/typebox").TLiteral<"INVALID_ROLE">;
157
+ message: import("@sinclair/typebox").TString;
158
+ }>, import("@sinclair/typebox").TObject<{
159
+ code: import("@sinclair/typebox").TLiteral<"ORG_ID_REQUIRED">;
160
+ message: import("@sinclair/typebox").TString;
161
+ }>, import("@sinclair/typebox").TObject<{
162
+ code: import("@sinclair/typebox").TLiteral<"SLUG_ALREADY_EXISTS">;
163
+ message: import("@sinclair/typebox").TString;
164
+ }>, import("@sinclair/typebox").TObject<{
165
+ code: import("@sinclair/typebox").TLiteral<"FETCH_FAILED">;
166
+ message: import("@sinclair/typebox").TString;
167
+ }>, import("@sinclair/typebox").TObject<{
168
+ code: import("@sinclair/typebox").TLiteral<"CREATE_FAILED">;
169
+ message: import("@sinclair/typebox").TString;
170
+ }>, import("@sinclair/typebox").TObject<{
171
+ code: import("@sinclair/typebox").TLiteral<"UPDATE_FAILED">;
172
+ message: import("@sinclair/typebox").TString;
173
+ }>, import("@sinclair/typebox").TObject<{
174
+ code: import("@sinclair/typebox").TLiteral<"DELETE_FAILED">;
175
+ message: import("@sinclair/typebox").TString;
176
+ }>, import("@sinclair/typebox").TObject<{
177
+ code: import("@sinclair/typebox").TLiteral<"ROLE_CREATION_FAILED">;
178
+ message: import("@sinclair/typebox").TString;
179
+ }>]>;
180
+ export type OrgError = Static<typeof OrgErrorSchema>;
181
+ /**
182
+ * Org error response wrapper
183
+ */
184
+ export declare const OrgErrorResponseSchema: import("@sinclair/typebox").TObject<{
185
+ success: import("@sinclair/typebox").TLiteral<false>;
186
+ error: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TObject<{
187
+ code: import("@sinclair/typebox").TLiteral<"UNKNOWN_ERROR">;
188
+ message: import("@sinclair/typebox").TString;
189
+ }>, import("@sinclair/typebox").TObject<{
190
+ code: import("@sinclair/typebox").TLiteral<"VALIDATION_ERROR">;
191
+ message: import("@sinclair/typebox").TString;
192
+ }>, import("@sinclair/typebox").TObject<{
193
+ code: import("@sinclair/typebox").TLiteral<"ORG_ID_MISMATCH">;
194
+ message: import("@sinclair/typebox").TString;
195
+ }>, import("@sinclair/typebox").TObject<{
196
+ code: import("@sinclair/typebox").TLiteral<"ORG_NOT_FOUND">;
197
+ message: import("@sinclair/typebox").TString;
198
+ }>, import("@sinclair/typebox").TObject<{
199
+ code: import("@sinclair/typebox").TLiteral<"ORG_ROLE_NOT_FOUND">;
200
+ message: import("@sinclair/typebox").TString;
201
+ }>, import("@sinclair/typebox").TObject<{
202
+ code: import("@sinclair/typebox").TLiteral<"USER_NOT_IN_ORG">;
203
+ message: import("@sinclair/typebox").TString;
204
+ }>, import("@sinclair/typebox").TObject<{
205
+ code: import("@sinclair/typebox").TLiteral<"FORBIDDEN">;
206
+ message: import("@sinclair/typebox").TString;
207
+ }>, import("@sinclair/typebox").TObject<{
208
+ code: import("@sinclair/typebox").TLiteral<"UNAUTHORIZED">;
209
+ message: import("@sinclair/typebox").TString;
210
+ }>, import("@sinclair/typebox").TObject<{
211
+ code: import("@sinclair/typebox").TLiteral<"INVALID_ROLE">;
212
+ message: import("@sinclair/typebox").TString;
213
+ }>, import("@sinclair/typebox").TObject<{
214
+ code: import("@sinclair/typebox").TLiteral<"ORG_ID_REQUIRED">;
215
+ message: import("@sinclair/typebox").TString;
216
+ }>, import("@sinclair/typebox").TObject<{
217
+ code: import("@sinclair/typebox").TLiteral<"SLUG_ALREADY_EXISTS">;
218
+ message: import("@sinclair/typebox").TString;
219
+ }>, import("@sinclair/typebox").TObject<{
220
+ code: import("@sinclair/typebox").TLiteral<"FETCH_FAILED">;
221
+ message: import("@sinclair/typebox").TString;
222
+ }>, import("@sinclair/typebox").TObject<{
223
+ code: import("@sinclair/typebox").TLiteral<"CREATE_FAILED">;
224
+ message: import("@sinclair/typebox").TString;
225
+ }>, import("@sinclair/typebox").TObject<{
226
+ code: import("@sinclair/typebox").TLiteral<"UPDATE_FAILED">;
227
+ message: import("@sinclair/typebox").TString;
228
+ }>, import("@sinclair/typebox").TObject<{
229
+ code: import("@sinclair/typebox").TLiteral<"DELETE_FAILED">;
230
+ message: import("@sinclair/typebox").TString;
231
+ }>, import("@sinclair/typebox").TObject<{
232
+ code: import("@sinclair/typebox").TLiteral<"ROLE_CREATION_FAILED">;
233
+ message: import("@sinclair/typebox").TString;
234
+ }>]>;
235
+ }>;
236
+ export type OrgErrorResponse = Static<typeof OrgErrorResponseSchema>;
237
+ export declare const OrgRequestResponseSchema: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TObject<{
238
+ success: import("@sinclair/typebox").TLiteral<true>;
239
+ data: import("@sinclair/typebox").TObject<{
240
+ org: import("@sinclair/typebox").TObject<{
241
+ id: import("@sinclair/typebox").TString;
242
+ org_id: import("@sinclair/typebox").TIntersect<[import("@sinclair/typebox").TString, import("@sinclair/typebox").TString]>;
243
+ user_id: import("@sinclair/typebox").TString;
244
+ created_at: import("@sinclair/typebox").TString;
245
+ updated_at: import("@sinclair/typebox").TString;
246
+ role: import("@sinclair/typebox").TEnum<typeof OrgRoleTypeEnum>;
247
+ org_name: import("@sinclair/typebox").TString;
248
+ org_slug: import("@sinclair/typebox").TString;
249
+ }>;
250
+ }>;
251
+ }>, import("@sinclair/typebox").TObject<{
252
+ success: import("@sinclair/typebox").TLiteral<false>;
253
+ error: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TObject<{
254
+ code: import("@sinclair/typebox").TLiteral<"UNKNOWN_ERROR">;
255
+ message: import("@sinclair/typebox").TString;
256
+ }>, import("@sinclair/typebox").TObject<{
257
+ code: import("@sinclair/typebox").TLiteral<"VALIDATION_ERROR">;
258
+ message: import("@sinclair/typebox").TString;
259
+ }>, import("@sinclair/typebox").TObject<{
260
+ code: import("@sinclair/typebox").TLiteral<"ORG_ID_MISMATCH">;
261
+ message: import("@sinclair/typebox").TString;
262
+ }>, import("@sinclair/typebox").TObject<{
263
+ code: import("@sinclair/typebox").TLiteral<"ORG_NOT_FOUND">;
264
+ message: import("@sinclair/typebox").TString;
265
+ }>, import("@sinclair/typebox").TObject<{
266
+ code: import("@sinclair/typebox").TLiteral<"ORG_ROLE_NOT_FOUND">;
267
+ message: import("@sinclair/typebox").TString;
268
+ }>, import("@sinclair/typebox").TObject<{
269
+ code: import("@sinclair/typebox").TLiteral<"USER_NOT_IN_ORG">;
270
+ message: import("@sinclair/typebox").TString;
271
+ }>, import("@sinclair/typebox").TObject<{
272
+ code: import("@sinclair/typebox").TLiteral<"FORBIDDEN">;
273
+ message: import("@sinclair/typebox").TString;
274
+ }>, import("@sinclair/typebox").TObject<{
275
+ code: import("@sinclair/typebox").TLiteral<"UNAUTHORIZED">;
276
+ message: import("@sinclair/typebox").TString;
277
+ }>, import("@sinclair/typebox").TObject<{
278
+ code: import("@sinclair/typebox").TLiteral<"INVALID_ROLE">;
279
+ message: import("@sinclair/typebox").TString;
280
+ }>, import("@sinclair/typebox").TObject<{
281
+ code: import("@sinclair/typebox").TLiteral<"ORG_ID_REQUIRED">;
282
+ message: import("@sinclair/typebox").TString;
283
+ }>, import("@sinclair/typebox").TObject<{
284
+ code: import("@sinclair/typebox").TLiteral<"SLUG_ALREADY_EXISTS">;
285
+ message: import("@sinclair/typebox").TString;
286
+ }>, import("@sinclair/typebox").TObject<{
287
+ code: import("@sinclair/typebox").TLiteral<"FETCH_FAILED">;
288
+ message: import("@sinclair/typebox").TString;
289
+ }>, import("@sinclair/typebox").TObject<{
290
+ code: import("@sinclair/typebox").TLiteral<"CREATE_FAILED">;
291
+ message: import("@sinclair/typebox").TString;
292
+ }>, import("@sinclair/typebox").TObject<{
293
+ code: import("@sinclair/typebox").TLiteral<"UPDATE_FAILED">;
294
+ message: import("@sinclair/typebox").TString;
295
+ }>, import("@sinclair/typebox").TObject<{
296
+ code: import("@sinclair/typebox").TLiteral<"DELETE_FAILED">;
297
+ message: import("@sinclair/typebox").TString;
298
+ }>, import("@sinclair/typebox").TObject<{
299
+ code: import("@sinclair/typebox").TLiteral<"ROLE_CREATION_FAILED">;
300
+ message: import("@sinclair/typebox").TString;
301
+ }>]>;
302
+ }>]>;
303
+ export type OrgRequestResponse = Static<typeof OrgRequestResponseSchema>;
304
+ export type _CheckOrgRow = AssertTrue<AssertSchemaCompatibleWithRow<Org, "orgs">>;
305
+ export type _CheckCreateOrg = AssertTrue<AssertSchemaCompatibleWithInsert<CreateOrg, "orgs">>;
306
+ export type _CheckUpdateOrg = AssertTrue<AssertSchemaCompatibleWithUpdate<UpdateOrg, "orgs">>;
307
+ export type _CheckOrgRoleRow = AssertTrue<AssertSchemaCompatibleWithRow<OrgRole, "org_roles">>;
308
+ export type _CheckAddOrgRole = AssertTrue<AssertSchemaCompatibleWithInsert<AddOrgRole, "org_roles">>;
@@ -0,0 +1,214 @@
1
+ import { OrgRoleTypeEnum, OrgTypeEnum } from "@teardown/types";
2
+ import { t } from "elysia";
3
+ import { SlugSchema, } from "../../common";
4
+ export const OrgHeadersSchema = t.Object({
5
+ "td-org-id": t.String(),
6
+ });
7
+ /**
8
+ * Helper to check if role is admin or owner
9
+ */
10
+ export function isAdminRole(role) {
11
+ return role === OrgRoleTypeEnum.OWNER || role === OrgRoleTypeEnum.ADMIN;
12
+ }
13
+ /**
14
+ * Helper to check if role is owner
15
+ */
16
+ export function isOwnerRole(role) {
17
+ return role === OrgRoleTypeEnum.OWNER;
18
+ }
19
+ /**
20
+ * Parse and validate an OrgRoleTypeEnum value
21
+ * Uses a switch statement to ensure type safety and runtime validation
22
+ * @param value - The value to parse
23
+ * @returns The validated OrgRoleTypeEnum value
24
+ * @throws Error if the value is not a valid OrgRoleTypeEnum
25
+ */
26
+ export function parseOrgRoleTypeEnum(value) {
27
+ switch (value) {
28
+ case OrgRoleTypeEnum.OWNER:
29
+ return OrgRoleTypeEnum.OWNER;
30
+ case OrgRoleTypeEnum.ADMIN:
31
+ return OrgRoleTypeEnum.ADMIN;
32
+ case OrgRoleTypeEnum.ENGINEER:
33
+ return OrgRoleTypeEnum.ENGINEER;
34
+ default:
35
+ throw new Error(`Invalid OrgRoleTypeEnum value: ${value}. Expected one of: ${Object.values(OrgRoleTypeEnum).join(", ")}`);
36
+ }
37
+ }
38
+ /**
39
+ * Parse and validate an OrgTypeEnum value
40
+ * Uses a switch statement to ensure type safety and runtime validation
41
+ * @param value - The value to parse
42
+ * @returns The validated OrgTypeEnum value
43
+ * @throws Error if the value is not a valid OrgTypeEnum
44
+ */
45
+ export function parseOrgTypeEnum(value) {
46
+ switch (value) {
47
+ case OrgTypeEnum.PERSONAL:
48
+ return OrgTypeEnum.PERSONAL;
49
+ case OrgTypeEnum.START_UP:
50
+ return OrgTypeEnum.START_UP;
51
+ case OrgTypeEnum.SCALE_UP:
52
+ return OrgTypeEnum.SCALE_UP;
53
+ case OrgTypeEnum.AGENCY:
54
+ return OrgTypeEnum.AGENCY;
55
+ case OrgTypeEnum.ENTERPRISE:
56
+ return OrgTypeEnum.ENTERPRISE;
57
+ default:
58
+ throw new Error(`Invalid OrgTypeEnum value: ${value}. Expected one of: ${Object.values(OrgTypeEnum).join(", ")}`);
59
+ }
60
+ }
61
+ export const OrgSlugOrIdParamsSchema = t.Object({
62
+ org_id_or_slug: t.String(),
63
+ });
64
+ export const OrgIdParamsSchema = t.Object({
65
+ org_id: t.String(),
66
+ });
67
+ export const OrgSlugParamsSchema = t.Object({
68
+ // org_slug: SlugSchema,
69
+ });
70
+ /**
71
+ * Base org schema
72
+ * Represents organisation table structure
73
+ */
74
+ export const OrgSchema = t.Object({
75
+ id: t.String({ format: "uuid" }),
76
+ name: t.String({ minLength: 1 }),
77
+ slug: SlugSchema,
78
+ type: t.Enum(OrgTypeEnum),
79
+ created_at: t.String(),
80
+ updated_at: t.String(),
81
+ });
82
+ /**
83
+ * Org role schema
84
+ * Represents organisation_role table structure
85
+ */
86
+ export const OrgRoleSchema = t.Object({
87
+ id: t.String({ format: "uuid" }),
88
+ org_id: t.String({ format: "uuid" }),
89
+ user_id: t.String({ format: "uuid" }),
90
+ role: t.Enum(OrgRoleTypeEnum),
91
+ created_at: t.String(),
92
+ updated_at: t.String(),
93
+ });
94
+ /**
95
+ * Extended org role with org name
96
+ * Used for user's org list
97
+ */
98
+ export const OrgRoleWithOrgSchema = t.Composite([
99
+ OrgRoleSchema,
100
+ t.Object({
101
+ org_id: t.String({ format: "uuid" }),
102
+ org_name: t.String(),
103
+ org_slug: SlugSchema,
104
+ }),
105
+ ]);
106
+ /**
107
+ * Create org request schema
108
+ */
109
+ export const CreateOrgSchema = t.Object({
110
+ name: t.String({ minLength: 1, maxLength: 255 }),
111
+ slug: SlugSchema,
112
+ type: t.Enum(OrgTypeEnum),
113
+ });
114
+ /**
115
+ * Update org request schema
116
+ */
117
+ export const UpdateOrgSchema = t.Object({
118
+ name: t.Optional(t.String({ minLength: 1, maxLength: 255 })),
119
+ });
120
+ /**
121
+ * Add org role request schema
122
+ */
123
+ export const AddOrgRoleSchema = t.Object({
124
+ org_id: t.String({ format: "uuid" }),
125
+ user_id: t.String({ format: "uuid" }),
126
+ role: t.Enum(OrgRoleTypeEnum),
127
+ });
128
+ /**
129
+ * Single org response schema
130
+ */
131
+ export const OrgResponseSchema = t.Object({
132
+ success: t.Literal(true),
133
+ data: t.Object({
134
+ org: OrgRoleWithOrgSchema,
135
+ }),
136
+ });
137
+ /**
138
+ * Org error response schema
139
+ * Discriminated union by error code
140
+ */
141
+ export const OrgErrorSchema = t.Union([
142
+ t.Object({
143
+ code: t.Literal("UNKNOWN_ERROR"),
144
+ message: t.String(),
145
+ }),
146
+ t.Object({
147
+ code: t.Literal("VALIDATION_ERROR"),
148
+ message: t.String(),
149
+ }),
150
+ t.Object({
151
+ code: t.Literal("ORG_ID_MISMATCH"),
152
+ message: t.String(),
153
+ }),
154
+ t.Object({
155
+ code: t.Literal("ORG_NOT_FOUND"),
156
+ message: t.String(),
157
+ }),
158
+ t.Object({
159
+ code: t.Literal("ORG_ROLE_NOT_FOUND"),
160
+ message: t.String(),
161
+ }),
162
+ t.Object({
163
+ code: t.Literal("USER_NOT_IN_ORG"),
164
+ message: t.String(),
165
+ }),
166
+ t.Object({
167
+ code: t.Literal("FORBIDDEN"),
168
+ message: t.String(),
169
+ }),
170
+ t.Object({
171
+ code: t.Literal("UNAUTHORIZED"),
172
+ message: t.String(),
173
+ }),
174
+ t.Object({
175
+ code: t.Literal("INVALID_ROLE"),
176
+ message: t.String(),
177
+ }),
178
+ t.Object({
179
+ code: t.Literal("ORG_ID_REQUIRED"),
180
+ message: t.String(),
181
+ }),
182
+ t.Object({
183
+ code: t.Literal("SLUG_ALREADY_EXISTS"),
184
+ message: t.String(),
185
+ }),
186
+ t.Object({
187
+ code: t.Literal("FETCH_FAILED"),
188
+ message: t.String(),
189
+ }),
190
+ t.Object({
191
+ code: t.Literal("CREATE_FAILED"),
192
+ message: t.String(),
193
+ }),
194
+ t.Object({
195
+ code: t.Literal("UPDATE_FAILED"),
196
+ message: t.String(),
197
+ }),
198
+ t.Object({
199
+ code: t.Literal("DELETE_FAILED"),
200
+ message: t.String(),
201
+ }),
202
+ t.Object({
203
+ code: t.Literal("ROLE_CREATION_FAILED"),
204
+ message: t.String(),
205
+ }),
206
+ ]);
207
+ /**
208
+ * Org error response wrapper
209
+ */
210
+ export const OrgErrorResponseSchema = t.Object({
211
+ success: t.Literal(false),
212
+ error: OrgErrorSchema,
213
+ });
214
+ export const OrgRequestResponseSchema = t.Union([OrgResponseSchema, OrgErrorResponseSchema]);