@kya-os/contracts 1.6.2-canary.0 → 1.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -6,6 +6,7 @@
6
6
  *
7
7
  * @module @kya-os/contracts/config
8
8
  */
9
+ import { z } from "zod";
9
10
  /**
10
11
  * Runtime Identity Configuration
11
12
  *
@@ -25,7 +26,7 @@ export interface RuntimeIdentityConfig {
25
26
  * Runtime environment for identity
26
27
  * Determines where keys come from and how they're managed
27
28
  */
28
- environment: 'development' | 'production';
29
+ environment: "development" | "production";
29
30
  /**
30
31
  * Production identity configuration
31
32
  * Used when environment is 'production'
@@ -71,7 +72,218 @@ export interface RuntimeIdentityConfig {
71
72
  * - 'persistent': User DIDs are persisted in storage (requires did:web setup)
72
73
  * @default 'ephemeral'
73
74
  */
74
- userDidStorage?: 'ephemeral' | 'persistent';
75
+ userDidStorage?: "ephemeral" | "persistent";
76
+ }
77
+ /**
78
+ * OAuth Provider Configuration
79
+ *
80
+ * Configuration for a single OAuth provider (GitHub, Google, etc.)
81
+ */
82
+ export interface OAuthProvider {
83
+ /** OAuth client ID (public, safe to expose) */
84
+ clientId: string;
85
+ /** OAuth client secret (NOT returned in API response for security) */
86
+ clientSecret?: string | null;
87
+ /** OAuth authorization URL */
88
+ authorizationUrl: string;
89
+ /** OAuth token exchange URL */
90
+ tokenUrl: string;
91
+ /** OAuth user info endpoint URL */
92
+ userInfoUrl?: string;
93
+ /** Whether provider supports PKCE (Proof Key for Code Exchange) */
94
+ supportsPKCE: boolean;
95
+ /** Whether provider requires client secret (false for PKCE-only providers) */
96
+ requiresClientSecret: boolean;
97
+ /** Available scopes for this provider */
98
+ scopes?: string[];
99
+ /** Default scopes to request */
100
+ defaultScopes?: string[];
101
+ /** Whether provider uses proxy mode (via AgentShield) */
102
+ proxyMode?: boolean;
103
+ /** Custom OAuth parameters to include in authorization URL (e.g., audience, acr_values) */
104
+ customParams?: Record<string, string>;
105
+ /** Token endpoint authentication method */
106
+ tokenEndpointAuthMethod?: "client_secret_post" | "client_secret_basic";
107
+ /** OAuth response type (default: "code") */
108
+ responseType?: string;
109
+ /** OAuth grant type (default: "authorization_code") */
110
+ grantType?: string;
111
+ }
112
+ /**
113
+ * OAuth Configuration
114
+ *
115
+ * Configuration for OAuth providers fetched from AgentShield API.
116
+ * Contains all available providers for a project.
117
+ *
118
+ * The `configuredProvider` field indicates which provider (if any) has been
119
+ * explicitly configured in the AgentShield dashboard for this project.
120
+ * Phase 2+ requires tools to explicitly specify oauthProvider.
121
+ */
122
+ export interface OAuthConfig {
123
+ /** Map of provider names to provider configurations */
124
+ providers: Record<string, OAuthProvider>;
125
+ /**
126
+ * The explicitly configured OAuth provider for this project.
127
+ * Null if no provider has been configured in AgentShield dashboard.
128
+ * Used by ProviderResolver as fallback when tool doesn't specify oauthProvider.
129
+ */
130
+ configuredProvider?: string | null;
131
+ }
132
+ /**
133
+ * Zod schema for OAuthProvider validation
134
+ */
135
+ export declare const OAuthProviderSchema: z.ZodObject<{
136
+ clientId: z.ZodString;
137
+ clientSecret: z.ZodOptional<z.ZodNullable<z.ZodString>>;
138
+ authorizationUrl: z.ZodString;
139
+ tokenUrl: z.ZodString;
140
+ userInfoUrl: z.ZodOptional<z.ZodString>;
141
+ supportsPKCE: z.ZodBoolean;
142
+ requiresClientSecret: z.ZodBoolean;
143
+ scopes: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
144
+ defaultScopes: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
145
+ proxyMode: z.ZodOptional<z.ZodBoolean>;
146
+ customParams: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
147
+ tokenEndpointAuthMethod: z.ZodOptional<z.ZodEnum<["client_secret_post", "client_secret_basic"]>>;
148
+ responseType: z.ZodDefault<z.ZodOptional<z.ZodString>>;
149
+ grantType: z.ZodDefault<z.ZodOptional<z.ZodString>>;
150
+ }, "strip", z.ZodTypeAny, {
151
+ clientId: string;
152
+ authorizationUrl: string;
153
+ tokenUrl: string;
154
+ supportsPKCE: boolean;
155
+ requiresClientSecret: boolean;
156
+ responseType: string;
157
+ grantType: string;
158
+ scopes?: string[] | undefined;
159
+ clientSecret?: string | null | undefined;
160
+ userInfoUrl?: string | undefined;
161
+ defaultScopes?: string[] | undefined;
162
+ proxyMode?: boolean | undefined;
163
+ customParams?: Record<string, string> | undefined;
164
+ tokenEndpointAuthMethod?: "client_secret_post" | "client_secret_basic" | undefined;
165
+ }, {
166
+ clientId: string;
167
+ authorizationUrl: string;
168
+ tokenUrl: string;
169
+ supportsPKCE: boolean;
170
+ requiresClientSecret: boolean;
171
+ scopes?: string[] | undefined;
172
+ clientSecret?: string | null | undefined;
173
+ userInfoUrl?: string | undefined;
174
+ defaultScopes?: string[] | undefined;
175
+ proxyMode?: boolean | undefined;
176
+ customParams?: Record<string, string> | undefined;
177
+ tokenEndpointAuthMethod?: "client_secret_post" | "client_secret_basic" | undefined;
178
+ responseType?: string | undefined;
179
+ grantType?: string | undefined;
180
+ }>;
181
+ /**
182
+ * Zod schema for OAuthConfig validation
183
+ */
184
+ export declare const OAuthConfigSchema: z.ZodObject<{
185
+ providers: z.ZodRecord<z.ZodString, z.ZodObject<{
186
+ clientId: z.ZodString;
187
+ clientSecret: z.ZodOptional<z.ZodNullable<z.ZodString>>;
188
+ authorizationUrl: z.ZodString;
189
+ tokenUrl: z.ZodString;
190
+ userInfoUrl: z.ZodOptional<z.ZodString>;
191
+ supportsPKCE: z.ZodBoolean;
192
+ requiresClientSecret: z.ZodBoolean;
193
+ scopes: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
194
+ defaultScopes: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
195
+ proxyMode: z.ZodOptional<z.ZodBoolean>;
196
+ customParams: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
197
+ tokenEndpointAuthMethod: z.ZodOptional<z.ZodEnum<["client_secret_post", "client_secret_basic"]>>;
198
+ responseType: z.ZodDefault<z.ZodOptional<z.ZodString>>;
199
+ grantType: z.ZodDefault<z.ZodOptional<z.ZodString>>;
200
+ }, "strip", z.ZodTypeAny, {
201
+ clientId: string;
202
+ authorizationUrl: string;
203
+ tokenUrl: string;
204
+ supportsPKCE: boolean;
205
+ requiresClientSecret: boolean;
206
+ responseType: string;
207
+ grantType: string;
208
+ scopes?: string[] | undefined;
209
+ clientSecret?: string | null | undefined;
210
+ userInfoUrl?: string | undefined;
211
+ defaultScopes?: string[] | undefined;
212
+ proxyMode?: boolean | undefined;
213
+ customParams?: Record<string, string> | undefined;
214
+ tokenEndpointAuthMethod?: "client_secret_post" | "client_secret_basic" | undefined;
215
+ }, {
216
+ clientId: string;
217
+ authorizationUrl: string;
218
+ tokenUrl: string;
219
+ supportsPKCE: boolean;
220
+ requiresClientSecret: boolean;
221
+ scopes?: string[] | undefined;
222
+ clientSecret?: string | null | undefined;
223
+ userInfoUrl?: string | undefined;
224
+ defaultScopes?: string[] | undefined;
225
+ proxyMode?: boolean | undefined;
226
+ customParams?: Record<string, string> | undefined;
227
+ tokenEndpointAuthMethod?: "client_secret_post" | "client_secret_basic" | undefined;
228
+ responseType?: string | undefined;
229
+ grantType?: string | undefined;
230
+ }>>;
231
+ configuredProvider: z.ZodOptional<z.ZodNullable<z.ZodString>>;
232
+ }, "strip", z.ZodTypeAny, {
233
+ providers: Record<string, {
234
+ clientId: string;
235
+ authorizationUrl: string;
236
+ tokenUrl: string;
237
+ supportsPKCE: boolean;
238
+ requiresClientSecret: boolean;
239
+ responseType: string;
240
+ grantType: string;
241
+ scopes?: string[] | undefined;
242
+ clientSecret?: string | null | undefined;
243
+ userInfoUrl?: string | undefined;
244
+ defaultScopes?: string[] | undefined;
245
+ proxyMode?: boolean | undefined;
246
+ customParams?: Record<string, string> | undefined;
247
+ tokenEndpointAuthMethod?: "client_secret_post" | "client_secret_basic" | undefined;
248
+ }>;
249
+ configuredProvider?: string | null | undefined;
250
+ }, {
251
+ providers: Record<string, {
252
+ clientId: string;
253
+ authorizationUrl: string;
254
+ tokenUrl: string;
255
+ supportsPKCE: boolean;
256
+ requiresClientSecret: boolean;
257
+ scopes?: string[] | undefined;
258
+ clientSecret?: string | null | undefined;
259
+ userInfoUrl?: string | undefined;
260
+ defaultScopes?: string[] | undefined;
261
+ proxyMode?: boolean | undefined;
262
+ customParams?: Record<string, string> | undefined;
263
+ tokenEndpointAuthMethod?: "client_secret_post" | "client_secret_basic" | undefined;
264
+ responseType?: string | undefined;
265
+ grantType?: string | undefined;
266
+ }>;
267
+ configuredProvider?: string | null | undefined;
268
+ }>;
269
+ /**
270
+ * IDP Tokens
271
+ *
272
+ * Tokens received from OAuth provider (IDP = Identity Provider)
273
+ */
274
+ export interface IdpTokens {
275
+ /** OAuth access token for API calls */
276
+ access_token: string;
277
+ /** OAuth refresh token (optional) */
278
+ refresh_token?: string;
279
+ /** Token expiration time in seconds */
280
+ expires_in?: number;
281
+ /** Token expiration timestamp (milliseconds since epoch) */
282
+ expires_at: number;
283
+ /** Token type (usually "Bearer") */
284
+ token_type: string;
285
+ /** Granted scopes */
286
+ scope?: string;
75
287
  }
