@teardown/schemas 0.1.21 → 0.1.23

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 (76) hide show
  1. package/package.json +49 -52
  2. package/src/common/primitives.ts +21 -0
  3. package/src/common/responses.ts +25 -0
  4. package/{dist/common/type-checks.d.ts → src/common/type-checks.ts} +23 -4
  5. package/{dist/index.js → src/index.ts} +1 -0
  6. package/src/modules/analytics/schemas.ts +178 -0
  7. package/src/modules/builds/schemas.ts +171 -0
  8. package/src/modules/devices/schemas.ts +196 -0
  9. package/src/modules/environment/schemas.ts +81 -0
  10. package/src/modules/events/index.ts +2 -0
  11. package/src/modules/events/schemas.ts +129 -0
  12. package/src/modules/identify/schemas.ts +257 -0
  13. package/src/modules/me/schemas.ts +87 -0
  14. package/src/modules/orgs/schemas.ts +260 -0
  15. package/src/modules/personas/schemas.ts +123 -0
  16. package/src/modules/projects/schemas.ts +179 -0
  17. package/src/modules/sessions/schemas.ts +158 -0
  18. package/src/modules/versions/schemas.ts +192 -0
  19. package/dist/common/index.js +0 -3
  20. package/dist/common/primitives.d.ts +0 -11
  21. package/dist/common/primitives.js +0 -8
  22. package/dist/common/responses.d.ts +0 -27
  23. package/dist/common/responses.js +0 -13
  24. package/dist/common/type-checks.js +0 -1
  25. package/dist/index.d.ts +0 -13
  26. package/dist/modules/analytics/schemas.d.ts +0 -239
  27. package/dist/modules/analytics/schemas.js +0 -136
  28. package/dist/modules/builds/schemas.d.ts +0 -248
  29. package/dist/modules/builds/schemas.js +0 -137
  30. package/dist/modules/devices/schemas.d.ts +0 -207
  31. package/dist/modules/devices/schemas.js +0 -165
  32. package/dist/modules/environment/schemas.d.ts +0 -56
  33. package/dist/modules/environment/schemas.js +0 -57
  34. package/dist/modules/events/schemas.d.ts +0 -138
  35. package/dist/modules/events/schemas.js +0 -116
  36. package/dist/modules/identify/index.js +0 -1
  37. package/dist/modules/identify/schemas.d.ts +0 -377
  38. package/dist/modules/identify/schemas.js +0 -221
  39. package/dist/modules/index.js +0 -12
  40. package/dist/modules/me/index.d.ts +0 -1
  41. package/dist/modules/me/index.js +0 -1
  42. package/dist/modules/me/schemas.d.ts +0 -75
  43. package/dist/modules/me/schemas.js +0 -76
  44. package/dist/modules/orgs/index.d.ts +0 -1
  45. package/dist/modules/orgs/index.js +0 -1
  46. package/dist/modules/orgs/schemas.d.ts +0 -308
  47. package/dist/modules/orgs/schemas.js +0 -214
  48. package/dist/modules/personas/index.d.ts +0 -1
  49. package/dist/modules/personas/index.js +0 -1
  50. package/dist/modules/personas/schemas.d.ts +0 -170
  51. package/dist/modules/personas/schemas.js +0 -100
  52. package/dist/modules/projects/index.d.ts +0 -1
  53. package/dist/modules/projects/index.js +0 -1
  54. package/dist/modules/projects/schemas.d.ts +0 -222
  55. package/dist/modules/projects/schemas.js +0 -145
  56. package/dist/modules/sessions/index.d.ts +0 -1
  57. package/dist/modules/sessions/index.js +0 -1
  58. package/dist/modules/sessions/schemas.d.ts +0 -258
  59. package/dist/modules/sessions/schemas.js +0 -128
  60. package/dist/modules/versions/index.d.ts +0 -1
  61. package/dist/modules/versions/index.js +0 -1
  62. package/dist/modules/versions/schemas.d.ts +0 -248
  63. package/dist/modules/versions/schemas.js +0 -155
  64. /package/{dist/common/index.d.ts → src/common/index.ts} +0 -0
  65. /package/{dist/modules/analytics/index.d.ts → src/modules/analytics/index.ts} +0 -0
  66. /package/{dist/modules/analytics/index.js → src/modules/builds/index.ts} +0 -0
  67. /package/{dist/modules/builds/index.d.ts → src/modules/devices/index.ts} +0 -0
  68. /package/{dist/modules/builds/index.js → src/modules/environment/index.ts} +0 -0
  69. /package/{dist/modules/devices/index.d.ts → src/modules/identify/index.ts} +0 -0
  70. /package/{dist/modules/index.d.ts → src/modules/index.ts} +0 -0
  71. /package/{dist/modules/devices/index.js → src/modules/me/index.ts} +0 -0
  72. /package/{dist/modules/environment/index.d.ts → src/modules/orgs/index.ts} +0 -0
  73. /package/{dist/modules/environment/index.js → src/modules/personas/index.ts} +0 -0
  74. /package/{dist/modules/events/index.d.ts → src/modules/projects/index.ts} +0 -0
  75. /package/{dist/modules/events/index.js → src/modules/sessions/index.ts} +0 -0
  76. /package/{dist/modules/identify/index.d.ts → src/modules/versions/index.ts} +0 -0
