@mitralab.io/platform-sdk 1.2.0-beta.1 → 1.2.0-beta.3

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/dist/index.d.cts CHANGED
@@ -1,5 +1,5 @@
1
- import { Transport, TransportRequestOptions, QueryParamValue, EntityTable, FunctionExecution, ListTemplateConfigsOptions, TemplateConfigPage, ProxyResult, ProxyInput, QueryResult, CredentialStatus, AgentModel as AgentModel$1, OAuthStartResult, OAuthExchangeInput, AuthenticationResult, DeviceAuthorization, PublicFunctionsModule, AgentTasksWithSessions } from '@mitralab.io/sdk-core';
2
- export { AgentQueueItem, AgentSendAndWaitOptions, AgentSendOptions, AgentSessionTransport, AgentTask, AgentTaskCreateInput, AgentTaskInput, AgentTaskListOptions, AgentTaskRuntime, AgentTaskSessionEventMap, AgentTaskSessionOptions, AgentTaskSessionStatus, AgentTurnResult, AuthenticationResult, CredentialStatus, DeviceAuthorization, EntityListOptions, EntityTable, ExistingAgentTaskSessionOptions, FunctionExecution, ListTemplateConfigsOptions, AgentMessage as NativeAgentMessage, AgentModel as NativeAgentModel, AgentTaskSession as NativeAgentTaskSession, AgentTimelineItem as NativeAgentTimelineItem, AgentToolEvent as NativeAgentToolEvent, NewAgentTaskSessionOptions, OAuthExchangeInput, OAuthStartResult, Page, PageOptions, ProxyInput, ProxyResult, PublicFunctionAsyncResult, PublicFunctionResult, PublicFunctionsModule, QueryResult, TemplateConfigPage } from '@mitralab.io/sdk-core';
1
+ import { Transport, TransportRequestOptions, QueryParamValue, EntityTable, FunctionExecution, ListTemplateConfigsOptions, TemplateConfigPage, ProxyResult, ProxyInput, QueryResult, AgentCredentialOptions, CredentialStatus, AgentModel as AgentModel$1, OAuthStartResult, OAuthExchangeInput, AuthenticationResult, DeviceAuthorization, PublicFunctionsModule, AgentTasksWithSessions } from '@mitralab.io/sdk-core';
2
+ export { AgentCredentialOptions, AgentCredentialScope, AgentQueueItem, AgentSendAndWaitOptions, AgentSendOptions, AgentSessionTransport, AgentTask, AgentTaskCreateInput, AgentTaskInput, AgentTaskListOptions, AgentTaskRuntime, AgentTaskSessionEventMap, AgentTaskSessionOptions, AgentTaskSessionStatus, AgentTurnResult, AuthenticationResult, CredentialStatus, DeviceAuthorization, EntityListOptions, EntityTable, ExistingAgentTaskSessionOptions, FunctionExecution, ListTemplateConfigsOptions, AgentMessage as NativeAgentMessage, AgentModel as NativeAgentModel, AgentTaskSession as NativeAgentTaskSession, AgentTimelineItem as NativeAgentTimelineItem, AgentToolEvent as NativeAgentToolEvent, NewAgentTaskSessionOptions, OAuthExchangeInput, OAuthStartResult, Page, PageOptions, ProxyInput, ProxyResult, PublicFunctionAsyncResult, PublicFunctionResult, PublicFunctionsModule, QueryResult, TemplateConfigPage } from '@mitralab.io/sdk-core';
3
3
  import * as LegacyTypes from 'mitra-interactions-sdk';
4
4
  import { exchangeSsoCodeMitra as exchangeSsoCodeMitra$1, loginMitra as loginMitra$1, loginWithGoogleMitra as loginWithGoogleMitra$1, loginWithMicrosoftMitra as loginWithMicrosoftMitra$1 } from 'mitra-interactions-sdk';
5
5
  export { callIntegrationMitra, configureSdkMitra, createMitraInstance, createRecordMitra, createRecordsBatchMitra, deleteRecordMitra, executePublicServerFunctionAsyncMitra, executePublicServerFunctionMitra, executeServerFunctionAsyncMitra, executeServerFunctionMitra, getAgentTaskMitra, getConfig, getPublicServerFunctionExecutionMitra, getRecordMitra, listIntegrationsMitra, listRecordsMitra, manageAgentChatMitra, manageAgentCredentialMitra, patchRecordMitra, refreshTokenSilently, resolveProjectId, stopServerFunctionExecutionMitra, updateRecordMitra } from 'mitra-interactions-sdk';
@@ -167,13 +167,25 @@ declare class MitraApiError extends Error {
167
167
  readonly code?: string | undefined;
168
168
  /** Additional error details from the server response */
169
169
  readonly details?: unknown | undefined;
170
+ /**
171
+ * Seconds the server asked the caller to wait before trying again, read
172
+ * from `Retry-After`. `null` when the response carries no such delay,
173
+ * including when CORS keeps the header from reaching the browser.
174
+ */
175
+ readonly retryAfterSeconds: number | null;
170
176
  constructor(message: string,
171
177
  /** HTTP status code (e.g., 400, 401, 404, 500) */
172
178
  status: number,
173
179
  /** Application-specific error code (e.g., 'ENTITY_NOT_FOUND', 'VALIDATION_ERROR') */
174
180
  code?: string | undefined,
175
181
  /** Additional error details from the server response */
176
- details?: unknown | undefined);
182
+ details?: unknown | undefined,
183
+ /**
184
+ * Seconds the server asked the caller to wait before trying again, read
185
+ * from `Retry-After`. `null` when the response carries no such delay,
186
+ * including when CORS keeps the header from reaching the browser.
187
+ */
188
+ retryAfterSeconds?: number | null);
177
189
  }
