@tokenite/shared 1.0.1 → 1.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 (52) hide show
  1. package/assets/providers/anthropic.svg +1 -0
  2. package/assets/providers/bedrock.svg +1 -0
  3. package/assets/providers/google.svg +1 -0
  4. package/assets/providers/grok.svg +1 -0
  5. package/assets/providers/openai.svg +1 -0
  6. package/dist/assets.d.ts +5 -0
  7. package/dist/assets.js +9 -0
  8. package/dist/catalog/access-models.d.ts +40 -0
  9. package/dist/catalog/access-models.js +66 -0
  10. package/dist/catalog/bindings/google.js +3 -0
  11. package/dist/catalog/bindings/index.d.ts +2 -0
  12. package/dist/catalog/bindings/index.js +16 -0
  13. package/dist/catalog/bindings/openai.js +9 -0
  14. package/dist/catalog/capabilities.js +8 -2
  15. package/dist/catalog/index.d.ts +2 -0
  16. package/dist/catalog/index.js +2 -0
  17. package/dist/catalog/models/google.d.ts +1 -0
  18. package/dist/catalog/models/google.js +4 -0
  19. package/dist/catalog/models/grok.js +6 -6
  20. package/dist/catalog/models/openai.d.ts +9 -0
  21. package/dist/catalog/models/openai.js +9 -0
  22. package/dist/catalog/providers/anthropic.js +1 -1
  23. package/dist/catalog/providers/bedrock.js +1 -1
  24. package/dist/catalog/providers/google.js +1 -1
  25. package/dist/catalog/providers/grok.js +1 -1
  26. package/dist/catalog/providers/index.d.ts +1 -1
  27. package/dist/catalog/providers/index.js +11 -4
  28. package/dist/catalog/providers/openai.js +1 -1
  29. package/dist/catalog/strategy-providers.d.ts +13 -0
  30. package/dist/catalog/strategy-providers.js +37 -0
  31. package/dist/catalog/tiers.js +8 -2
  32. package/dist/index.d.ts +6 -4
  33. package/dist/index.js +6 -4
  34. package/dist/parse.d.ts +2 -0
  35. package/dist/parse.js +11 -2
  36. package/dist/schemas/access-token.d.ts +2 -0
  37. package/dist/schemas/access-token.js +1 -0
  38. package/dist/schemas/app.d.ts +46 -88
  39. package/dist/schemas/app.js +26 -20
  40. package/dist/schemas/cli-login.js +2 -1
  41. package/dist/schemas/error-codes.d.ts +14 -0
  42. package/dist/schemas/error-codes.js +6 -0
  43. package/dist/schemas/proxy-response.d.ts +1 -1
  44. package/dist/schemas/sponsored-api-key.d.ts +9 -3
  45. package/dist/schemas/sponsored-api-key.js +5 -0
  46. package/dist/schemas/topup.d.ts +52 -0
  47. package/dist/schemas/topup.js +44 -0
  48. package/dist/schemas/user.d.ts +1 -1
  49. package/dist/schemas/user.js +6 -3
  50. package/dist/type-utils.d.ts +9 -0
  51. package/dist/type-utils.js +19 -0
  52. package/package.json +6 -1
@@ -7,6 +7,7 @@ export const accessTokenSchema = z.object({
7
7
  budgetLimit: z.number().positive(),
8
8
  budgetSpent: z.number().default(0),
9
9
  isRevoked: z.boolean().default(false),
10
+ consentVersionAtIssue: z.number().int().positive().default(1),
10
11
  createdAt: z.string().datetime(),
11
12
  });