76
288
  /**
77
289
  * Agent identity representation
@@ -8,3 +8,32 @@
8
8
  * @module @kya-os/contracts/config
9
9
  */
10
10
  Object.defineProperty(exports, "__esModule", { value: true });
11
+ exports.OAuthConfigSchema = exports.OAuthProviderSchema = void 0;
12
+ const zod_1 = require("zod");
13
+ /**
14
+ * Zod schema for OAuthProvider validation
15
+ */
16
+ exports.OAuthProviderSchema = zod_1.z.object({
17
+ clientId: zod_1.z.string().min(1),
18
+ clientSecret: zod_1.z.string().nullable().optional(),
19
+ authorizationUrl: zod_1.z.string().url(),
20
+ tokenUrl: zod_1.z.string().url(),
21
+ userInfoUrl: zod_1.z.string().url().optional(),
22
+ supportsPKCE: zod_1.z.boolean(),
23
+ requiresClientSecret: zod_1.z.boolean(),
24
+ scopes: zod_1.z.array(zod_1.z.string()).optional(),
25
+ defaultScopes: zod_1.z.array(zod_1.z.string()).optional(),
26
+ proxyMode: zod_1.z.boolean().optional(),
27
+ // Phase 3: Custom IDP Support
28
+ customParams: zod_1.z.record(zod_1.z.string()).optional(),
29
+ tokenEndpointAuthMethod: zod_1.z.enum(["client_secret_post", "client_secret_basic"]).optional(),
30
+ responseType: zod_1.z.string().optional().default("code"),
31
+ grantType: zod_1.z.string().optional().default("authorization_code"),
32
+ });
33
+ /**
34
+ * Zod schema for OAuthConfig validation
35
+ */
36
+ exports.OAuthConfigSchema = zod_1.z.object({
37
+ providers: zod_1.z.record(zod_1.z.string(), exports.OAuthProviderSchema),
38
+ configuredProvider: zod_1.z.string().nullable().optional(),
39
+ });
@@ -12,7 +12,8 @@ import type { ProofingConfig } from "./proofing.js";
12
12
  import type { DelegationConfig } from "./delegation.js";