178
190
 
179
191
  /** Authenticated user in the Mitra Platform. */
@@ -217,6 +229,29 @@ type MicrosoftSignInOptions = AuthPageSignInOptions;
217
229
  * which collects the address and the one-time code.
218
230
  */
219
231
  type EmailSignInOptions = AuthPageSignInOptions;
232
+ /** Language of the message IAM sends. The platform writes it in these two. */
233
+ type EmailCodeLanguage = 'pt-BR' | 'en';
234
+ /** The address to send a one-time code to, and the language to write it in. */
235
+ interface EmailCodeRequest {
236
+ email: string;
237
+ /** Defaults to the browser language, and to `pt-BR` when that is neither. */
238
+ language?: EmailCodeLanguage;
239
+ }
240
+ /**
241
+ * What IAM accepted. The answer is deliberately neutral about whether the
242
+ * address exists, so it carries no verdict about the person.
243
+ */
244
+ interface EmailCodeRequestResult {
245
+ /** Names this request when the code is verified. Not a credential. */
246
+ receipt: string;
247
+ /** How long to wait before offering to send another message. */
248
+ resendAfterSeconds: number;
249
+ }
250
+ /** The code the person read in the message, against the request that sent it. */
251
+ interface EmailCodeVerification {
252
+ receipt: string;
253
+ code: string;
254
+ }
220
255
  /** Callback for auth state changes. Receives the user on login, null on logout. */
221
256
  type AuthStateChangeCallback = (user: User | null) => void;
222
257
 
