@withloops.ai/contracts 0.3.0 → 0.4.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.
package/src/trust.ts CHANGED
@@ -122,6 +122,29 @@ export const SecretRef = z.object({
122
122
  });
123
123
  export type SecretRef = z.infer<typeof SecretRef>;
124
124
 
125
+ /**
126
+ * The developer's OAuth client secret for their own service is stored once per app under this reserved install id,
127
+ * in the app owner's workspace: `{ installId: APP_CLIENT_INSTALL_ID, workspaceId: app.ownerWorkspaceId, appId, name: 'oauth_client_secret' }`.
128
+ * Uninstall never deletes it; only deleting the app does. Added in 0.3.1.
129
+ */
130
+ export const APP_CLIENT_INSTALL_ID = 'ins_appclient' as const;
131
+ export const APP_CLIENT_SECRET_NAME = 'oauth_client_secret' as const;
132
+ export function appClientSecretRef(appId: string, ownerWorkspaceId: string): SecretRef {
133
+ return { installId: APP_CLIENT_INSTALL_ID, workspaceId: ownerWorkspaceId, appId, name: APP_CLIENT_SECRET_NAME };
134
+ }
135
+
136
+ /** Engine-side code exchange for an app connecting OUT (the handoff at api.thesoogroup.com/oauth/callback). Added in 0.3.1. */
137
+ export const OAuthCodeExchange = z.object({
138
+ install: SecretRef.omit({ name: true }),
139
+ ownerWorkspaceId: WorkspaceId,
140
+ tokenUrl: z.string().url(),
141
+ clientId: z.string().min(1),
142
+ code: z.string().min(1),
143
+ codeVerifier: z.string().min(43).max(128).optional(),
144
+ redirectUri: z.string().url(),
145
+ });
146
+ export type OAuthCodeExchange = z.infer<typeof OAuthCodeExchange>;
147
+
125
148
  /** What anyone outside the engine may see about a secret: never the value. */
126
149
  export const SecretInfo = z.object({
127
150
  name: SecretName,
@@ -156,4 +179,6 @@ export interface EngineVaultRpc {
156
179
  listSecrets(installId: string): Promise<SecretInfo[]>;
157
180
  /** Uninstall calls this; returns how many rows went. */
158
181
  deleteSecrets(installId: string): Promise<{ deleted: number }>;
182
+ /** Reads the app's client secret, POSTs to tokenUrl, stores access/refresh tokens for the install itself. Values never come back. Added in 0.3.1. */
183
+ exchangeOAuthCode(input: OAuthCodeExchange): Promise<{ ok: true; expiresAt: string | null } | { ok: false; error: string }>;
159
184
  }