13
13
  import type { ToolProtectionSourceConfig } from "./tool-protection.js";
14
14
  export { MCPIBaseConfig } from "./base.js";
15
- export { RuntimeIdentityConfig, AgentIdentity } from "./identity.js";
15
+ export { RuntimeIdentityConfig, AgentIdentity, OAuthProvider, OAuthConfig, IdpTokens, } from "./identity.js";
16
+ export type { ToolExecutionContext } from "./tool-context.js";
16
17
  /**
17
18
  * @deprecated Use RuntimeIdentityConfig instead
18
19
  * This export is maintained for backward compatibility
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Tool Execution Context
3
+ *
4
+ * Execution context passed to tool handlers, enabling tools to access
5
+ * IDP tokens for external API calls (GitHub, Google, etc.).
6
+ *
7
+ * All fields are optional for backward compatibility - tools that don't
8
+ * require OAuth will receive undefined context.
9
+ *
10
+ * @package @kya-os/contracts
11
+ */
12
+ /**
13
+ * Execution context passed to tool handlers
14
+ *
15
+ * Enables tools to access IDP tokens for external API calls.
16
+ * Context is only provided when:
17
+ * - Tool requires OAuth (has requiredScopes)
18
+ * - User DID is available
19
+ * - IDP token is successfully resolved
20
+ */
21
+ export interface ToolExecutionContext {
22
+ /** IDP access token for external API calls (e.g., GitHub, Google) */
23
+ idpToken?: string;
24
+ /** OAuth provider name (e.g., "github", "google") */
25
+ provider?: string;
26
+ /** Scopes granted for this token */
27
+ scopes?: string[];
28
+ /** User DID associated with this token */
29
+ userDid?: string;
30
+ /** Session ID */
31
+ sessionId?: string;
32
+ /** Delegation token (MCP-I internal authorization) */
33
+ delegationToken?: string;
34
+ }
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ /**
3
+ * Tool Execution Context
4
+ *
5
+ * Execution context passed to tool handlers, enabling tools to access
6
+ * IDP tokens for external API calls (GitHub, Google, etc.).
7
+ *
8
+ * All fields are optional for backward compatibility - tools that don't
9
+ * require OAuth will receive undefined context.
10
+ *
11
+ * @package @kya-os/contracts
12
+ */
13
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -165,13 +165,14 @@ export type OAuthIdentity = z.infer<typeof oauthIdentitySchema>;
165
165
  /**
166
166
  * Consent Page Config Schema
167
167
  */