@@ -257,6 +292,8 @@ declare class AuthModule {
257
292
  private readonly googleAuth;
258
293
  private readonly microsoftAuth;
259
294
  private readonly emailAuth;
295
+ private readonly emailCode;
296
+ private brand;
260
297
  constructor(appId: string, iamBaseUrl: string, options?: AuthModuleOptions);
261
298
  /** The currently authenticated user, or null. */
262
299
  get currentUser(): User | null;
@@ -382,17 +419,82 @@ declare class AuthModule {
382
419
  */
383
420
  signInWithEmail(options?: EmailSignInOptions): Promise<User>;
384
421
  /**
385
- * Completes an email sign-in from `#codeMitra` and `#stateMitra`, during
386
- * application startup like {@link completeGoogleSignInRedirect}.
422
+ * Publishes the brand `init()` read from the app info, which IAM needs to
423
+ * choose the message it sends for {@link requestEmailCode}.
424
+ *
425
+ * @internal
426
+ */
427
+ setBrand(brand: string): void;
428
+ /**
429
+ * Asks IAM to email a six-digit code, without any platform screen: the
430
+ * application renders its own address and code fields, and the message is
431
+ * branded as the app. Answer it with {@link verifyEmailCode}.
432
+ *
433
+ * The same message also carries a link back to this application's own origin.
434
+ * Sign-in continues there through {@link completeEmailSignInRedirect}, so the
435
+ * request is written to `localStorage` under `mitra_email_redirect_{appId}` -
436
+ * the one-time state and this origin, never a token - for 10 minutes. Only the
437
+ * browser that asked can finish through the link.
438
+ *
439
+ * Resending is calling this again: the new request replaces the pending one,
440
+ * and `resendAfterSeconds` says how long the application should wait before
441
+ * offering that.
442
+ *
443
+ * @param request - Address to send to, and the language to write in.
444
+ * @returns The receipt that names this request, and the resend delay.
445
+ * @throws {MitraApiError} `INVALID_CONFIGURATION` before `init()` resolved the
446
+ * app info, `RATE_LIMITED` (with `retryAfterSeconds`) when IAM asks the person
447
+ * to wait, and the app access codes when this app refuses the address.
387
448
  *
388
- * It covers both ways the flow comes back, and they are the same check: a
389
- * redirect in the tab that started it, and the tab the link in the message
390
- * opened. Both carry the one-time state this SDK generated, which the second
391
- * tab matches against the pending request kept in `localStorage`. A request
392
- * older than 10 minutes is discarded instead of completed.
449
+ * @example
450
+ * ```typescript
451
+ * const { receipt, resendAfterSeconds } = await mitra.auth.requestEmailCode({
452
+ * email: 'person@example.com',
453
+ * });
454
+ * ```
455
+ */
456
+ requestEmailCode(request: EmailCodeRequest): Promise<EmailCodeRequestResult>;
457
+ /**
458
+ * Turns the code from the message into a session, hydrating and persisting it
459
+ * exactly like SSO does.
460
+ *
461
+ * @param verification - The receipt from {@link requestEmailCode} and the code
462
+ * the person typed.
463
+ * @returns The authenticated and hydrated user.
464
+ * @throws {MitraApiError} `INVALID_CODE` when the code does not match,
465
+ * `MAGIC_LINK_EXPIRED` or `MAGIC_LINK_USED` when the request is over.
393
466
  *
394
- * @returns The authenticated user, or `null` when the URL carries no result or
395
- * carries one that belongs to another sign-in method's flow.
467
+ * @example
468
+ * ```typescript
469
+ * const user = await mitra.auth.verifyEmailCode({ receipt, code: '123456' });
470
+ * ```
471
+ */
472
+ verifyEmailCode(verification: EmailCodeVerification): Promise<User>;
473
+ /**
474
+ * Completes an email sign-in during application startup, like
475
+ * {@link completeGoogleSignInRedirect}.
476
+ *
477
+ * It covers every way the flow comes back. The link in the message lands on
478
+ * this application's own origin as `#emailToken=`, and that is the headless
479
+ * flow: the link is inspected before it is spent, and it is only spent when
480
+ * IAM reports the same origin the page is on and the one-time state of the
481
+ * request pending in this browser. A browser without that request - another
482
+ * device, or a scanner opening links on the way to a mailbox - consumes
483
+ * nothing and leaves the link valid for the person who asked for it.
484
+ *
485
+ * The platform auth page instead comes back as `#codeMitra` and `#stateMitra`,
486
+ * from the redirect in the tab that started it or from the tab the older link
487
+ * opened, and is completed by the same state check.
488
+ *
489
+ * From the link, only `emailToken` leaves the URL, so a fragment the
490
+ * application routes on is left as it was. Coming back from the platform auth
491
+ * page, the fragment is removed whole.
492
+ *
493
+ * @returns The authenticated user, or `null` when the URL carries no result,
494
+ * carries one that belongs to another sign-in method's flow, or carries a link
495
+ * this browser cannot claim.
496
+ * @throws {MitraApiError} `MAGIC_LINK_EXPIRED`, `MAGIC_LINK_USED`, or
497
+ * `MAGIC_LINK_INVALID` when the link belongs here but cannot be used.
396
498
  */
397
499
  completeEmailSignInRedirect(): Promise<User | null>;
398
500
  /** @deprecated Email/password registration is not implemented by IAM. Use signInWithEmail() or SSO. */
@@ -580,6 +682,12 @@ declare class AuthModule {
580
682
  private invalidatePendingRefreshes;
581
683
  private hasValidAppIdentity;
582
684
  private belongsToConfiguredApp;
685
+ /**
686
+ * The brand IAM needs to brand the message. It arrives with the app info, so
687
+ * asking before `init()` is a configuration mistake rather than something to
688
+ * guess a default for: the wrong brand sends the wrong message.
689
+ */
690
+ private requireBrand;
583
691
  private notifySessionListeners;
584
692
  private notifyListeners;
585
693
  private saveToStorage;
@@ -652,14 +760,14 @@ type AgentCredentialProvider = 'ANTHROPIC' | 'OPENAI';
652
760
  type AgentOAuthProvider = 'ANTHROPIC';
653
761
  type AgentDeviceProvider = 'OPENAI';
654
762
  interface AgentCredentialsModule {
655
- list(): Promise<CredentialStatus[]>;
656
- listModels(agentId?: string): Promise<AgentModel$1[]>;
657
- saveApiKey(provider: AgentCredentialProvider, apiKey: string): Promise<void>;
658
- remove(provider: AgentCredentialProvider): Promise<void>;
659
- startOAuth(provider: AgentOAuthProvider): Promise<OAuthStartResult>;
660
- exchangeOAuth(provider: AgentOAuthProvider, input: OAuthExchangeInput): Promise<AuthenticationResult>;
661
- startDeviceAuthorization(provider: AgentDeviceProvider): Promise<DeviceAuthorization>;
662
- pollDeviceAuthorization(provider: AgentDeviceProvider, deviceAuthId: string): Promise<AuthenticationResult>;
763
+ list(options?: AgentCredentialOptions): Promise<CredentialStatus[]>;
764
+ listModels(agentId?: string, options?: AgentCredentialOptions): Promise<AgentModel$1[]>;
765
+ saveApiKey(provider: AgentCredentialProvider, apiKey: string, options?: AgentCredentialOptions): Promise<void>;
766
+ remove(provider: AgentCredentialProvider, options?: AgentCredentialOptions): Promise<void>;
767
+ startOAuth(provider: AgentOAuthProvider, options?: AgentCredentialOptions): Promise<OAuthStartResult>;
768
+ exchangeOAuth(provider: AgentOAuthProvider, input: OAuthExchangeInput, options?: AgentCredentialOptions): Promise<AuthenticationResult>;
769
+ startDeviceAuthorization(provider: AgentDeviceProvider, options?: AgentCredentialOptions): Promise<DeviceAuthorization>;
770
+ pollDeviceAuthorization(provider: AgentDeviceProvider, deviceAuthId: string, options?: AgentCredentialOptions): Promise<AuthenticationResult>;
663
771
  }
664
772
 
665
773
  /**
@@ -741,8 +849,8 @@ interface MitraClient {
741
849
  /**
742
850
  * Initializes the client by resolving app config from the server.
743
851
  *
744
- * Fetches the compatibility dataSourceId, allowSignup, and emailLoginEnabled
745
- * from the public app info endpoint.
852
+ * Fetches the compatibility dataSourceId, allowSignup, emailLoginEnabled, and
853
+ * the brand `requestEmailCode()` sends with, from the public app info endpoint.
746
854
  *
747
855
  * Safe to call multiple times. Subsequent calls are no-ops.
748
856
  *
@@ -1057,4 +1165,4 @@ type StopServerFunctionExecutionResponse = LegacyTypes.StopServerFunctionExecuti
1057
1165
  /** @deprecated Legacy compatibility type. */
1058
1166
  type UpdateRecordOptions = LegacyTypes.UpdateRecordOptions;
1059
1167
 
1060
- export { type AgentChat, type AgentCredentialProvider, type AgentCredentialStatus, type AgentCredentialsModule, type AgentDeltaEvent, type AgentDeviceProvider, type AgentErrorEvent, type AgentMessage, type AgentModel, type AgentOAuthProvider, type AgentProvider, type AgentQueueChangeEvent, type AgentRawEvent, type AgentStatusChangeEvent, type AgentTaskCreatedEvent, type AgentTaskEventMap, type AgentTaskEventName, type AgentTaskSession, type AgentTaskStatus, type AgentTaskTransport, type AgentTimelineItem, type AgentToolEvent, type AgentTurnEndEvent, type AgentType, type AuthAgentCredentialResult, type AuthPageSignInOptions, type CallIntegrationOptions, type CallIntegrationResponse, type ChatManageAction, type ConnectAgentCredentialResult, type CreateRecordOptions, type CreateRecordsBatchOptions, type CredentialAction, type DeleteAgentChatResult, type DeleteRecordOptions, type DeviceAuthAgentCredentialResult, type EmailSignInOptions, type ExecutePublicServerFunctionAsyncResponse, type ExecutePublicServerFunctionOptions, type ExecutePublicServerFunctionResponse, type ExecuteServerFunctionAsyncOptions, type ExecuteServerFunctionAsyncResponse, type ExecuteServerFunctionOptions, type ExecuteServerFunctionResponse, type GetAgentTaskCreateOptions, type GetAgentTaskOpenOptions, type GetAgentTaskOptions, type GetPublicServerFunctionExecutionOptions, type GetPublicServerFunctionExecutionResponse, type GetRecordOptions, type GoogleSignInOptions, type IntegrationResponse, type ListAgentModelsResult, type ListAgentProvidersResult, type ListIntegrationsOptions, type ListRecordsOptions, type ListRecordsResponse, type LoginOptions, type LoginResponse, type ManageAgentChatDeleteOptions, type ManageAgentChatListOptions, type ManageAgentChatOptions, type ManageAgentChatRenameOptions, type ManageAgentCredentialOptions, type MicrosoftSignInOptions, MitraApiError, type MitraClient, type MitraClientConfig, type MitraConfig, type MitraInstance, type PatchRecordOptions, type QueuedItem, type RenameAgentChatResult, type SendOptions, type SignInCredentials, type SignUpData, type StopServerFunctionExecutionOptions, type StopServerFunctionExecutionResponse, type UpdateRecordOptions, type User, createClient, exchangeSsoCodeMitra, loginMitra, loginWithGoogleMitra, loginWithMicrosoftMitra };
1168
+ export { type AgentChat, type AgentCredentialProvider, type AgentCredentialStatus, type AgentCredentialsModule, type AgentDeltaEvent, type AgentDeviceProvider, type AgentErrorEvent, type AgentMessage, type AgentModel, type AgentOAuthProvider, type AgentProvider, type AgentQueueChangeEvent, type AgentRawEvent, type AgentStatusChangeEvent, type AgentTaskCreatedEvent, type AgentTaskEventMap, type AgentTaskEventName, type AgentTaskSession, type AgentTaskStatus, type AgentTaskTransport, type AgentTimelineItem, type AgentToolEvent, type AgentTurnEndEvent, type AgentType, type AuthAgentCredentialResult, type AuthPageSignInOptions, type CallIntegrationOptions, type CallIntegrationResponse, type ChatManageAction, type ConnectAgentCredentialResult, type CreateRecordOptions, type CreateRecordsBatchOptions, type CredentialAction, type DeleteAgentChatResult, type DeleteRecordOptions, type DeviceAuthAgentCredentialResult, type EmailCodeLanguage, type EmailCodeRequest, type EmailCodeRequestResult, type EmailCodeVerification, type EmailSignInOptions, type ExecutePublicServerFunctionAsyncResponse, type ExecutePublicServerFunctionOptions, type ExecutePublicServerFunctionResponse, type ExecuteServerFunctionAsyncOptions, type ExecuteServerFunctionAsyncResponse, type ExecuteServerFunctionOptions, type ExecuteServerFunctionResponse, type GetAgentTaskCreateOptions, type GetAgentTaskOpenOptions, type GetAgentTaskOptions, type GetPublicServerFunctionExecutionOptions, type GetPublicServerFunctionExecutionResponse, type GetRecordOptions, type GoogleSignInOptions, type IntegrationResponse, type ListAgentModelsResult, type ListAgentProvidersResult, type ListIntegrationsOptions, type ListRecordsOptions, type ListRecordsResponse, type LoginOptions, type LoginResponse, type ManageAgentChatDeleteOptions, type ManageAgentChatListOptions, type ManageAgentChatOptions, type ManageAgentChatRenameOptions, type ManageAgentCredentialOptions, type MicrosoftSignInOptions, MitraApiError, type MitraClient, type MitraClientConfig, type MitraConfig, type MitraInstance, type PatchRecordOptions, type QueuedItem, type RenameAgentChatResult, type SendOptions, type SignInCredentials, type SignUpData, type StopServerFunctionExecutionOptions, type StopServerFunctionExecutionResponse, type UpdateRecordOptions, type User, createClient, exchangeSsoCodeMitra, loginMitra, loginWithGoogleMitra, loginWithMicrosoftMitra };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { Transport, TransportRequestOptions, QueryParamValue, EntityTable, FunctionExecution, ListTemplateConfigsOptions, TemplateConfigPage, ProxyResult, ProxyInput, QueryResult, CredentialStatus, AgentModel as AgentModel$1, OAuthStartResult, OAuthExchangeInput, AuthenticationResult, DeviceAuthorization, PublicFunctionsModule, AgentTasksWithSessions } from '@mitralab.io/sdk-core';
2
- export { AgentQueueItem, AgentSendAndWaitOptions, AgentSendOptions, AgentSessionTransport, AgentTask, AgentTaskCreateInput, AgentTaskInput, AgentTaskListOptions, AgentTaskRuntime, AgentTaskSessionEventMap, AgentTaskSessionOptions, AgentTaskSessionStatus, AgentTurnResult, AuthenticationResult, CredentialStatus, DeviceAuthorization, EntityListOptions, EntityTable, ExistingAgentTaskSessionOptions, FunctionExecution, ListTemplateConfigsOptions, AgentMessage as NativeAgentMessage, AgentModel as NativeAgentModel, AgentTaskSession as NativeAgentTaskSession, AgentTimelineItem as NativeAgentTimelineItem, AgentToolEvent as NativeAgentToolEvent, NewAgentTaskSessionOptions, OAuthExchangeInput, OAuthStartResult, Page, PageOptions, ProxyInput, ProxyResult, PublicFunctionAsyncResult, PublicFunctionResult, PublicFunctionsModule, QueryResult, TemplateConfigPage } from '@mitralab.io/sdk-core';
1
+ import { Transport, TransportRequestOptions, QueryParamValue, EntityTable, FunctionExecution, ListTemplateConfigsOptions, TemplateConfigPage, ProxyResult, ProxyInput, QueryResult, AgentCredentialOptions, CredentialStatus, AgentModel as AgentModel$1, OAuthStartResult, OAuthExchangeInput, AuthenticationResult, DeviceAuthorization, PublicFunctionsModule, AgentTasksWithSessions } from '@mitralab.io/sdk-core';
2
+ export { AgentCredentialOptions, AgentCredentialScope, AgentQueueItem, AgentSendAndWaitOptions, AgentSendOptions, AgentSessionTransport, AgentTask, AgentTaskCreateInput, AgentTaskInput, AgentTaskListOptions, AgentTaskRuntime, AgentTaskSessionEventMap, AgentTaskSessionOptions, AgentTaskSessionStatus, AgentTurnResult, AuthenticationResult, CredentialStatus, DeviceAuthorization, EntityListOptions, EntityTable, ExistingAgentTaskSessionOptions, FunctionExecution, ListTemplateConfigsOptions, AgentMessage as NativeAgentMessage, AgentModel as NativeAgentModel, AgentTaskSession as NativeAgentTaskSession, AgentTimelineItem as NativeAgentTimelineItem, AgentToolEvent as NativeAgentToolEvent, NewAgentTaskSessionOptions, OAuthExchangeInput, OAuthStartResult, Page, PageOptions, ProxyInput, ProxyResult, PublicFunctionAsyncResult, PublicFunctionResult, PublicFunctionsModule, QueryResult, TemplateConfigPage } from '@mitralab.io/sdk-core';
3
3
  import * as LegacyTypes from 'mitra-interactions-sdk';
4
4
  import { exchangeSsoCodeMitra as exchangeSsoCodeMitra$1, loginMitra as loginMitra$1, loginWithGoogleMitra as loginWithGoogleMitra$1, loginWithMicrosoftMitra as loginWithMicrosoftMitra$1 } from 'mitra-interactions-sdk';
5
5
  export { callIntegrationMitra, configureSdkMitra, createMitraInstance, createRecordMitra, createRecordsBatchMitra, deleteRecordMitra, executePublicServerFunctionAsyncMitra, executePublicServerFunctionMitra, executeServerFunctionAsyncMitra, executeServerFunctionMitra, getAgentTaskMitra, getConfig, getPublicServerFunctionExecutionMitra, getRecordMitra, listIntegrationsMitra, listRecordsMitra, manageAgentChatMitra, manageAgentCredentialMitra, patchRecordMitra, refreshTokenSilently, resolveProjectId, stopServerFunctionExecutionMitra, updateRecordMitra } from 'mitra-interactions-sdk';
@@ -167,13 +167,25 @@ declare class MitraApiError extends Error {
167
167
  readonly code?: string | undefined;
168
168
  /** Additional error details from the server response */
169
169
  readonly details?: unknown | undefined;
170
+ /**
171
+ * Seconds the server asked the caller to wait before trying again, read
172
+ * from `Retry-After`. `null` when the response carries no such delay,
173
+ * including when CORS keeps the header from reaching the browser.
174
+ */
175
+ readonly retryAfterSeconds: number | null;
170
176
  constructor(message: string,
171
177
  /** HTTP status code (e.g., 400, 401, 404, 500) */
172
178
  status: number,
173
179
  /** Application-specific error code (e.g., 'ENTITY_NOT_FOUND', 'VALIDATION_ERROR') */
174
180
  code?: string | undefined,
175
181
  /** Additional error details from the server response */
176
- details?: unknown | undefined);
182
+ details?: unknown | undefined,
183
+ /**
184
+ * Seconds the server asked the caller to wait before trying again, read
185
+ * from `Retry-After`. `null` when the response carries no such delay,
186
+ * including when CORS keeps the header from reaching the browser.
187
+ */
188
+ retryAfterSeconds?: number | null);
177
189
  }
178
190
 
179
191
  /** Authenticated user in the Mitra Platform. */
@@ -217,6 +229,29 @@ type MicrosoftSignInOptions = AuthPageSignInOptions;
217
229
  * which collects the address and the one-time code.
218
230
  */
219
231
  type EmailSignInOptions = AuthPageSignInOptions;
232
+ /** Language of the message IAM sends. The platform writes it in these two. */
233
+ type EmailCodeLanguage = 'pt-BR' | 'en';
234
+ /** The address to send a one-time code to, and the language to write it in. */
235
+ interface EmailCodeRequest {
236
+ email: string;
237
+ /** Defaults to the browser language, and to `pt-BR` when that is neither. */
238
+ language?: EmailCodeLanguage;
239
+ }
240
+ /**
241
+ * What IAM accepted. The answer is deliberately neutral about whether the
242
+ * address exists, so it carries no verdict about the person.
243
+ */
244
+ interface EmailCodeRequestResult {
245
+ /** Names this request when the code is verified. Not a credential. */
246
+ receipt: string;
247
+ /** How long to wait before offering to send another message. */
248
+ resendAfterSeconds: number;
249
+ }
250
+ /** The code the person read in the message, against the request that sent it. */
251
+ interface EmailCodeVerification {
252
+ receipt: string;
253
+ code: string;
254
+ }
220
255
  /** Callback for auth state changes. Receives the user on login, null on logout. */
221
256
  type AuthStateChangeCallback = (user: User | null) => void;
222
257
 
@@ -257,6 +292,8 @@ declare class AuthModule {
257
292
  private readonly googleAuth;
258
293
  private readonly microsoftAuth;
259
294
  private readonly emailAuth;
295
+ private readonly emailCode;
296
+ private brand;
260
297
  constructor(appId: string, iamBaseUrl: string, options?: AuthModuleOptions);
261
298
  /** The currently authenticated user, or null. */
262
299
  get currentUser(): User | null;
@@ -382,17 +419,82 @@ declare class AuthModule {
382
419
  */
383
420
  signInWithEmail(options?: EmailSignInOptions): Promise<User>;
384
421
  /**
385
- * Completes an email sign-in from `#codeMitra` and `#stateMitra`, during
386
- * application startup like {@link completeGoogleSignInRedirect}.
422
+ * Publishes the brand `init()` read from the app info, which IAM needs to
423
+ * choose the message it sends for {@link requestEmailCode}.
424
+ *
425
+ * @internal
426
+ */
427
+ setBrand(brand: string): void;
428
+ /**
429
+ * Asks IAM to email a six-digit code, without any platform screen: the
430
+ * application renders its own address and code fields, and the message is
431
+ * branded as the app. Answer it with {@link verifyEmailCode}.
432
+ *
433
+ * The same message also carries a link back to this application's own origin.
434
+ * Sign-in continues there through {@link completeEmailSignInRedirect}, so the
435
+ * request is written to `localStorage` under `mitra_email_redirect_{appId}` -
436
+ * the one-time state and this origin, never a token - for 10 minutes. Only the
437
+ * browser that asked can finish through the link.
438
+ *
439
+ * Resending is calling this again: the new request replaces the pending one,
440
+ * and `resendAfterSeconds` says how long the application should wait before
441
+ * offering that.
442
+ *
443
+ * @param request - Address to send to, and the language to write in.
444
+ * @returns The receipt that names this request, and the resend delay.
445
+ * @throws {MitraApiError} `INVALID_CONFIGURATION` before `init()` resolved the
446
+ * app info, `RATE_LIMITED` (with `retryAfterSeconds`) when IAM asks the person
447
+ * to wait, and the app access codes when this app refuses the address.
387
448
  *
388
- * It covers both ways the flow comes back, and they are the same check: a
389
- * redirect in the tab that started it, and the tab the link in the message
390
- * opened. Both carry the one-time state this SDK generated, which the second
391
- * tab matches against the pending request kept in `localStorage`. A request
392
- * older than 10 minutes is discarded instead of completed.
449
+ * @example
450
+ * ```typescript
451
+ * const { receipt, resendAfterSeconds } = await mitra.auth.requestEmailCode({
452
+ * email: 'person@example.com',
453
+ * });
454
+ * ```
455
+ */
456
+ requestEmailCode(request: EmailCodeRequest): Promise<EmailCodeRequestResult>;
457
+ /**
458
+ * Turns the code from the message into a session, hydrating and persisting it
459
+ * exactly like SSO does.
460
+ *
461
+ * @param verification - The receipt from {@link requestEmailCode} and the code
462
+ * the person typed.
463
+ * @returns The authenticated and hydrated user.
464
+ * @throws {MitraApiError} `INVALID_CODE` when the code does not match,
465
+ * `MAGIC_LINK_EXPIRED` or `MAGIC_LINK_USED` when the request is over.
393
466
  *
394
- * @returns The authenticated user, or `null` when the URL carries no result or
395
- * carries one that belongs to another sign-in method's flow.
467
+ * @example
468
+ * ```typescript
469
+ * const user = await mitra.auth.verifyEmailCode({ receipt, code: '123456' });
470
+ * ```
471
+ */
472
+ verifyEmailCode(verification: EmailCodeVerification): Promise<User>;
473
+ /**
474
+ * Completes an email sign-in during application startup, like
475
+ * {@link completeGoogleSignInRedirect}.
476
+ *
477
+ * It covers every way the flow comes back. The link in the message lands on
478
+ * this application's own origin as `#emailToken=`, and that is the headless
479
+ * flow: the link is inspected before it is spent, and it is only spent when
480
+ * IAM reports the same origin the page is on and the one-time state of the
481
+ * request pending in this browser. A browser without that request - another
482
+ * device, or a scanner opening links on the way to a mailbox - consumes
483
+ * nothing and leaves the link valid for the person who asked for it.
484
+ *
485
+ * The platform auth page instead comes back as `#codeMitra` and `#stateMitra`,
486
+ * from the redirect in the tab that started it or from the tab the older link
487
+ * opened, and is completed by the same state check.
488
+ *
489
+ * From the link, only `emailToken` leaves the URL, so a fragment the
490
+ * application routes on is left as it was. Coming back from the platform auth
491
+ * page, the fragment is removed whole.
492
+ *
493
+ * @returns The authenticated user, or `null` when the URL carries no result,
494
+ * carries one that belongs to another sign-in method's flow, or carries a link
495
+ * this browser cannot claim.
496
+ * @throws {MitraApiError} `MAGIC_LINK_EXPIRED`, `MAGIC_LINK_USED`, or
497
+ * `MAGIC_LINK_INVALID` when the link belongs here but cannot be used.
396
498
  */
397
499
  completeEmailSignInRedirect(): Promise<User | null>;
398
500
  /** @deprecated Email/password registration is not implemented by IAM. Use signInWithEmail() or SSO. */
@@ -580,6 +682,12 @@ declare class AuthModule {
580
682
  private invalidatePendingRefreshes;
581
683
  private hasValidAppIdentity;
582
684
  private belongsToConfiguredApp;
685
+ /**
686
+ * The brand IAM needs to brand the message. It arrives with the app info, so
687
+ * asking before `init()` is a configuration mistake rather than something to
688
+ * guess a default for: the wrong brand sends the wrong message.
689
+ */
690
+ private requireBrand;
583
691
  private notifySessionListeners;
584
692
  private notifyListeners;
585
693
  private saveToStorage;
@@ -652,14 +760,14 @@ type AgentCredentialProvider = 'ANTHROPIC' | 'OPENAI';
652
760
  type AgentOAuthProvider = 'ANTHROPIC';
653
761
  type AgentDeviceProvider = 'OPENAI';
654
762
  interface AgentCredentialsModule {
655
- list(): Promise<CredentialStatus[]>;
656
- listModels(agentId?: string): Promise<AgentModel$1[]>;
657
- saveApiKey(provider: AgentCredentialProvider, apiKey: string): Promise<void>;
658
- remove(provider: AgentCredentialProvider): Promise<void>;
659
- startOAuth(provider: AgentOAuthProvider): Promise<OAuthStartResult>;
660
- exchangeOAuth(provider: AgentOAuthProvider, input: OAuthExchangeInput): Promise<AuthenticationResult>;
661
- startDeviceAuthorization(provider: AgentDeviceProvider): Promise<DeviceAuthorization>;
662
- pollDeviceAuthorization(provider: AgentDeviceProvider, deviceAuthId: string): Promise<AuthenticationResult>;
763
+ list(options?: AgentCredentialOptions): Promise<CredentialStatus[]>;
764
+ listModels(agentId?: string, options?: AgentCredentialOptions): Promise<AgentModel$1[]>;
765
+ saveApiKey(provider: AgentCredentialProvider, apiKey: string, options?: AgentCredentialOptions): Promise<void>;
766
+ remove(provider: AgentCredentialProvider, options?: AgentCredentialOptions): Promise<void>;
767
+ startOAuth(provider: AgentOAuthProvider, options?: AgentCredentialOptions): Promise<OAuthStartResult>;
768
+ exchangeOAuth(provider: AgentOAuthProvider, input: OAuthExchangeInput, options?: AgentCredentialOptions): Promise<AuthenticationResult>;
769
+ startDeviceAuthorization(provider: AgentDeviceProvider, options?: AgentCredentialOptions): Promise<DeviceAuthorization>;
770
+ pollDeviceAuthorization(provider: AgentDeviceProvider, deviceAuthId: string, options?: AgentCredentialOptions): Promise<AuthenticationResult>;
663
771
  }
664
772
 
665
773
  /**
@@ -741,8 +849,8 @@ interface MitraClient {
741
849
  /**
742
850
  * Initializes the client by resolving app config from the server.
743
851
  *
744
- * Fetches the compatibility dataSourceId, allowSignup, and emailLoginEnabled
745
- * from the public app info endpoint.
852
+ * Fetches the compatibility dataSourceId, allowSignup, emailLoginEnabled, and
853
+ * the brand `requestEmailCode()` sends with, from the public app info endpoint.
746
854
  *
747
855
  * Safe to call multiple times. Subsequent calls are no-ops.
748
856
  *
@@ -1057,4 +1165,4 @@ type StopServerFunctionExecutionResponse = LegacyTypes.StopServerFunctionExecuti
1057
1165
  /** @deprecated Legacy compatibility type. */
1058
1166
  type UpdateRecordOptions = LegacyTypes.UpdateRecordOptions;
1059
1167
 
1060
- export { type AgentChat, type AgentCredentialProvider, type AgentCredentialStatus, type AgentCredentialsModule, type AgentDeltaEvent, type AgentDeviceProvider, type AgentErrorEvent, type AgentMessage, type AgentModel, type AgentOAuthProvider, type AgentProvider, type AgentQueueChangeEvent, type AgentRawEvent, type AgentStatusChangeEvent, type AgentTaskCreatedEvent, type AgentTaskEventMap, type AgentTaskEventName, type AgentTaskSession, type AgentTaskStatus, type AgentTaskTransport, type AgentTimelineItem, type AgentToolEvent, type AgentTurnEndEvent, type AgentType, type AuthAgentCredentialResult, type AuthPageSignInOptions, type CallIntegrationOptions, type CallIntegrationResponse, type ChatManageAction, type ConnectAgentCredentialResult, type CreateRecordOptions, type CreateRecordsBatchOptions, type CredentialAction, type DeleteAgentChatResult, type DeleteRecordOptions, type DeviceAuthAgentCredentialResult, type EmailSignInOptions, type ExecutePublicServerFunctionAsyncResponse, type ExecutePublicServerFunctionOptions, type ExecutePublicServerFunctionResponse, type ExecuteServerFunctionAsyncOptions, type ExecuteServerFunctionAsyncResponse, type ExecuteServerFunctionOptions, type ExecuteServerFunctionResponse, type GetAgentTaskCreateOptions, type GetAgentTaskOpenOptions, type GetAgentTaskOptions, type GetPublicServerFunctionExecutionOptions, type GetPublicServerFunctionExecutionResponse, type GetRecordOptions, type GoogleSignInOptions, type IntegrationResponse, type ListAgentModelsResult, type ListAgentProvidersResult, type ListIntegrationsOptions, type ListRecordsOptions, type ListRecordsResponse, type LoginOptions, type LoginResponse, type ManageAgentChatDeleteOptions, type ManageAgentChatListOptions, type ManageAgentChatOptions, type ManageAgentChatRenameOptions, type ManageAgentCredentialOptions, type MicrosoftSignInOptions, MitraApiError, type MitraClient, type MitraClientConfig, type MitraConfig, type MitraInstance, type PatchRecordOptions, type QueuedItem, type RenameAgentChatResult, type SendOptions, type SignInCredentials, type SignUpData, type StopServerFunctionExecutionOptions, type StopServerFunctionExecutionResponse, type UpdateRecordOptions, type User, createClient, exchangeSsoCodeMitra, loginMitra, loginWithGoogleMitra, loginWithMicrosoftMitra };
1168
+ export { type AgentChat, type AgentCredentialProvider, type AgentCredentialStatus, type AgentCredentialsModule, type AgentDeltaEvent, type AgentDeviceProvider, type AgentErrorEvent, type AgentMessage, type AgentModel, type AgentOAuthProvider, type AgentProvider, type AgentQueueChangeEvent, type AgentRawEvent, type AgentStatusChangeEvent, type AgentTaskCreatedEvent, type AgentTaskEventMap, type AgentTaskEventName, type AgentTaskSession, type AgentTaskStatus, type AgentTaskTransport, type AgentTimelineItem, type AgentToolEvent, type AgentTurnEndEvent, type AgentType, type AuthAgentCredentialResult, type AuthPageSignInOptions, type CallIntegrationOptions, type CallIntegrationResponse, type ChatManageAction, type ConnectAgentCredentialResult, type CreateRecordOptions, type CreateRecordsBatchOptions, type CredentialAction, type DeleteAgentChatResult, type DeleteRecordOptions, type DeviceAuthAgentCredentialResult, type EmailCodeLanguage, type EmailCodeRequest, type EmailCodeRequestResult, type EmailCodeVerification, type EmailSignInOptions, type ExecutePublicServerFunctionAsyncResponse, type ExecutePublicServerFunctionOptions, type ExecutePublicServerFunctionResponse, type ExecuteServerFunctionAsyncOptions, type ExecuteServerFunctionAsyncResponse, type ExecuteServerFunctionOptions, type ExecuteServerFunctionResponse, type GetAgentTaskCreateOptions, type GetAgentTaskOpenOptions, type GetAgentTaskOptions, type GetPublicServerFunctionExecutionOptions, type GetPublicServerFunctionExecutionResponse, type GetRecordOptions, type GoogleSignInOptions, type IntegrationResponse, type ListAgentModelsResult, type ListAgentProvidersResult, type ListIntegrationsOptions, type ListRecordsOptions, type ListRecordsResponse, type LoginOptions, type LoginResponse, type ManageAgentChatDeleteOptions, type ManageAgentChatListOptions, type ManageAgentChatOptions, type ManageAgentChatRenameOptions, type ManageAgentCredentialOptions, type MicrosoftSignInOptions, MitraApiError, type MitraClient, type MitraClientConfig, type MitraConfig, type MitraInstance, type PatchRecordOptions, type QueuedItem, type RenameAgentChatResult, type SendOptions, type SignInCredentials, type SignUpData, type StopServerFunctionExecutionOptions, type StopServerFunctionExecutionResponse, type UpdateRecordOptions, type User, createClient, exchangeSsoCodeMitra, loginMitra, loginWithGoogleMitra, loginWithMicrosoftMitra };