@@ -1,308 +0,0 @@
1
- import { type Static } from "@sinclair/typebox";
2
- import { OrgRoleTypeEnum, OrgTypeEnum } from "@teardown/types";
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
- user_id: import("@sinclair/typebox").TString;
75
- created_at: import("@sinclair/typebox").TString;
76
- updated_at: import("@sinclair/typebox").TString;
77
- org_id: import("@sinclair/typebox").TIntersect<[import("@sinclair/typebox").TString, 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
- user_id: import("@sinclair/typebox").TString;
117
- created_at: import("@sinclair/typebox").TString;
118
- updated_at: import("@sinclair/typebox").TString;
119
- org_id: import("@sinclair/typebox").TIntersect<[import("@sinclair/typebox").TString, 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
- user_id: import("@sinclair/typebox").TString;
243
- created_at: import("@sinclair/typebox").TString;
244
- updated_at: import("@sinclair/typebox").TString;
245
- org_id: import("@sinclair/typebox").TIntersect<[import("@sinclair/typebox").TString, 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">>;
@@ -1,214 +0,0 @@
1
- import { Type } from "@sinclair/typebox";
2
- import { OrgRoleTypeEnum, OrgTypeEnum } from "@teardown/types";
3
- import { SlugSchema, } from "../../common";
4
- export const OrgHeadersSchema = Type.Object({
5
- "td-org-id": Type.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 = Type.Object({
62
- org_id_or_slug: Type.String(),
63
- });
64
- export const OrgIdParamsSchema = Type.Object({
65
- org_id: Type.String(),
66
- });
67
- export const OrgSlugParamsSchema = Type.Object({
68
- // org_slug: SlugSchema,
69
- });
70
- /**
71
- * Base org schema
72
- * Represents organisation table structure
73
- */
74
- export const OrgSchema = Type.Object({
75
- id: Type.String({ format: "uuid" }),
76
- name: Type.String({ minLength: 1 }),
77
- slug: SlugSchema,
78
- type: Type.Enum(OrgTypeEnum),
79
- created_at: Type.String(),
80
- updated_at: Type.String(),
81
- });
82
- /**
83
- * Org role schema
84
- * Represents organisation_role table structure
85
- */
86
- export const OrgRoleSchema = Type.Object({
87
- id: Type.String({ format: "uuid" }),
88
- org_id: Type.String({ format: "uuid" }),
89
- user_id: Type.String({ format: "uuid" }),
90
- role: Type.Enum(OrgRoleTypeEnum),
91
- created_at: Type.String(),
92
- updated_at: Type.String(),
93
- });
94
- /**
95
- * Extended org role with org name
96
- * Used for user's org list
97
- */
98
- export const OrgRoleWithOrgSchema = Type.Composite([
99
- OrgRoleSchema,
100
- Type.Object({
101
- org_id: Type.String({ format: "uuid" }),
102
- org_name: Type.String(),
103
- org_slug: SlugSchema,
104
- }),
105
- ]);
106
- /**
107
- * Create org request schema
108
- */
109
- export const CreateOrgSchema = Type.Object({
110
- name: Type.String({ minLength: 1, maxLength: 255 }),
111
- slug: SlugSchema,
112
- type: Type.Enum(OrgTypeEnum),
113
- });
114
- /**
115
- * Update org request schema
116
- */
117
- export const UpdateOrgSchema = Type.Object({
118
- name: Type.Optional(Type.String({ minLength: 1, maxLength: 255 })),
119
- });
120
- /**
121
- * Add org role request schema
122
- */
123
- export const AddOrgRoleSchema = Type.Object({
124
- org_id: Type.String({ format: "uuid" }),
125
- user_id: Type.String({ format: "uuid" }),
126
- role: Type.Enum(OrgRoleTypeEnum),
127
- });
128
- /**
129
- * Single org response schema
130
- */
131
- export const OrgResponseSchema = Type.Object({
132
- success: Type.Literal(true),
133
- data: Type.Object({
134
- org: OrgRoleWithOrgSchema,
135
- }),
136
- });
137
- /**
138
- * Org error response schema
139
- * Discriminated union by error code
140
- */
141
- export const OrgErrorSchema = Type.Union([
142
- Type.Object({
143
- code: Type.Literal("UNKNOWN_ERROR"),
144
- message: Type.String(),
145
- }),
146
- Type.Object({
147
- code: Type.Literal("VALIDATION_ERROR"),
148
- message: Type.String(),
149
- }),
150
- Type.Object({
151
- code: Type.Literal("ORG_ID_MISMATCH"),
152
- message: Type.String(),
153
- }),
154
- Type.Object({
155
- code: Type.Literal("ORG_NOT_FOUND"),
156
- message: Type.String(),
157
- }),
158
- Type.Object({
159
- code: Type.Literal("ORG_ROLE_NOT_FOUND"),
160
- message: Type.String(),
161
- }),
162
- Type.Object({
163
- code: Type.Literal("USER_NOT_IN_ORG"),
164
- message: Type.String(),
165
- }),
166
- Type.Object({
167
- code: Type.Literal("FORBIDDEN"),
168
- message: Type.String(),
169
- }),
170
- Type.Object({
171
- code: Type.Literal("UNAUTHORIZED"),
172
- message: Type.String(),
173
- }),
174
- Type.Object({
175
- code: Type.Literal("INVALID_ROLE"),
176
- message: Type.String(),
177
- }),
178
- Type.Object({
179
- code: Type.Literal("ORG_ID_REQUIRED"),
180
- message: Type.String(),
181
- }),
182
- Type.Object({
183
- code: Type.Literal("SLUG_ALREADY_EXISTS"),
184
- message: Type.String(),
185
- }),
186
- Type.Object({
187
- code: Type.Literal("FETCH_FAILED"),
188
- message: Type.String(),
189
- }),
190
- Type.Object({
191
- code: Type.Literal("CREATE_FAILED"),
192
- message: Type.String(),
193
- }),
194
- Type.Object({
195
- code: Type.Literal("UPDATE_FAILED"),
196
- message: Type.String(),
197
- }),
198
- Type.Object({
199
- code: Type.Literal("DELETE_FAILED"),
200
- message: Type.String(),
201
- }),
202
- Type.Object({
203
- code: Type.Literal("ROLE_CREATION_FAILED"),
204
- message: Type.String(),
205
- }),
206
- ]);
207
- /**
208
- * Org error response wrapper
209
- */
210
- export const OrgErrorResponseSchema = Type.Object({
211
- success: Type.Literal(false),
212
- error: OrgErrorSchema,
213
- });
214
- export const OrgRequestResponseSchema = Type.Union([OrgResponseSchema, OrgErrorResponseSchema]);
@@ -1 +0,0 @@
1
- export * from "./schemas";
@@ -1 +0,0 @@
1
- export * from "./schemas";