168
- export declare const consentPageConfigSchema: z.ZodObject<{
168
+ export declare const consentPageConfigSchema: z.ZodEffects<z.ZodObject<{
169
169
  tool: z.ZodString;
170
170
  toolDescription: z.ZodString;
171
171
  scopes: z.ZodArray<z.ZodString, "many">;
172
172
  agentDid: z.ZodString;
173
173
  sessionId: z.ZodString;
174
174
  projectId: z.ZodString;
175
+ provider: z.ZodOptional<z.ZodString>;
175
176
  branding: z.ZodOptional<z.ZodObject<{
176
177
  primaryColor: z.ZodOptional<z.ZodString>;
177
178
  logoUrl: z.ZodOptional<z.ZodString>;
@@ -268,14 +269,25 @@ export declare const consentPageConfigSchema: z.ZodObject<{
268
269
  }>, "many">>;
269
270
  serverUrl: z.ZodString;
270
271
  autoClose: z.ZodOptional<z.ZodBoolean>;
272
+ /**
273
+ * Whether OAuth authorization is required immediately
274
+ * If true, the consent page will act as a landing page before redirecting
275
+ */
276
+ oauthRequired: z.ZodOptional<z.ZodBoolean>;
277
+ /**
278
+ * The OAuth authorization URL to redirect to
279
+ * Required if oauthRequired is true
280
+ */
281
+ oauthUrl: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodLiteral<"">]>>;
271
282
  }, "strip", z.ZodTypeAny, {
272
283
  agentDid: string;
273
284
  sessionId: string;
274
285
  tool: string;
275
286
  scopes: string[];
276
287
  projectId: string;
277
- toolDescription: string;
278
288
  serverUrl: string;
289
+ toolDescription: string;
290
+ provider?: string | undefined;
279
291
  branding?: {
280
292
  primaryColor?: string | undefined;
281
293
  logoUrl?: string | undefined;
@@ -301,14 +313,89 @@ export declare const consentPageConfigSchema: z.ZodObject<{
301
313
  pattern?: string | undefined;
302
314
  }[] | undefined;
303
315
  autoClose?: boolean | undefined;
316
+ oauthRequired?: boolean | undefined;
317
+ oauthUrl?: string | undefined;
304
318
  }, {
305
319
  agentDid: string;
306
320
  sessionId: string;
307
321
  tool: string;
308
322
  scopes: string[];
309
323
  projectId: string;
324
+ serverUrl: string;
325
+ toolDescription: string;
326
+ provider?: string | undefined;
327
+ branding?: {
328
+ primaryColor?: string | undefined;
329
+ logoUrl?: string | undefined;
330
+ companyName?: string | undefined;
331
+ theme?: "light" | "dark" | "auto" | undefined;
332
+ } | undefined;
333
+ terms?: {
334
+ version?: string | undefined;
335
+ url?: string | undefined;
336
+ required?: boolean | undefined;
337
+ text?: string | undefined;
338
+ } | undefined;
339
+ customFields?: {
340
+ type: "text" | "textarea" | "checkbox" | "select";
341
+ name: string;
342
+ required: boolean;
343
+ label: string;
344
+ options?: {
345
+ value: string;
346
+ label: string;
347
+ }[] | undefined;
348
+ placeholder?: string | undefined;
349
+ pattern?: string | undefined;
350
+ }[] | undefined;
351
+ autoClose?: boolean | undefined;
352
+ oauthRequired?: boolean | undefined;
353
+ oauthUrl?: string | undefined;
354
+ }>, {
355
+ agentDid: string;
356
+ sessionId: string;
357
+ tool: string;
358
+ scopes: string[];
359
+ projectId: string;
360
+ serverUrl: string;
310
361
  toolDescription: string;
362
+ provider?: string | undefined;
363
+ branding?: {
364
+ primaryColor?: string | undefined;
365
+ logoUrl?: string | undefined;
366
+ companyName?: string | undefined;
367
+ theme?: "light" | "dark" | "auto" | undefined;
368
+ } | undefined;
369
+ terms?: {
370
+ required: boolean;
371
+ version?: string | undefined;
372
+ url?: string | undefined;
373
+ text?: string | undefined;
374
+ } | undefined;
375
+ customFields?: {
376
+ type: "text" | "textarea" | "checkbox" | "select";
377
+ name: string;
378
+ required: boolean;
379
+ label: string;
380
+ options?: {
381
+ value: string;
382
+ label: string;
383
+ }[] | undefined;
384
+ placeholder?: string | undefined;
385
+ pattern?: string | undefined;
386
+ }[] | undefined;
387
+ autoClose?: boolean | undefined;
388
+ oauthRequired?: boolean | undefined;
389
+ oauthUrl?: string | undefined;
390
+ }, {
391
+ agentDid: string;
392
+ sessionId: string;
393
+ tool: string;
394
+ scopes: string[];
395
+ projectId: string;
311
396
  serverUrl: string;
397
+ toolDescription: string;
398
+ provider?: string | undefined;
312
399
  branding?: {
313
400
  primaryColor?: string | undefined;
314
401
  logoUrl?: string | undefined;
@@ -334,6 +421,8 @@ export declare const consentPageConfigSchema: z.ZodObject<{
334
421
  pattern?: string | undefined;
335
422
  }[] | undefined;
336
423
  autoClose?: boolean | undefined;
424
+ oauthRequired?: boolean | undefined;
425
+ oauthUrl?: string | undefined;
337
426
  }>;
338
427
  export type ConsentPageConfig = z.infer<typeof consentPageConfigSchema>;
339
428
  /**
@@ -658,8 +747,9 @@ export declare function validateConsentPageConfig(config: unknown): z.SafeParseR
658
747
  tool: string;
659
748
  scopes: string[];
660
749
  projectId: string;
661
- toolDescription: string;
662
750
  serverUrl: string;
751
+ toolDescription: string;
752
+ provider?: string | undefined;
663
753
  branding?: {
664
754
  primaryColor?: string | undefined;
665
755
  logoUrl?: string | undefined;
@@ -685,14 +775,17 @@ export declare function validateConsentPageConfig(config: unknown): z.SafeParseR
685
775
  pattern?: string | undefined;
686
776
  }[] | undefined;
687
777
  autoClose?: boolean | undefined;
778
+ oauthRequired?: boolean | undefined;
779
+ oauthUrl?: string | undefined;
688
780
  }, {
689
781
  agentDid: string;
690
782
  sessionId: string;
691
783
  tool: string;
692
784
  scopes: string[];
693
785
  projectId: string;
694
- toolDescription: string;
695
786
  serverUrl: string;
787
+ toolDescription: string;
788
+ provider?: string | undefined;
696
789
  branding?: {
697
790
  primaryColor?: string | undefined;
698
791
  logoUrl?: string | undefined;
@@ -718,6 +811,8 @@ export declare function validateConsentPageConfig(config: unknown): z.SafeParseR
718
811
  pattern?: string | undefined;
719
812
  }[] | undefined;
720
813
  autoClose?: boolean | undefined;
814
+ oauthRequired?: boolean | undefined;
815
+ oauthUrl?: string | undefined;
721
816
  }>;
722
817
  /**
723
818
  * Validate a consent approval request
@@ -132,7 +132,8 @@ exports.oauthIdentitySchema = zod_1.z.object({
132
132
  /**
133
133
  * Consent Page Config Schema
134
134
  */
135
- exports.consentPageConfigSchema = zod_1.z.object({
135
+ exports.consentPageConfigSchema = zod_1.z
136
+ .object({
136
137
  tool: zod_1.z.string().min(1, "Tool name is required"),
137
138
  toolDescription: zod_1.z
138
139
  .string()
@@ -141,6 +142,7 @@ exports.consentPageConfigSchema = zod_1.z.object({
141
142
  agentDid: zod_1.z.string().min(1, "Agent DID is required"),
142
143
  sessionId: zod_1.z.string().min(1, "Session ID is required"),
143
144
  projectId: zod_1.z.string().min(1, "Project ID is required"),
145
+ provider: zod_1.z.string().optional(), // Phase 2: OAuth provider name (e.g., "github", "google")
144
146
  branding: exports.consentBrandingSchema.optional(),
145
147
  terms: exports.consentTermsSchema.optional(),
146
148
  customFields: zod_1.z
@@ -149,6 +151,42 @@ exports.consentPageConfigSchema = zod_1.z.object({
149
151
  .optional(),
150
152
  serverUrl: zod_1.z.string().url("Server URL must be a valid URL"),
151
153
  autoClose: zod_1.z.boolean().optional(),
154
+ /**
155
+ * Whether OAuth authorization is required immediately
156
+ * If true, the consent page will act as a landing page before redirecting
157
+ */
158
+ oauthRequired: zod_1.z.boolean().optional(),
159
+ /**
160
+ * The OAuth authorization URL to redirect to
161
+ * Required if oauthRequired is true
162
+ */
163
+ oauthUrl: zod_1.z
164
+ .union([
165
+ zod_1.z.string().url(),
166
+ zod_1.z.literal(""), // Allow empty string to catch it in refine with better error
167
+ ])
168
+ .optional(),
169
+ })
170
+ .superRefine((data, ctx) => {
171
+ // If oauthRequired is true, oauthUrl must be provided and non-empty
172
+ if (data.oauthRequired === true) {
173
+ if (data.oauthUrl === undefined || data.oauthUrl === "") {
174
+ ctx.addIssue({
175
+ code: zod_1.z.ZodIssueCode.custom,
176
+ message: "oauthUrl is required when oauthRequired is true",
177
+ path: ["oauthUrl"],
178
+ });
179
+ return;
180
+ }
181
+ }
182
+ // If oauthUrl is provided (not undefined), it must be a valid URL (not empty)
183
+ if (data.oauthUrl !== undefined && data.oauthUrl === "") {
184
+ ctx.addIssue({
185
+ code: zod_1.z.ZodIssueCode.custom,
186
+ message: "oauthUrl must be a valid URL",
187
+ path: ["oauthUrl"],
188
+ });
189
+ }
152
190
  });
153
191
  /**
154
192
  * Consent Approval Request Schema