12
13
  export const authorizeAppRequest = z.object({
@@ -3,6 +3,7 @@ export declare const modelStrategySchema: z.ZodEnum<{
3
3
  any: "any";
4
4
  tier: "tier";
5
5
  models: "models";
6
+ none: "none";
6
7
  }>;
7
8
  export type ModelStrategy = z.infer<typeof modelStrategySchema>;
8
9
  export declare const tierSchema: z.ZodEnum<{
@@ -17,169 +18,126 @@ export declare const appSchema: z.ZodObject<{
17
18
  builderId: z.ZodString;
18
19
  name: z.ZodString;
19
20
  callbackUrl: z.ZodString;
20
- requiredProviders: z.ZodArray<z.ZodEnum<{
21
- anthropic: "anthropic";
22
- openai: "openai";
23
- bedrock: "bedrock";
24
- google: "google";
25
- grok: "grok";
26
- }>>;
27
- preferredProviders: z.ZodDefault<z.ZodArray<z.ZodEnum<{
28
- anthropic: "anthropic";
29
- openai: "openai";
30
- bedrock: "bedrock";
31
- google: "google";
32
- grok: "grok";
33
- }>>>;
34
- allowSubstitution: z.ZodDefault<z.ZodBoolean>;
35
- allowedModels: z.ZodOptional<z.ZodArray<z.ZodString>>;
21
+ allowedModels: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodString>>>;
36
22
  modelStrategy: z.ZodDefault<z.ZodEnum<{
37
23
  any: "any";
38
24
  tier: "tier";
39
25
  models: "models";
26
+ none: "none";
40
27
  }>>;
41
- requiredTier: z.ZodOptional<z.ZodEnum<{
28
+ requiredTier: z.ZodOptional<z.ZodNullable<z.ZodEnum<{
42
29
  cheap: "cheap";
43
30
  fast: "fast";
44
31
  smart: "smart";
45
32
  reasoning: "reasoning";
46
- }>>;
33
+ }>>>;
47
34
  allowsManagedAgents: z.ZodDefault<z.ZodBoolean>;
48
35
  websiteUrl: z.ZodOptional<z.ZodString>;
49
36
  description: z.ZodOptional<z.ZodString>;
50
- iconUrl: z.ZodOptional<z.ZodString>;
37
+ iconUrl: z.ZodOptional<z.ZodNullable<z.ZodString>>;
51
38
  appSecret: z.ZodString;
39
+ consentVersion: z.ZodDefault<z.ZodNumber>;
52
40
  createdAt: z.ZodString;
53
41
  }, z.core.$strip>;
54
42
  export type App = z.infer<typeof appSchema>;
55
43
  export declare const createAppRequestBase: z.ZodObject<{
56
44
  name: z.ZodString;
57
45
  callbackUrl: z.ZodString;
58
- requiredProviders: z.ZodArray<z.ZodEnum<{
59
- anthropic: "anthropic";
60
- openai: "openai";
61
- bedrock: "bedrock";
62
- google: "google";
63
- grok: "grok";
64
- }>>;
65
- preferredProviders: z.ZodDefault<z.ZodArray<z.ZodEnum<{
66
- anthropic: "anthropic";
67
- openai: "openai";
68
- bedrock: "bedrock";
69
- google: "google";
70
- grok: "grok";
71
- }>>>;
72
- allowSubstitution: z.ZodDefault<z.ZodBoolean>;
73
- allowedModels: z.ZodOptional<z.ZodArray<z.ZodString>>;
46
+ allowedModels: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodString>>>;
74
47
  modelStrategy: z.ZodDefault<z.ZodEnum<{
75
48
  any: "any";
76
49
  tier: "tier";
77
50
  models: "models";
51
+ none: "none";
78
52
  }>>;
79
- requiredTier: z.ZodOptional<z.ZodEnum<{
53
+ requiredTier: z.ZodOptional<z.ZodNullable<z.ZodEnum<{
80
54
  cheap: "cheap";
81
55
  fast: "fast";
82
56
  smart: "smart";
83
57
  reasoning: "reasoning";
84
- }>>;
58
+ }>>>;
85
59
  allowsManagedAgents: z.ZodDefault<z.ZodBoolean>;
86
60
  websiteUrl: z.ZodOptional<z.ZodString>;
87
61
  description: z.ZodOptional<z.ZodString>;
88
- iconUrl: z.ZodOptional<z.ZodString>;
62
+ iconUrl: z.ZodOptional<z.ZodNullable<z.ZodString>>;
89
63
  }, z.core.$strip>;
64
+ type StrategyShape = {
65
+ modelStrategy?: ModelStrategy;
66
+ requiredTier?: RequiredTier | null;
67
+ allowedModels?: readonly string[] | null;
68
+ allowsManagedAgents?: boolean;
69
+ };
70
+ export declare const hasAtLeastOneCapability: (v: StrategyShape) => boolean;
71
+ export declare const AT_LEAST_ONE_CAPABILITY_MESSAGE = "App must enable at least one capability \u2014 direct proxy calls or Managed Agents";
90
72
  export declare const createAppRequest: z.ZodType<{
91
73
  name: string;
92
74
  callbackUrl: string;
93
- requiredProviders: ("anthropic" | "openai" | "bedrock" | "google" | "grok")[];
94
- preferredProviders: ("anthropic" | "openai" | "bedrock" | "google" | "grok")[];
95
- allowSubstitution: boolean;
96
- modelStrategy: "any" | "tier" | "models";
75
+ modelStrategy: "any" | "tier" | "models" | "none";
97
76
  allowsManagedAgents: boolean;
98
- allowedModels?: string[] | undefined;
99
- requiredTier?: "cheap" | "fast" | "smart" | "reasoning" | undefined;
77
+ allowedModels?: string[] | null | undefined;
78
+ requiredTier?: "cheap" | "fast" | "smart" | "reasoning" | null | undefined;
100
79
  websiteUrl?: string | undefined;
101
80
  description?: string | undefined;
102
- iconUrl?: string | undefined;
81
+ iconUrl?: string | null | undefined;
103
82
  }, unknown, z.core.$ZodTypeInternals<{
104
83
  name: string;
105
84
  callbackUrl: string;
106
- requiredProviders: ("anthropic" | "openai" | "bedrock" | "google" | "grok")[];
107
- preferredProviders: ("anthropic" | "openai" | "bedrock" | "google" | "grok")[];
108
- allowSubstitution: boolean;
109
- modelStrategy: "any" | "tier" | "models";
85
+ modelStrategy: "any" | "tier" | "models" | "none";
110
86
  allowsManagedAgents: boolean;
111
- allowedModels?: string[] | undefined;
112
- requiredTier?: "cheap" | "fast" | "smart" | "reasoning" | undefined;
87
+ allowedModels?: string[] | null | undefined;
88
+ requiredTier?: "cheap" | "fast" | "smart" | "reasoning" | null | undefined;
113
89
  websiteUrl?: string | undefined;
114
90
  description?: string | undefined;
115
- iconUrl?: string | undefined;
91
+ iconUrl?: string | null | undefined;
116
92
  }, unknown>>;
117
93
  export type CreateAppRequest = z.infer<typeof createAppRequest>;
118
94
  export declare const updateAppRequest: z.ZodType<{
119
95
  name?: string | undefined;
120
96
  callbackUrl?: string | undefined;
121
- requiredProviders?: ("anthropic" | "openai" | "bedrock" | "google" | "grok")[] | undefined;
122
- preferredProviders?: ("anthropic" | "openai" | "bedrock" | "google" | "grok")[] | undefined;
123
- allowSubstitution?: boolean | undefined;
124
- allowedModels?: string[] | undefined;
125
- modelStrategy?: "any" | "tier" | "models" | undefined;
126
- requiredTier?: "cheap" | "fast" | "smart" | "reasoning" | undefined;
97
+ allowedModels?: string[] | null | undefined;
98
+ modelStrategy?: "any" | "tier" | "models" | "none" | undefined;
99
+ requiredTier?: "cheap" | "fast" | "smart" | "reasoning" | null | undefined;
127
100
  allowsManagedAgents?: boolean | undefined;
128
101
  websiteUrl?: string | undefined;
129
102
  description?: string | undefined;
130
- iconUrl?: string | undefined;
103
+ iconUrl?: string | null | undefined;
131
104
  }, unknown, z.core.$ZodTypeInternals<{
132
105
  name?: string | undefined;
133
106
  callbackUrl?: string | undefined;
134
- requiredProviders?: ("anthropic" | "openai" | "bedrock" | "google" | "grok")[] | undefined;
135
- preferredProviders?: ("anthropic" | "openai" | "bedrock" | "google" | "grok")[] | undefined;
136
- allowSubstitution?: boolean | undefined;
137
- allowedModels?: string[] | undefined;
138
- modelStrategy?: "any" | "tier" | "models" | undefined;
139
- requiredTier?: "cheap" | "fast" | "smart" | "reasoning" | undefined;
107
+ allowedModels?: string[] | null | undefined;
108
+ modelStrategy?: "any" | "tier" | "models" | "none" | undefined;
109
+ requiredTier?: "cheap" | "fast" | "smart" | "reasoning" | null | undefined;
140
110
  allowsManagedAgents?: boolean | undefined;
141
111
  websiteUrl?: string | undefined;
142
112
  description?: string | undefined;
143
- iconUrl?: string | undefined;
113
+ iconUrl?: string | null | undefined;
144
114
  }, unknown>>;
145
115
  export type UpdateAppRequest = z.infer<typeof updateAppRequest>;
146
116
  export declare const appResponse: z.ZodObject<{
147
- name: z.ZodString;
117
+ callbackUrl: z.ZodString;
118
+ allowedModels: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodString>>>;
148
119
  id: z.ZodString;
149
- createdAt: z.ZodString;
150
120
  builderId: z.ZodString;
151
- callbackUrl: z.ZodString;
152
- requiredProviders: z.ZodArray<z.ZodEnum<{
153
- anthropic: "anthropic";
154
- openai: "openai";
155
- bedrock: "bedrock";
156
- google: "google";
157
- grok: "grok";
158
- }>>;
159
- preferredProviders: z.ZodDefault<z.ZodArray<z.ZodEnum<{
160
- anthropic: "anthropic";
161
- openai: "openai";
162
- bedrock: "bedrock";
163
- google: "google";
164
- grok: "grok";
165
- }>>>;
166
- allowSubstitution: z.ZodDefault<z.ZodBoolean>;
167
- allowedModels: z.ZodOptional<z.ZodArray<z.ZodString>>;
121
+ name: z.ZodString;
168
122
  modelStrategy: z.ZodDefault<z.ZodEnum<{
169
123
  any: "any";
170
124
  tier: "tier";
171
125
  models: "models";
126
+ none: "none";
172
127
  }>>;
173
- requiredTier: z.ZodOptional<z.ZodEnum<{
128
+ requiredTier: z.ZodOptional<z.ZodNullable<z.ZodEnum<{
174
129
  cheap: "cheap";
175
130
  fast: "fast";
176
131
  smart: "smart";
177
132
  reasoning: "reasoning";
178
- }>>;
133
+ }>>>;
179
134
  allowsManagedAgents: z.ZodDefault<z.ZodBoolean>;
180
135
  websiteUrl: z.ZodOptional<z.ZodString>;
181
136
  description: z.ZodOptional<z.ZodString>;
182
- iconUrl: z.ZodOptional<z.ZodString>;
137
+ iconUrl: z.ZodOptional<z.ZodNullable<z.ZodString>>;
138
+ consentVersion: z.ZodDefault<z.ZodNumber>;
139
+ createdAt: z.ZodString;
183
140
  }, z.core.$strip>;
184
141
  export type AppResponse = z.infer<typeof appResponse>;
142
+ export {};
185
143
  //# sourceMappingURL=app.d.ts.map
@@ -1,41 +1,47 @@
1
1
  import { z } from 'zod';
2
- import { providerSchema } from './provider.js';
3
- export const modelStrategySchema = z.enum(['any', 'tier', 'models']);
4
- export const tierSchema = z.enum(['cheap', 'fast', 'smart', 'reasoning']);
2
+ import { ALL_MODELS } from '../catalog/models/index.js';
3
+ import { TIERS } from '../catalog/tiers.js';
4
+ import { enumKeys } from '../type-utils.js';
5
+ export const modelStrategySchema = z.enum(['any', 'tier', 'models', 'none']);
6
+ export const tierSchema = z.enum(enumKeys(TIERS));
7
+ const httpsUrl = z.string().url().refine((u) => /^https?:\/\//i.test(u), { message: 'URL must use http:// or https:// scheme' });
8
+ const knownModelSlugs = ALL_MODELS.map((m) => m.slug);
9
+ const allowedModelsField = z
10
+ .array(z.string())
11
+ .refine((slugs) => slugs.every((s) => knownModelSlugs.includes(s)), { message: `allowedModels must be slugs from the model catalog` })
12
+ .nullish();
5
13
  export const appSchema = z.object({
6
14
  id: z.string().uuid(),
7
15
  builderId: z.string().uuid(),
8
16
  name: z.string().min(1).max(100),
9
- callbackUrl: z.string().url(),
10
- requiredProviders: z.array(providerSchema),
11
- preferredProviders: z.array(providerSchema).default([]),
12
- allowSubstitution: z.boolean().default(false),
13
- allowedModels: z.array(z.string()).optional(),
17
+ callbackUrl: httpsUrl,
18
+ allowedModels: allowedModelsField,
14
19
  modelStrategy: modelStrategySchema.default('any'),
15
- requiredTier: tierSchema.optional(),
20
+ requiredTier: tierSchema.nullish(),
16
21
  allowsManagedAgents: z.boolean().default(false),
17
- websiteUrl: z.string().url().optional(),
22
+ websiteUrl: httpsUrl.optional(),
18
23
  description: z.string().max(500).optional(),
19
- iconUrl: z.string().url().optional(),
24
+ iconUrl: httpsUrl.nullish(),
20
25
  appSecret: z.string(),
26
+ consentVersion: z.number().int().positive().default(1),
21
27
  createdAt: z.string().datetime(),
22
28
  });
23
29
  export const createAppRequestBase = z.object({
24
30
  name: z.string().min(1).max(100),
25
- callbackUrl: z.string().url(),
26
- requiredProviders: z.array(providerSchema).min(1),
27
- preferredProviders: z.array(providerSchema).default([]),
28
- allowSubstitution: z.boolean().default(false),
29
- allowedModels: z.array(z.string()).optional(),
31
+ callbackUrl: httpsUrl,
32
+ allowedModels: allowedModelsField,
30
33
  modelStrategy: modelStrategySchema.default('any'),
31
- requiredTier: tierSchema.optional(),
34
+ requiredTier: tierSchema.nullish(),
32
35
  allowsManagedAgents: z.boolean().default(false),
33
- websiteUrl: z.string().url().optional(),
36
+ websiteUrl: httpsUrl.optional(),
34
37
  description: z.string().max(500).optional(),
35
- iconUrl: z.string().url().optional(),
38
+ iconUrl: httpsUrl.nullish(),
36
39
  });
37
40
  const refineStrategy = (s) => s.refine((v) => v.modelStrategy !== 'tier' || !!v.requiredTier, { message: "modelStrategy='tier' requires requiredTier", path: ['requiredTier'] }).refine((v) => v.modelStrategy !== 'models' || (v.allowedModels?.length ?? 0) > 0, { message: "modelStrategy='models' requires non-empty allowedModels", path: ['allowedModels'] });
38
- export const createAppRequest = refineStrategy(createAppRequestBase);
41
+ export const hasAtLeastOneCapability = (v) => v.modelStrategy !== 'none' || v.allowsManagedAgents === true;
42
+ export const AT_LEAST_ONE_CAPABILITY_MESSAGE = 'App must enable at least one capability — direct proxy calls or Managed Agents';
43
+ const refineCapabilityFloor = (s) => s.refine(hasAtLeastOneCapability, { message: AT_LEAST_ONE_CAPABILITY_MESSAGE, path: ['modelStrategy'] });
44
+ export const createAppRequest = refineCapabilityFloor(refineStrategy(createAppRequestBase));
39
45
  export const updateAppRequest = refineStrategy(createAppRequestBase.partial());
40
46
  export const appResponse = appSchema.omit({ appSecret: true });
41
47
  //# sourceMappingURL=app.js.map
@@ -1,10 +1,11 @@
1
1
  import { z } from 'zod';
2
+ import { enumValues } from '../type-utils.js';
2
3
  export const CliLoopbackHost = {
3
4
  V4: '127.0.0.1',
4
5
  V6: '[::1]',
5
6
  Localhost: 'localhost',
6
7
  };
7
- const cliLoopbackHostSchema = z.enum([CliLoopbackHost.V4, CliLoopbackHost.V6, CliLoopbackHost.Localhost]);
8
+ const cliLoopbackHostSchema = z.enum(enumValues(CliLoopbackHost));
8
9
  export const cliLoginParamsSchema = z.object({
9
10
  port: z.coerce.number().int().min(1).max(65535),
10
11
  state: z.string().min(8).max(128),
@@ -54,6 +54,16 @@ export declare const proxyErrorCodes: {
54
54
  readonly status: 403;
55
55
  readonly message: "App does not have the managed-agents scope";
56
56
  };
57
+ readonly PROXY_NOT_ALLOWED: {
58
+ readonly code: "PROXY_NOT_ALLOWED";
59
+ readonly status: 403;
60
+ readonly message: "App does not allow direct provider calls; use the managed-agents endpoints instead";
61
+ };
62
+ readonly CONSENT_OUTDATED: {
63
+ readonly code: "CONSENT_OUTDATED";
64
+ readonly status: 401;
65
+ readonly message: "App requirements have changed since you authorized";
66
+ };
57
67
  readonly SPONSORED_POOL_EXHAUSTED: {
58
68
  readonly code: "SPONSORED_POOL_EXHAUSTED";
59
69
  readonly status: 402;
@@ -146,6 +156,10 @@ export declare const apiErrorCodes: {
146
156
  readonly DECRYPTION_FAILED: "DECRYPTION_FAILED";
147
157
  readonly DB_INSERT_FAILED: "DB_INSERT_FAILED";
148
158
  readonly FETCH_FAILED: "FETCH_FAILED";
159
+ readonly PAYLOAD_TOO_LARGE: "PAYLOAD_TOO_LARGE";
160
+ readonly INVALID_REDIRECT_URI: "INVALID_REDIRECT_URI";
161
+ readonly ACCOUNT_DELETED: "ACCOUNT_DELETED";
162
+ readonly RATE_LIMITED_PROXY: "RATE_LIMITED_PROXY";
149
163
  };
150
164
  export type ProxyErrorCode = keyof typeof proxyErrorCodes;
151
165
  export type ProviderErrorCode = keyof typeof providerErrorCodes;
@@ -10,6 +10,8 @@ export const proxyErrorCodes = {
10
10
  APP_NOT_FOUND: { code: 'APP_NOT_FOUND', status: 404, message: 'Application not found' },
11
11
  MODEL_NOT_ALLOWED: { code: 'MODEL_NOT_ALLOWED', status: 403, message: 'Model not in allowed models list' },
12
12
  AGENT_SCOPE_MISSING: { code: 'AGENT_SCOPE_MISSING', status: 403, message: 'App does not have the managed-agents scope' },
13
+ PROXY_NOT_ALLOWED: { code: 'PROXY_NOT_ALLOWED', status: 403, message: 'App does not allow direct provider calls; use the managed-agents endpoints instead' },
14
+ CONSENT_OUTDATED: { code: 'CONSENT_OUTDATED', status: 401, message: 'App requirements have changed since you authorized' },
13
15
  SPONSORED_POOL_EXHAUSTED: { code: 'SPONSORED_POOL_EXHAUSTED', status: 402, message: 'Sponsored credits pool is exhausted' },
14
16
  SPONSORED_KEY_UNAVAILABLE: { code: 'SPONSORED_KEY_UNAVAILABLE', status: 402, message: 'Sponsored key is no longer active' },
15
17
  SPONSORED_PROVIDER_MISMATCH: { code: 'SPONSORED_PROVIDER_MISMATCH', status: 402, message: 'Sponsored key does not cover requested provider' },
@@ -58,5 +60,9 @@ export const apiErrorCodes = {
58
60
  DECRYPTION_FAILED: 'DECRYPTION_FAILED',
59
61
  DB_INSERT_FAILED: 'DB_INSERT_FAILED',
60
62
  FETCH_FAILED: 'FETCH_FAILED',
63
+ PAYLOAD_TOO_LARGE: 'PAYLOAD_TOO_LARGE',
64
+ INVALID_REDIRECT_URI: 'INVALID_REDIRECT_URI',
65
+ ACCOUNT_DELETED: 'ACCOUNT_DELETED',
66
+ RATE_LIMITED_PROXY: 'RATE_LIMITED_PROXY',
61
67
  };
62
68
  //# sourceMappingURL=error-codes.js.map
@@ -39,8 +39,8 @@ export declare const proxyResponseSchema: z.ZodUnion<readonly [z.ZodObject<{
39
39
  code: z.ZodString;
40
40
  message: z.ZodString;
41
41
  source: z.ZodEnum<{
42
- proxy: "proxy";
43
42
  provider: "provider";
43
+ proxy: "proxy";
44
44
  }>;
45
45
  details: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
46
46
  }, z.core.$strip>;
@@ -31,6 +31,12 @@ export declare const addSponsoredApiKeyRequest: z.ZodObject<{
31
31
  perUserBudgetUsd: z.ZodOptional<z.ZodNumber>;
32
32
  }, z.core.$strip>;
33
33
  export type AddSponsoredApiKeyRequest = z.infer<typeof addSponsoredApiKeyRequest>;
34
+ export declare const updateSponsoredApiKeyRequest: z.ZodObject<{
35
+ totalBudgetUsd: z.ZodOptional<z.ZodNumber>;
36
+ perUserBudgetUsd: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
37
+ isActive: z.ZodOptional<z.ZodBoolean>;
38
+ }, z.core.$strip>;
39
+ export type UpdateSponsoredApiKeyRequest = z.infer<typeof updateSponsoredApiKeyRequest>;
34
40
  export declare const sponsoredKeyConsumerSchema: z.ZodObject<{
35
41
  userId: z.ZodString;
36
42
  email: z.ZodString;
@@ -47,13 +53,13 @@ export declare const sponsoredApiKeyResponse: z.ZodObject<{
47
53
  grok: "grok";
48
54
  }>;
49
55
  id: z.ZodString;
50
- createdAt: z.ZodString;
51
- keyHint: z.ZodString;
52
- isActive: z.ZodDefault<z.ZodBoolean>;
53
56
  appId: z.ZodString;
57
+ keyHint: z.ZodString;
54
58
  totalBudgetUsd: z.ZodNumber;
55
59
  totalSpentUsd: z.ZodDefault<z.ZodNumber>;
56
60
  perUserBudgetUsd: z.ZodNullable<z.ZodNumber>;
61
+ isActive: z.ZodDefault<z.ZodBoolean>;
62
+ createdAt: z.ZodString;
57
63
  consumers: z.ZodArray<z.ZodObject<{
58
64
  userId: z.ZodString;
59
65
  email: z.ZodString;
@@ -18,6 +18,11 @@ export const addSponsoredApiKeyRequest = z.object({
18
18
  totalBudgetUsd: z.number().positive(),
19
19
  perUserBudgetUsd: z.number().positive().optional(),
20
20
  });
21
+ export const updateSponsoredApiKeyRequest = z.object({
22
+ totalBudgetUsd: z.number().positive().optional(),
23
+ perUserBudgetUsd: z.number().positive().nullable().optional(),
24
+ isActive: z.boolean().optional(),
25
+ }).refine((v) => v.totalBudgetUsd !== undefined || v.perUserBudgetUsd !== undefined || v.isActive !== undefined, { message: 'Provide at least one field to update' });
21
26
  export const sponsoredKeyConsumerSchema = z.object({
22
27
  userId: z.string().uuid(),
23
28
  email: z.string(),
@@ -0,0 +1,52 @@
1
+ import { z } from 'zod';
2
+ export declare const TopupMessageType: {
3
+ readonly Success: "tokenite:topup-success";
4
+ readonly Cancelled: "tokenite:topup-cancelled";
5
+ };
6
+ export declare const AuthMessageType: {
7
+ readonly Success: "tokenite:auth-success";
8
+ readonly Error: "tokenite:auth-error";
9
+ };
10
+ export declare const topupContextResponse: z.ZodObject<{
11
+ appName: z.ZodString;
12
+ appIconUrl: z.ZodNullable<z.ZodString>;
13
+ callbackUrl: z.ZodString;
14
+ tokenId: z.ZodString;
15
+ currentLimit: z.ZodNumber;
16
+ currentSpent: z.ZodNumber;
17
+ }, z.core.$strip>;
18
+ export type TopupContextResponse = z.infer<typeof topupContextResponse>;
19
+ export declare const topupRaiseRequest: z.ZodObject<{
20
+ client_id: z.ZodString;
21
+ new_budget_limit: z.ZodNumber;
22
+ }, z.core.$strip>;
23
+ export type TopupRaiseRequest = z.infer<typeof topupRaiseRequest>;
24
+ export declare const topupRaiseResponse: z.ZodObject<{
25
+ newLimit: z.ZodNumber;
26
+ remaining: z.ZodNumber;
27
+ callbackUrl: z.ZodString;
28
+ }, z.core.$strip>;
29
+ export type TopupRaiseResponse = z.infer<typeof topupRaiseResponse>;
30
+ export declare const topupSuccessMessage: z.ZodObject<{
31
+ type: z.ZodLiteral<"tokenite:topup-success">;
32
+ newLimit: z.ZodNumber;
33
+ remaining: z.ZodNumber;
34
+ }, z.core.$strip>;
35
+ export declare const topupCancelledMessage: z.ZodObject<{
36
+ type: z.ZodLiteral<"tokenite:topup-cancelled">;
37
+ }, z.core.$strip>;
38
+ export declare const topupPostMessage: z.ZodDiscriminatedUnion<[z.ZodObject<{
39
+ type: z.ZodLiteral<"tokenite:topup-success">;
40
+ newLimit: z.ZodNumber;
41
+ remaining: z.ZodNumber;
42
+ }, z.core.$strip>, z.ZodObject<{
43
+ type: z.ZodLiteral<"tokenite:topup-cancelled">;
44
+ }, z.core.$strip>], "type">;
45
+ export type TopupPostMessage = z.infer<typeof topupPostMessage>;
46
+ export declare const fundingErrorDetails: z.ZodObject<{
47
+ remaining: z.ZodOptional<z.ZodNumber>;
48
+ currentLimit: z.ZodOptional<z.ZodNumber>;
49
+ currentSpent: z.ZodOptional<z.ZodNumber>;
50
+ }, z.core.$loose>;
51
+ export type FundingErrorDetails = z.infer<typeof fundingErrorDetails>;
52
+ //# sourceMappingURL=topup.d.ts.map
@@ -0,0 +1,44 @@
1
+ import { z } from 'zod';
2
+ export const TopupMessageType = {
3
+ Success: 'tokenite:topup-success',
4
+ Cancelled: 'tokenite:topup-cancelled',
5
+ };
6
+ export const AuthMessageType = {
7
+ Success: 'tokenite:auth-success',
8
+ Error: 'tokenite:auth-error',
9
+ };
10
+ export const topupContextResponse = z.object({
11
+ appName: z.string(),
12
+ appIconUrl: z.string().nullable(),
13
+ callbackUrl: z.string().url(),
14
+ tokenId: z.string().uuid(),
15
+ currentLimit: z.number().nonnegative(),
16
+ currentSpent: z.number().nonnegative(),
17
+ });
18
+ export const topupRaiseRequest = z.object({
19
+ client_id: z.string().uuid(),
20
+ new_budget_limit: z.number().positive(),
21
+ });
22
+ export const topupRaiseResponse = z.object({
23
+ newLimit: z.number().nonnegative(),
24
+ remaining: z.number().nonnegative(),
25
+ callbackUrl: z.string().url(),
26
+ });
27
+ export const topupSuccessMessage = z.object({
28
+ type: z.literal(TopupMessageType.Success),
29
+ newLimit: z.number().nonnegative(),
30
+ remaining: z.number().nonnegative(),
31
+ });
32
+ export const topupCancelledMessage = z.object({
33
+ type: z.literal(TopupMessageType.Cancelled),
34
+ });
35
+ export const topupPostMessage = z.discriminatedUnion('type', [
36
+ topupSuccessMessage,
37
+ topupCancelledMessage,
38
+ ]);
39
+ export const fundingErrorDetails = z.object({
40
+ remaining: z.number().nonnegative().optional(),
41
+ currentLimit: z.number().nonnegative().optional(),
42
+ currentSpent: z.number().nonnegative().optional(),
43
+ }).passthrough();
44
+ //# sourceMappingURL=topup.js.map
@@ -8,7 +8,7 @@ export declare const userSchema: z.ZodObject<{
8
8
  export type User = z.infer<typeof userSchema>;
9
9
  export declare const createUserRequest: z.ZodObject<{
10
10
  email: z.ZodString;
11
- password: z.ZodOptional<z.ZodString>;
11
+ password: z.ZodString;
12
12
  }, z.core.$strip>;
13
13
  export type CreateUserRequest = z.infer<typeof createUserRequest>;
14
14
  export declare const userResponse: z.ZodObject<{
@@ -1,13 +1,16 @@
1
1
  import { z } from 'zod';
2
2
  export const userSchema = z.object({
3
3
  id: z.string().uuid(),
4
- email: z.string().email(),
4
+ email: z.string().email().max(254),
5
5
  passwordHash: z.string().optional(),
6
6
  createdAt: z.string().datetime(),
7
7
  });
8
+ // Password is required for the email/password register flow. Social
9
+ // flows mint an account inside `loginOrCreateFromSocial`, never via
10
+ // this schema. Removing the `.optional()` closes F-043.
8
11
  export const createUserRequest = z.object({
9
- email: z.string().email(),
10
- password: z.string().min(8).max(128).optional(),
12
+ email: z.string().email().max(254),
13
+ password: z.string().min(8).max(72),
11
14
  });
12
15
  export const userResponse = userSchema.omit({ passwordHash: true });
13
16
  //# sourceMappingURL=user.js.map
@@ -0,0 +1,9 @@
1
+ type StringKeys<T> = Extract<keyof T, string>;
2
+ export type NonEmptyKeyTuple<T> = T extends Record<string, unknown> ? readonly [StringKeys<T>, ...StringKeys<T>[]] : never;
3
+ export type NonEmptyValueTuple<T> = T extends Record<string, infer V> ? readonly [V, ...V[]] : never;
4
+ export type NonEmptyEntryTuple<T> = T extends Record<string, infer V> ? readonly [readonly [StringKeys<T>, V], ...(readonly [StringKeys<T>, V])[]] : never;
5
+ export declare const enumKeys: <T extends Record<string, unknown>>(obj: T) => NonEmptyKeyTuple<T>;
6
+ export declare const enumValues: <T extends Record<string, unknown>>(obj: T) => NonEmptyValueTuple<T>;
7
+ export declare const enumEntries: <T extends Record<string, unknown>>(obj: T) => NonEmptyEntryTuple<T>;
8
+ export {};
9
+ //# sourceMappingURL=type-utils.d.ts.map
@@ -0,0 +1,19 @@
1
+ export const enumKeys = (obj) => {
2
+ const keys = Object.keys(obj);
3
+ if (keys.length === 0)
4
+ throw new Error('enumKeys requires a non-empty object');
5
+ return keys;
6
+ };
7
+ export const enumValues = (obj) => {
8
+ const values = Object.values(obj);
9
+ if (values.length === 0)
10
+ throw new Error('enumValues requires a non-empty object');
11
+ return values;
12
+ };
13
+ export const enumEntries = (obj) => {
14
+ const entries = Object.entries(obj);
15
+ if (entries.length === 0)
16
+ throw new Error('enumEntries requires a non-empty object');
17
+ return entries;
18
+ };
19
+ //# sourceMappingURL=type-utils.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tokenite/shared",
3
- "version": "1.0.1",
3
+ "version": "1.1.0",
4
4
  "description": "Shared types, schemas, and model catalog for the Tokenite SDK and CLI. Public protocol surface.",
5
5
  "type": "module",
6
6
  "exports": {
@@ -16,6 +16,10 @@
16
16
  "types": "./dist/catalog/index.d.ts",
17
17
  "import": "./dist/catalog/index.js"
18
18
  },
19
+ "./assets": {
20
+ "types": "./dist/assets.d.ts",
21
+ "import": "./dist/assets.js"
22
+ },
19
23
  "./schemas/cli-login": {
20
24
  "types": "./dist/schemas/cli-login.d.ts",
21
25
  "import": "./dist/schemas/cli-login.js"
@@ -31,6 +35,7 @@
31
35
  },
32
36
  "files": [
33
37
  "dist",
38
+ "assets",
34
39
  "README.md",
35
40
  "LICENSE"
36
41
  ],