@omnichar/contracts 0.0.0-7b02f40 → 0.0.0-b4da233

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.
@@ -0,0 +1,57 @@
1
+ import { z } from 'zod';
2
+ // Two logical environments per team in one deployment; the web app is always production.
3
+ export const TEAM_ENVS = ['production', 'sandbox'];
4
+ export const teamEnvSchema = z.enum(TEAM_ENVS);
5
+ export const KEY_SCOPES = [
6
+ 'chars:read',
7
+ 'chars:write',
8
+ 'licenses:read',
9
+ 'licenses:write',
10
+ 'usage:read',
11
+ ];
12
+ export const keyScopeSchema = z.enum(KEY_SCOPES);
13
+ // The environment is read from the prefix, so a request can never name its own.
14
+ export const TEAM_KEY_PREFIX = {
15
+ production: 'sk_live_',
16
+ sandbox: 'sk_test_',
17
+ };
18
+ export const teamKeySecretSchema = z
19
+ .string()
20
+ .regex(/^sk_(live|test)_[a-z0-9]{8}_[A-Za-z0-9_-]{43}$/);
21
+ export const TEAM_KEY_STATUSES = ['active', 'expiring', 'revoked'];
22
+ export const teamKeySchema = z.object({
23
+ id: z.uuid(),
24
+ name: z.string(),
25
+ env: teamEnvSchema,
26
+ prefix: z.string(),
27
+ hint: z.string().length(4),
28
+ scopes: z.array(keyScopeSchema),
29
+ createdBy: z.object({ name: z.string().nullable(), email: z.string().nullable() }),
30
+ createdAt: z.iso.datetime(),
31
+ lastUsedAt: z.iso.datetime().nullable(),
32
+ // Set on the old key of a rotation, which keeps working until then.
33
+ expiresAt: z.iso.datetime().nullable(),
34
+ status: z.enum(TEAM_KEY_STATUSES),
35
+ });
36
+ export const teamKeyListSchema = z.object({ items: z.array(teamKeySchema) });
37
+ export const createTeamKeyBodySchema = z.object({
38
+ name: z.string().trim().min(1).max(60),
39
+ env: teamEnvSchema,
40
+ scopes: z
41
+ .array(keyScopeSchema)
42
+ .min(1)
43
+ .default([...KEY_SCOPES]),
44
+ });
45
+ // The only response that ever carries the secret; only its hash is stored.
46
+ export const createTeamKeyResponseSchema = z.object({
47
+ key: teamKeySchema,
48
+ secret: teamKeySecretSchema,
49
+ });
50
+ // What GET /v1/team answers, so an integrator can check which team and environment a key reaches.
51
+ export const teamInfoSchema = z.object({
52
+ id: z.uuid(),
53
+ name: z.string(),
54
+ plan: z.enum(['free', 'team', 'partner']),
55
+ env: teamEnvSchema,
56
+ });
57
+ //# sourceMappingURL=teamKeys.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"teamKeys.js","sourceRoot":"","sources":["../../src/v1/teamKeys.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB,yFAAyF;AACzF,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,YAAY,EAAE,SAAS,CAAU,CAAA;AAC3D,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAA;AAG9C,MAAM,CAAC,MAAM,UAAU,GAAG;IACxB,YAAY;IACZ,aAAa;IACb,eAAe;IACf,gBAAgB;IAChB,YAAY;CACJ,CAAA;AACV,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAA;AAGhD,gFAAgF;AAChF,MAAM,CAAC,MAAM,eAAe,GAA4B;IACtD,UAAU,EAAE,UAAU;IACtB,OAAO,EAAE,UAAU;CACpB,CAAA;AACD,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC;KACjC,MAAM,EAAE;KACR,KAAK,CAAC,gDAAgD,CAAC,CAAA;AAE1D,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,QAAQ,EAAE,UAAU,EAAE,SAAS,CAAU,CAAA;AAE3E,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,CAAC,MAAM,CAAC;IACpC,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE;IACZ,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE;IAChB,GAAG,EAAE,aAAa;IAClB,MAAM,EA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AM,EAAE,mBAAmB;CAC5B,CAAC,CAAA;AAGF,kGAAkG;AAClG,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,CAAC,MAAM,CAAC;IACrC,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE;IACZ,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE;IAChB,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,CAAC,CAAC;IACzC,GAAG,EAAE,aAAa;CACnB,CAAC,CAAA"}
@@ -0,0 +1,242 @@
1
+ import { z } from 'zod';
2
+ export declare const TEAM_HEADER = "x-omnichar-team";
3
+ export declare const TEAM_ROLES: readonly ["owner", "admin", "developer", "member"];
4
+ export declare const teamRoleSchema: z.ZodEnum<{
5
+ admin: "admin";
6
+ member: "member";
7
+ owner: "owner";
8
+ developer: "developer";
9
+ }>;
10
+ export type TeamRole = z.infer<typeof teamRoleSchema>;
11
+ export declare const INVITE_ROLES: readonly ["admin", "developer", "member"];
12
+ export declare const inviteRoleSchema: z.ZodEnum<{
13
+ admin: "admin";
14
+ member: "member";
15
+ developer: "developer";
16
+ }>;
17
+ export declare const TEAM_PLANS: readonly ["free", "team", "partner"];
18
+ export declare const teamPlanSchema: z.ZodEnum<{
19
+ free: "free";
20
+ team: "team";
21
+ partner: "partner";
22
+ }>;
23
+ export type TeamPlan = z.infer<typeof teamPlanSchema>;
24
+ export declare const TEAM_ACTIONS: readonly ["generate", "manage_members", "view_billing", "delete_team", "transfer_ownership", "manage_keys"];
25
+ export type TeamAction = (typeof TEAM_ACTIONS)[number];
26
+ /** The permission table. The control plane enforces it; the studio uses it to hide controls. */
27
+ export declare function teamCan(role: TeamRole, action: TeamAction): boolean;
28
+ export declare const teamFlagsSchema: z.ZodObject<{
29
+ provider: z.ZodDefault<z.ZodBoolean>;
30
+ api_access: z.ZodDefault<z.ZodBoolean>;
31
+ sandbox: z.ZodDefault<z.ZodBoolean>;
32
+ }, z.core.$strip>;
33
+ export type TeamFlags = z.infer<typeof teamFlagsSchema>;
34
+ export declare const teamSlugSchema: z.ZodString;
35
+ export declare const teamSchema: z.ZodObject<{
36
+ id: z.ZodUUID;
37
+ name: z.ZodString;
38
+ slug: z.ZodString;
39
+ personal: z.ZodBoolean;
40
+ plan: z.ZodEnum<{
41
+ free: "free";
42
+ team: "team";
43
+ partner: "partner";
44
+ }>;
45
+ role: z.ZodEnum<{
46
+ admin: "admin";
47
+ member: "member";
48
+ owner: "owner";
49
+ developer: "developer";
50
+ }>;
51
+ flags: z.ZodObject<{
52
+ provider: z.ZodDefault<z.ZodBoolean>;
53
+ api_access: z.ZodDefault<z.ZodBoolean>;
54
+ sandbox: z.ZodDefault<z.ZodBoolean>;
55
+ }, z.core.$strip>;
56
+ }, z.core.$strip>;
57
+ export type Team = z.infer<typeof teamSchema>;
58
+ export declare const teamListSchema: z.ZodObject<{
59
+ items: z.ZodArray<z.ZodObject<{
60
+ id: z.ZodUUID;
61
+ name: z.ZodString;
62
+ slug: z.ZodString;
63
+ personal: z.ZodBoolean;
64
+ plan: z.ZodEnum<{
65
+ free: "free";
66
+ team: "team";
67
+ partner: "partner";
68
+ }>;
69
+ role: z.ZodEnum<{
70
+ admin: "admin";
71
+ member: "member";
72
+ owner: "owner";
73
+ developer: "developer";
74
+ }>;
75
+ flags: z.ZodObject<{
76
+ provider: z.ZodDefault<z.ZodBoolean>;
77
+ api_access: z.ZodDefault<z.ZodBoolean>;
78
+ sandbox: z.ZodDefault<z.ZodBoolean>;
79
+ }, z.core.$strip>;
80
+ }, z.core.$strip>>;
81
+ }, z.core.$strip>;
82
+ export declare const createTeamBodySchema: z.ZodObject<{
83
+ name: z.ZodString;
84
+ }, z.core.$strip>;
85
+ export declare const renameTeamBodySchema: z.ZodObject<{
86
+ name: z.ZodString;
87
+ }, z.core.$strip>;
88
+ export declare const transferTeamBodySchema: z.ZodObject<{
89
+ userId: z.ZodUUID;
90
+ }, z.core.$strip>;
91
+ export declare const memberSchema: z.ZodObject<{
92
+ userId: z.ZodUUID;
93
+ role: z.ZodEnum<{
94
+ admin: "admin";
95
+ member: "member";
96
+ owner: "owner";
97
+ developer: "developer";
98
+ }>;
99
+ email: z.ZodNullable<z.ZodString>;
100
+ name: z.ZodNullable<z.ZodString>;
101
+ avatarUrl: z.ZodNullable<z.ZodURL>;
102
+ joinedAt: z.ZodISODateTime;
103
+ }, z.core.$strip>;
104
+ export type Member = z.infer<typeof memberSchema>;
105
+ export declare const memberListSchema: z.ZodObject<{
106
+ items: z.ZodArray<z.ZodObject<{
107
+ userId: z.ZodUUID;
108
+ role: z.ZodEnum<{
109
+ admin: "admin";
110
+ member: "member";
111
+ owner: "owner";
112
+ developer: "developer";
113
+ }>;
114
+ email: z.ZodNullable<z.ZodString>;
115
+ name: z.ZodNullable<z.ZodString>;
116
+ avatarUrl: z.ZodNullable<z.ZodURL>;
117
+ joinedAt: z.ZodISODateTime;
118
+ }, z.core.$strip>>;
119
+ }, z.core.$strip>;
120
+ export declare const changeRoleBodySchema: z.ZodObject<{
121
+ role: z.ZodEnum<{
122
+ admin: "admin";
123
+ member: "member";
124
+ owner: "owner";
125
+ developer: "developer";
126
+ }>;
127
+ }, z.core.$strip>;
128
+ export declare const inviteSchema: z.ZodObject<{
129
+ id: z.ZodUUID;
130
+ email: z.ZodString;
131
+ role: z.ZodEnum<{
132
+ admin: "admin";
133
+ member: "member";
134
+ developer: "developer";
135
+ }>;
136
+ createdAt: z.ZodISODateTime;
137
+ expiresAt: z.ZodISODateTime;
138
+ lastSentAt: z.ZodISODateTime;
139
+ }, z.core.$strip>;
140
+ export type Invite = z.infer<typeof inviteSchema>;
141
+ export declare const inviteListSchema: z.ZodObject<{
142
+ items: z.ZodArray<z.ZodObject<{
143
+ id: z.ZodUUID;
144
+ email: z.ZodString;
145
+ role: z.ZodEnum<{
146
+ admin: "admin";
147
+ member: "member";
148
+ developer: "developer";
149
+ }>;
150
+ createdAt: z.ZodISODateTime;
151
+ expiresAt: z.ZodISODateTime;
152
+ lastSentAt: z.ZodISODateTime;
153
+ }, z.core.$strip>>;
154
+ }, z.core.$strip>;
155
+ export declare const createInviteBodySchema: z.ZodObject<{
156
+ email: z.ZodPipe<z.ZodEmail, z.ZodTransform<string, string>>;
157
+ role: z.ZodDefault<z.ZodEnum<{
158
+ admin: "admin";
159
+ member: "member";
160
+ developer: "developer";
161
+ }>>;
162
+ }, z.core.$strip>;
163
+ export declare const inviteResultSchema: z.ZodObject<{
164
+ invite: z.ZodObject<{
165
+ id: z.ZodUUID;
166
+ email: z.ZodString;
167
+ role: z.ZodEnum<{
168
+ admin: "admin";
169
+ member: "member";
170
+ developer: "developer";
171
+ }>;
172
+ createdAt: z.ZodISODateTime;
173
+ expiresAt: z.ZodISODateTime;
174
+ lastSentAt: z.ZodISODateTime;
175
+ }, z.core.$strip>;
176
+ emailSent: z.ZodBoolean;
177
+ }, z.core.$strip>;
178
+ export declare const adminTeamSchema: z.ZodObject<{
179
+ id: z.ZodUUID;
180
+ name: z.ZodString;
181
+ slug: z.ZodString;
182
+ personal: z.ZodBoolean;
183
+ plan: z.ZodEnum<{
184
+ free: "free";
185
+ team: "team";
186
+ partner: "partner";
187
+ }>;
188
+ flags: z.ZodObject<{
189
+ provider: z.ZodDefault<z.ZodBoolean>;
190
+ api_access: z.ZodDefault<z.ZodBoolean>;
191
+ sandbox: z.ZodDefault<z.ZodBoolean>;
192
+ }, z.core.$strip>;
193
+ members: z.ZodNumber;
194
+ createdAt: z.ZodISODateTime;
195
+ }, z.core.$strip>;
196
+ export type AdminTeam = z.infer<typeof adminTeamSchema>;
197
+ export declare const adminTeamListSchema: z.ZodObject<{
198
+ items: z.ZodArray<z.ZodObject<{
199
+ id: z.ZodUUID;
200
+ name: z.ZodString;
201
+ slug: z.ZodString;
202
+ personal: z.ZodBoolean;
203
+ plan: z.ZodEnum<{
204
+ free: "free";
205
+ team: "team";
206
+ partner: "partner";
207
+ }>;
208
+ flags: z.ZodObject<{
209
+ provider: z.ZodDefault<z.ZodBoolean>;
210
+ api_access: z.ZodDefault<z.ZodBoolean>;
211
+ sandbox: z.ZodDefault<z.ZodBoolean>;
212
+ }, z.core.$strip>;
213
+ members: z.ZodNumber;
214
+ createdAt: z.ZodISODateTime;
215
+ }, z.core.$strip>>;
216
+ }, z.core.$strip>;
217
+ export declare const adminTeamQuerySchema: z.ZodObject<{
218
+ q: z.ZodString;
219
+ }, z.core.$strip>;
220
+ export declare const adminTeamPatchSchema: z.ZodObject<{
221
+ plan: z.ZodOptional<z.ZodEnum<{
222
+ free: "free";
223
+ team: "team";
224
+ partner: "partner";
225
+ }>>;
226
+ flags: z.ZodOptional<z.ZodObject<{
227
+ provider: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>;
228
+ api_access: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>;
229
+ sandbox: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>;
230
+ }, z.core.$strip>>;
231
+ }, z.core.$strip>;
232
+ export declare const adminTeamGrantBodySchema: z.ZodObject<{
233
+ credits: z.ZodNumber;
234
+ note: z.ZodOptional<z.ZodString>;
235
+ idempotencyKey: z.ZodString;
236
+ }, z.core.$strip>;
237
+ export type AdminTeamGrantBody = z.infer<typeof adminTeamGrantBodySchema>;
238
+ export type CreateTeamBody = z.infer<typeof createTeamBodySchema>;
239
+ export type CreateInviteBody = z.infer<typeof createInviteBodySchema>;
240
+ export type InviteResult = z.infer<typeof inviteResultSchema>;
241
+ export type AdminTeamPatch = z.infer<typeof adminTeamPatchSchema>;
242
+ //# sourceMappingURL=teams.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"teams.d.ts","sourceRoot":"","sources":["../../src/v1/teams.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAIvB,eAAO,MAAM,WAAW,oBAAoB,CAAA;AAG5C,eAAO,MAAM,UAAU,oDAAqD,CAAA;AAC5E,eAAO,MAAM,cAAc;;;;;EAAqB,CAAA;AAChD,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,oBAAoB;;;;;;;iBAAqC,CAAA;AAEtE,eAAO,MAAM,YAAY;;;;;;;;;;;iBAOvB,CAAA;AACF,MAAM,MAAM,MAAM,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,YAAY,CAAC,CAAA;AACjD,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;iBAA6C,CAAA;AAG1E,eAAO,MAAM,sBAAsB;;;;;;;iBAMjC,CAAA;AAGF,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;iBAA6D,CAAA;AAG5F,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;;;iBAS1B,CAAA;AACF,MAAM,MAAM,SAAS,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,eAAe,CAAC,CAAA;AACvD,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;;iBAAgD,CAAA;AAChF,eAAO,MAAM,oBAAoB;;iBAAoD,CAAA;AACrF,eAAO,MAAM,oBAAoB;;;;;;;;;;;iBAKoD,CAAA;AAGrF,eAAO,MAAM,wBAAwB;;;;iBAAgD,CAAA;AACrF,MAAM,MAAM,kBAAkB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,wBAAwB,CAAC,CAAA;AAEzE,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAA;AACjE,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,sBAAsB,CAAC,CAAA;AACrE,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,kBAAkB,CAAC,CAAA;AAC7D,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAA"}
@@ -0,0 +1,103 @@
1
+ import { z } from 'zod';
2
+ import { grantCreditsBodySchema } from './credits.js';
3
+ // Which team a request acts for; membership is proven before use, and a non-member gets 404.
4
+ export const TEAM_HEADER = 'x-omnichar-team';
5
+ // Named teamRole because the person-level role (admin, team, member, user) means staff access.
6
+ export const TEAM_ROLES = ['owner', 'admin', 'developer', 'member'];
7
+ export const teamRoleSchema = z.enum(TEAM_ROLES);
8
+ // Ownership moves by transfer, never by invite, so an invite cannot hand someone the team.
9
+ export const INVITE_ROLES = ['admin', 'developer', 'member'];
10
+ export const inviteRoleSchema = z.enum(INVITE_ROLES);
11
+ export const TEAM_PLANS = ['free', 'team', 'partner'];
12
+ export const teamPlanSchema = z.enum(TEAM_PLANS);
13
+ export const TEAM_ACTIONS = [
14
+ 'generate',
15
+ 'manage_members',
16
+ 'view_billing',
17
+ 'delete_team',
18
+ 'transfer_ownership',
19
+ 'manage_keys',
20
+ ];
21
+ const ALLOWED = {
22
+ generate: ['owner', 'admin', 'developer', 'member'],
23
+ manage_members: ['owner', 'admin'],
24
+ view_billing: ['owner', 'admin'],
25
+ delete_team: ['owner'],
26
+ transfer_ownership: ['owner'],
27
+ manage_keys: ['owner', 'admin', 'developer'],
28
+ };
29
+ /** The permission table. The control plane enforces it; the studio uses it to hide controls. */
30
+ export function teamCan(role, action) {
31
+ return ALLOWED[action].includes(role);
32
+ }
33
+ export const teamFlagsSchema = z.object({
34
+ provider: z.boolean().default(false),
35
+ api_access: z.boolean().default(false),
36
+ sandbox: z.boolean().default(false),
37
+ });
38
+ export const teamSlugSchema = z.string().regex(/^[a-z0-9-]{3,40}$/);
39
+ export const teamSchema = z.object({
40
+ id: z.uuid(),
41
+ name: z.string(),
42
+ slug: z.string(),
43
+ personal: z.boolean(),
44
+ plan: teamPlanSchema,
45
+ role: teamRoleSchema,
46
+ flags: teamFlagsSchema,
47
+ });
48
+ // Personal first, then shared teams by name.
49
+ export const teamListSchema = z.object({ items: z.array(teamSchema) });
50
+ export const createTeamBodySchema = z.object({ name: z.string().trim().min(2).max(60) });
51
+ export const renameTeamBodySchema = createTeamBodySchema;
52
+ export const transferTeamBodySchema = z.object({ userId: z.uuid() });
53
+ export const memberSchema = z.object({
54
+ userId: z.uuid(),
55
+ role: teamRoleSchema,
56
+ email: z.string().nullable(),
57
+ name: z.string().nullable(),
58
+ avatarUrl: z.url().nullable(),
59
+ joinedAt: z.iso.datetime(),
60
+ });
61
+ export const memberListSchema = z.object({ items: z.array(memberSchema) });
62
+ export const changeRoleBodySchema = z.object({ role: teamRoleSchema });
63
+ export const inviteSchema = z.object({
64
+ id: z.uuid(),
65
+ email: z.string(),
66
+ role: inviteRoleSchema,
67
+ createdAt: z.iso.datetime(),
68
+ expiresAt: z.iso.datetime(),
69
+ lastSentAt: z.iso.datetime(),
70
+ });
71
+ export const inviteListSchema = z.object({ items: z.array(inviteSchema) });
72
+ // Lowercased here so the stored value, the duplicate check and the sign-in match agree on one form.
73
+ export const createInviteBodySchema = z.object({
74
+ email: z
75
+ .email()
76
+ .max(254)
77
+ .transform((v) => v.toLowerCase()),
78
+ role: inviteRoleSchema.default('member'),
79
+ });
80
+ // Whether the email left. The invite is stored either way, since sign-in accepts it by address.
81
+ export const inviteResultSchema = z.object({ invite: inviteSchema, emailSent: z.boolean() });
82
+ // Staff only. Each field is optional, so a change touches only what it names.
83
+ export const adminTeamSchema = z.object({
84
+ id: z.uuid(),
85
+ name: z.string(),
86
+ slug: z.string(),
87
+ personal: z.boolean(),
88
+ plan: teamPlanSchema,
89
+ flags: teamFlagsSchema,
90
+ members: z.number().int(),
91
+ createdAt: z.iso.datetime(),
92
+ });
93
+ export const adminTeamListSchema = z.object({ items: z.array(adminTeamSchema) });
94
+ export const adminTeamQuerySchema = z.object({ q: z.string().trim().min(1).max(60) });
95
+ export const adminTeamPatchSchema = z
96
+ .object({
97
+ plan: teamPlanSchema.optional(),
98
+ flags: teamFlagsSchema.partial().optional(),
99
+ })
100
+ .refine((v) => v.plan !== undefined || v.flags !== undefined, 'Nothing to change.');
101
+ // Staff loading a team's balance: the user grant without a user, since a team id is its account id.
102
+ export const adminTeamGrantBodySchema = grantCreditsBodySchema.omit({ userId: true });
103
+ //# sourceMappingURL=teams.js.map
@@ -0,0 +1 @@
1
+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CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC,CAAA;AACrF,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC;KAClC,MAAM,CAAC;IACN,IAAI,EAAE,cAAc,CAAC,QAAQ,EAAE;IAC/B,KAAK,EAAE,eAAe,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE;CAC5C,CAAC;KACD,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,SAAS,IAAI,CAAC,CAAC,KAAK,KAAK,SAAS,EAAE,oBAAoB,CAAC,CAAA;AAErF,oGAAoG;AACpG,MAAM,CAAC,MAAM,wBAAwB,GAAG,sBAAsB,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@omnichar/contracts",
3
- "version": "0.0.0-7b02f40",
3
+ "version": "0.0.0-b4da233",
4
4
  "description": "The wire contract between Cloud-Studio and Cloud-Control-Plane. Zod schemas and the types inferred from them.",
5
5
  "license": "UNLICENSED",
6
6
  "type": "module",