@mitralab.io/platform-sdk 1.8.7 → 1.9.0-beta.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.
package/dist/index.d.cts CHANGED
@@ -1,5 +1,5 @@
1
- import { Transport, TransportRequestOptions, QueryParamValue, EntityTable, FunctionExecution, ListTemplateConfigsOptions, TemplateConfigPage, ProxyResult, ProxyInput, QueryResult, AgentCredentialOptions, CredentialStatus, AgentModel as AgentModel$1, AgentReadyProvider, CredentialUsage, OAuthStartResult, OAuthExchangeInput, AuthenticationResult, DeviceAuthorization, AgentConnectionCustomProvider, AgentConnectionCustomProviderInput, PublicFunctionsModule, AgentTasksWithSessions, AiProvidersModule } from '@mitralab.io/sdk-core';
2
- export { AgentConnectionCustomProvider, AgentConnectionCustomProviderInput, AgentCredentialOptions, AgentCredentialScope, AgentProviderUsage, AgentQueueItem, AgentReadyProvider, AgentSendAndWaitOptions, AgentSendOptions, AgentSessionTransport, AgentTask, AgentTaskCreateInput, AgentTaskInput, AgentTaskListOptions, AgentTaskRuntime, AgentTaskSessionEventMap, AgentTaskSessionOptions, AgentTaskSessionStatus, AgentTurnResult, AgentTurnUsage, AgentTurnUsageRequest, AiProviders, AiProvidersModule, AuthenticationResult, CredentialStatus, CredentialUsage, CredentialUsageWindow, DeviceAuthorization, EntityListOptions, EntityTable, ExistingAgentTaskSessionOptions, FunctionExecution, IncludedAiQuota, IncludedAiQuotaWindow, ListTemplateConfigsOptions, ManagedAiProfile, AgentMessage as NativeAgentMessage, AgentModel as NativeAgentModel, AgentTaskSession as NativeAgentTaskSession, AgentTimelineItem as NativeAgentTimelineItem, AgentToolEvent as NativeAgentToolEvent, NewAgentTaskSessionOptions, OAuthExchangeInput, OAuthStartResult, OpencodeAiProvider, 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, AgentReadyProvider, CredentialUsage, OAuthStartResult, OAuthExchangeInput, AuthenticationResult, DeviceAuthorization, AgentConnectionCustomProvider, AgentConnectionCustomProviderInput, PublicFunctionsModule, AgentTasksWithSessions, AiProvidersModule, FilesModule } from '@mitralab.io/sdk-core';
2
+ export { AgentConnectionCustomProvider, AgentConnectionCustomProviderInput, AgentCredentialOptions, AgentCredentialScope, AgentProviderUsage, AgentQueueItem, AgentReadyProvider, AgentSendAndWaitOptions, AgentSendOptions, AgentSessionTransport, AgentTask, AgentTaskCreateInput, AgentTaskInput, AgentTaskListOptions, AgentTaskRuntime, AgentTaskSessionEventMap, AgentTaskSessionOptions, AgentTaskSessionStatus, AgentTurnResult, AgentTurnUsage, AgentTurnUsageRequest, AiProviders, AiProvidersModule, AuthenticationResult, CredentialStatus, CredentialUsage, CredentialUsageWindow, DeviceAuthorization, EntityListOptions, EntityTable, ExistingAgentTaskSessionOptions, FileCreator, FileDownloadOptions, FileKind, FileMetadata, FileReadUrl, FileReadUrlItem, FileReadUrlOptions, FileReadUrls, FileStatus, FileTransferError, FileTransferStep, FileUpload, FileUploadInput, FileUploadOptions, FileVisibility, FilesModule, FunctionExecution, IncludedAiQuota, IncludedAiQuotaWindow, ListTemplateConfigsOptions, ManagedAiProfile, AgentMessage as NativeAgentMessage, AgentModel as NativeAgentModel, AgentTaskSession as NativeAgentTaskSession, AgentTimelineItem as NativeAgentTimelineItem, AgentToolEvent as NativeAgentToolEvent, NewAgentTaskSessionOptions, OAuthExchangeInput, OAuthStartResult, OpencodeAiProvider, 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';
@@ -233,6 +233,19 @@ type MicrosoftSignInOptions = AuthPageSignInOptions;
233
233
  type EmailSignInOptions = AuthPageSignInOptions;
234
234
  /** Language of the message IAM sends. The platform writes it in these two. */
235
235
  type EmailCodeLanguage = 'pt-BR' | 'en';
236
+ /** Options for `auth.signInWithIdentityConnection()`. */
237
+ interface IdentityConnectionSignInOptions {
238
+ /** Navigates the current page to the identity provider of the connection. */
239
+ mode: 'redirect';
240
+ /**
241
+ * Where the identity provider sends the browser back. Defaults to the
242
+ * current origin and path, without query or fragment. It has to be one of
243
+ * the redirect URIs the connection client accepts.
244
+ */
245
+ redirectUri?: string;
246
+ /** Defaults to the browser language, and to `pt-BR` when that is neither. */
247
+ language?: EmailCodeLanguage;
248
+ }
236
249
  /** The address to send a one-time code to, and the language to write it in. */
237
250
  interface EmailCodeRequest {
238
251
  email: string;
@@ -349,10 +362,12 @@ interface AuthModuleOptions {
349
362
  /**
350
363
  * Authentication module for managing user sessions.
351
364
  *
352
- * Handles Google and Microsoft SSO, email and password sign-in, trusted session adoption, sign-out,
365
+ * Handles Google and Microsoft SSO, email and password sign-in, the auth page screen that offers
366
+ * them all, trusted session adoption, sign-out,
353
367
  * and automatic token refresh.
354
368
  * Auth state is persisted to localStorage with key `mitra_auth_{appId}`
355
- * and restored on page reload.
369
+ * and restored on page reload; a session from an identity connection is kept
370
+ * in sessionStorage under the same key instead, so it lives in its tab only.
356
371
  *
357
372
  * @example
358
373
  * ```typescript
@@ -378,9 +393,14 @@ declare class AuthModule {
378
393
  private readonly microsoftAuth;
379
394
  private readonly emailAuth;
380
395
  private readonly passwordAuth;
396
+ private readonly authPage;
381
397
  private readonly emailCode;
382
398
  private readonly passwordForm;
399
+ private readonly identityConnection;
400
+ private readonly identityConnectionRedirect;
383
401
  private brand;
402
+ /** Session kept in sessionStorage: an identity connection opens one app per host account, and sharing localStorage would hand one account's session to another tab's reload. */
403
+ private sessionScoped;
384
404
  constructor(appId: string, iamBaseUrl: string, options?: AuthModuleOptions);
385
405
  /** The currently authenticated user, or null. */
386
406
  get currentUser(): User | null;
@@ -603,6 +623,109 @@ declare class AuthModule {
603
623
  * `MAGIC_LINK_INVALID` when the link belongs here but cannot be used.
604
624
  */
605
625
  completeEmailSignInRedirect(): Promise<User | null>;
626
+ /**
627
+ * Signs in on a single screen of the Mitra auth page that offers every method
628
+ * the app has on: Google and Microsoft always, plus password and the email
629
+ * code when the app has them enabled. The person picks one there, and
630
+ * the page reports which; the code is redeemed at that method's IAM route,
631
+ * exactly as the method's own sign-in would.
632
+ *
633
+ * Popup by default; redirect mode navigates away, and
634
+ * {@link completeAuthPageSignInRedirect} finishes it at startup. Since the
635
+ * person may choose the email code, whose message carries a link that opens
636
+ * a new tab, the pending request is kept in `localStorage` under
637
+ * `mitra_all_redirect_{appId}` for 10 minutes - the one-time state and the
638
+ * auth page URL, never a token - as {@link signInWithEmail} does.
639
+ *
640
+ * Call it straight from the click handler, before any `await`, or the browser
641
+ * blocks the popup.
642
+ *
643
+ * @param options - Popup or redirect mode.
644
+ * @returns The authenticated and hydrated user in popup mode.
645
+ * @throws {MitraApiError} When IAM rejects the exchange code.
646
+ * @throws {Error} When the browser blocks or cancels the popup, the flow times
647
+ * out, the response fails origin, source, state, or shape validation, or the
648
+ * page does not say which method produced the code. A person who finishes
649
+ * through the email link instead of the popup leaves this call to time out,
650
+ * which the application should treat as a cancelled popup.
651
+ *
652
+ * @example
653
+ * ```typescript
654
+ * const user = await mitra.auth.signInWithAuthPage();
655
+ * ```
656
+ */
657
+ signInWithAuthPage(options?: AuthPageSignInOptions): Promise<User>;
658
+ /**
659
+ * Completes a sign-in started by {@link signInWithAuthPage} from `#codeMitra`,
660
+ * `#stateMitra` and `#providerMitra`, during application startup: the redirect
661
+ * back to the tab that started it, or the tab the email link opened. The state
662
+ * must match the request pending in this browser, as in
663
+ * {@link completeEmailSignInRedirect}.
664
+ *
665
+ * @returns The authenticated user, or `null` when the URL carries no result,
666
+ * or carries one that belongs to another sign-in method's flow.
667
+ * @throws When the fragment belongs to this flow but its state does not match,
668
+ * the request expired, the page reports an error, or it does not say which
669
+ * method produced the code. The fragment is removed first.
670
+ *
671
+ * @example
672
+ * ```typescript
673
+ * const redirectedUser = await mitra.auth.completeAuthPageSignInRedirect();
674
+ * ```
675
+ */
676
+ completeAuthPageSignInRedirect(): Promise<User | null>;
677
+ /**
678
+ * Completes a sign-in made through an identity connection, such as Sankhya
679
+ * Pass, from the single-use code the platform bridge page leaves in the
680
+ * fragment (`#codeMitra`, `#stateMitra=connection.*`, `#connectionMitra`).
681
+ *
682
+ * `init()` already calls it, so an application only calls it itself when it
683
+ * does not call `init()`. The session is kept in `sessionStorage`, not
684
+ * `localStorage`, and so lives only as long as its tab.
685
+ *
686
+ * @returns The authenticated user, or `null` when the URL carries no
687
+ * identity connection result. A fragment of another sign-in method is left
688
+ * untouched.
689
+ * @throws When the fragment belongs to an identity connection but cannot be
690
+ * redeemed: outside an iframe, with an invalid connection, an error from the
691
+ * bridge, no code, or a code IAM refuses. The fragment is removed first, and
692
+ * the session this page held is dropped from memory, though not from storage.
693
+ */
694
+ completeIdentityConnectionSignInRedirect(): Promise<User | null>;
695
+ /**
696
+ * Signs in through an identity connection, such as Sankhya Pass, outside a
697
+ * host system iframe: the page is sent to the connection's identity provider
698
+ * (Authorization Code with PKCE) and comes back to `redirectUri` with a code.
699
+ * `init()` finishes it on the way back, or {@link completeIdentityConnectionRedirect}
700
+ * when the app does not call `init()`. The returned promise never resolves,
701
+ * because the page navigates away.
702
+ *
703
+ * @param slug - The connection, such as `sankhya-pass`.
704
+ * @throws When the slug is invalid, the connection is unknown or does not
705
+ * support redirect sign-in, or `sessionStorage` is unavailable.
706
+ *
707
+ * @example
708
+ * ```typescript
709
+ * await mitra.auth.signInWithIdentityConnection('sankhya-pass', { mode: 'redirect' });
710
+ * ```
711
+ */
712
+ signInWithIdentityConnection(slug: string, options: IdentityConnectionSignInOptions): Promise<User>;
713
+ /**
714
+ * Completes a redirect started by {@link signInWithIdentityConnection} from
715
+ * the query the identity provider sent back (`?code=...&state=connection.*`).
716
+ *
717
+ * `init()` already calls it. The session is kept in `sessionStorage`, like
718
+ * the one from the host system iframe, and lives only as long as its tab.
719
+ *
720
+ * @returns The authenticated user, or `null` when the query carries no
721
+ * identity connection redirect. Another query is left untouched.
722
+ * @throws When the query belongs to this flow but no pending request in this
723
+ * tab matches its state, the provider reports an error, or the provider or
724
+ * IAM refuses the code. The query is removed first. When a sign-in was
725
+ * pending in this tab, the session this page held is dropped from memory,
726
+ * though not from storage; a callback with no pending sign-in leaves it.
727
+ */
728
+ completeIdentityConnectionRedirect(): Promise<User | null>;
606
729
  /**
607
730
  * @deprecated Use signUpWithPassword(), which opens the Mitra auth page,
608
731
  * startPasswordSignUp() in an app with the form mode on, signInWithEmail() or SSO.
@@ -876,7 +999,7 @@ declare class AuthModule {
876
999
  */
877
1000
  confirmPasswordReset(confirmation: PasswordResetConfirmation): Promise<void>;
878
1001
  /**
879
- * Signs out the current user, clearing all auth state and localStorage.
1002
+ * Signs out the current user, clearing all auth state and the stored session.
880
1003
  *
881
1004
  * In an app whose accounts are its own, the session also ends on the server:
882
1005
  * the refresh token is sent to IAM's logout, so it can no longer be renewed.
@@ -953,6 +1076,9 @@ declare class AuthModule {
953
1076
  *
954
1077
  * Call `me()` afterwards to fetch the associated user data. {@link allTokens}
955
1078
  * goes back to `null`, because it belongs to the session being replaced.
1079
+ * The token starts a session of its own, so it is kept in `localStorage`
1080
+ * even when the one it replaces lived in its tab, and that tab copy is
1081
+ * removed in any case.
956
1082
  *
957
1083
  * @param token - JWT access token.
958
1084
  * @param saveToStorage - Whether to persist to localStorage (default: true).
@@ -1116,6 +1242,8 @@ declare class AuthModule {
1116
1242
  private notifyListeners;
1117
1243
  private saveToStorage;
1118
1244
  private loadFromStorage;
1245
+ /** An unusable entry is removed from this storage only, so a broken tab session does not take the shared one with it. */
1246
+ private restoreFrom;
1119
1247
  private removeFromStorage;
1120
1248
  }
1121
1249
 
@@ -1290,7 +1418,14 @@ interface MitraClient {
1290
1418
  * passwordLoginEnabled, and the brand `requestEmailCode()` sends with, from
1291
1419
  * the public app info endpoint.
1292
1420
  *
1293
- * Safe to call multiple times. Subsequent calls are no-ops.
1421
+ * In a browser it also finishes a sign-in through an identity connection
1422
+ * (see `auth.completeIdentityConnectionSignInRedirect()` and
1423
+ * `auth.completeIdentityConnectionRedirect()`) when the URL carries one, and
1424
+ * rejects when that sign-in fails. Without such a fragment or query it makes
1425
+ * no extra request.
1426
+ *
1427
+ * Safe to call multiple times. A call made while another runs waits for it;
1428
+ * once the app info is read, later calls are no-ops.
1294
1429
  *
1295
1430
  * @example
1296
1431
  * ```typescript
@@ -1344,6 +1479,26 @@ interface MitraClient {
1344
1479
  /** Browser-safe credential status, model discovery, and provider auth flows. */
1345
1480
  agentCredentials: AgentCredentialsModule;
1346
1481
  readonly aiProviders: AiProvidersModule;
1482
+ /**
1483
+ * App files kept by the Data Manager: `upload` a `File` or `Blob`, read its
1484
+ * metadata with `get`, ask for signed read links with `getUrl` or `getUrls`,
1485
+ * `download` and `delete`.
1486
+ *
1487
+ * The API calls carry the session token and `X-App-Id`. The bytes go straight
1488
+ * to storage through the signed link, with the browser `fetch` and without
1489
+ * those headers.
1490
+ *
1491
+ * @example
1492
+ * ```typescript
1493
+ * // `picked` is a File from an <input type="file">
1494
+ * const file = await mitra.files.upload(picked, {
1495
+ * kind: 'PERMANENT',
1496
+ * visibility: 'PRIVATE',
1497
+ * });
1498
+ * const { url } = await mitra.files.getUrl(file.id);
1499
+ * ```
1500
+ */
1501
+ readonly files: FilesModule;
1347
1502
  /**
1348
1503
  * Integration module for proxying HTTP requests to external APIs.
1349
1504
  *
@@ -1402,6 +1557,7 @@ interface MitraClient {
1402
1557
  * - **functions**: Serverless function invocation
1403
1558
  * - **integration**: Proxy HTTP requests to external APIs
1404
1559
  * - **queries**: Custom query management and execution
1560
+ * - **files**: App file upload, signed read links and download
1405
1561
  *
1406
1562
  * After creating the client, call `init()` to resolve the app's public config
1407
1563
  * (dataSourceId, allowSignup, emailLoginEnabled, passwordLoginEnabled) automatically from the server.
@@ -1610,4 +1766,4 @@ type StopServerFunctionExecutionResponse = LegacyTypes.StopServerFunctionExecuti
1610
1766
  /** @deprecated Legacy compatibility type. */
1611
1767
  type UpdateRecordOptions = LegacyTypes.UpdateRecordOptions;
1612
1768
 
1613
- 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 AllTokens, type AuthAgentCredentialResult, type AuthPageSignInOptions, type BackofficeToken, 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 MitraSpaceToken, type PasswordChange, type PasswordResetConfirmation, type PasswordResetOptions, type PasswordResetRequestResult, type PasswordSignUpCompletion, type PasswordSignUpRequest, type PasswordSignUpRequestResult, type PatchRecordOptions, type PlatformSessionTokens, type QueuedItem, type RenameAgentChatResult, type SendOptions, type SignInCredentials, type SignUpData, type StopServerFunctionExecutionOptions, type StopServerFunctionExecutionResponse, type UpdateRecordOptions, type User, createClient, exchangeSsoCodeMitra, loginMitra, loginWithGoogleMitra, loginWithMicrosoftMitra };
1769
+ 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 AllTokens, type AuthAgentCredentialResult, type AuthPageSignInOptions, type BackofficeToken, 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 IdentityConnectionSignInOptions, 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 MitraSpaceToken, type PasswordChange, type PasswordResetConfirmation, type PasswordResetOptions, type PasswordResetRequestResult, type PasswordSignUpCompletion, type PasswordSignUpRequest, type PasswordSignUpRequestResult, type PatchRecordOptions, type PlatformSessionTokens, 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, AgentCredentialOptions, CredentialStatus, AgentModel as AgentModel$1, AgentReadyProvider, CredentialUsage, OAuthStartResult, OAuthExchangeInput, AuthenticationResult, DeviceAuthorization, AgentConnectionCustomProvider, AgentConnectionCustomProviderInput, PublicFunctionsModule, AgentTasksWithSessions, AiProvidersModule } from '@mitralab.io/sdk-core';
2
- export { AgentConnectionCustomProvider, AgentConnectionCustomProviderInput, AgentCredentialOptions, AgentCredentialScope, AgentProviderUsage, AgentQueueItem, AgentReadyProvider, AgentSendAndWaitOptions, AgentSendOptions, AgentSessionTransport, AgentTask, AgentTaskCreateInput, AgentTaskInput, AgentTaskListOptions, AgentTaskRuntime, AgentTaskSessionEventMap, AgentTaskSessionOptions, AgentTaskSessionStatus, AgentTurnResult, AgentTurnUsage, AgentTurnUsageRequest, AiProviders, AiProvidersModule, AuthenticationResult, CredentialStatus, CredentialUsage, CredentialUsageWindow, DeviceAuthorization, EntityListOptions, EntityTable, ExistingAgentTaskSessionOptions, FunctionExecution, IncludedAiQuota, IncludedAiQuotaWindow, ListTemplateConfigsOptions, ManagedAiProfile, AgentMessage as NativeAgentMessage, AgentModel as NativeAgentModel, AgentTaskSession as NativeAgentTaskSession, AgentTimelineItem as NativeAgentTimelineItem, AgentToolEvent as NativeAgentToolEvent, NewAgentTaskSessionOptions, OAuthExchangeInput, OAuthStartResult, OpencodeAiProvider, 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, AgentReadyProvider, CredentialUsage, OAuthStartResult, OAuthExchangeInput, AuthenticationResult, DeviceAuthorization, AgentConnectionCustomProvider, AgentConnectionCustomProviderInput, PublicFunctionsModule, AgentTasksWithSessions, AiProvidersModule, FilesModule } from '@mitralab.io/sdk-core';
2
+ export { AgentConnectionCustomProvider, AgentConnectionCustomProviderInput, AgentCredentialOptions, AgentCredentialScope, AgentProviderUsage, AgentQueueItem, AgentReadyProvider, AgentSendAndWaitOptions, AgentSendOptions, AgentSessionTransport, AgentTask, AgentTaskCreateInput, AgentTaskInput, AgentTaskListOptions, AgentTaskRuntime, AgentTaskSessionEventMap, AgentTaskSessionOptions, AgentTaskSessionStatus, AgentTurnResult, AgentTurnUsage, AgentTurnUsageRequest, AiProviders, AiProvidersModule, AuthenticationResult, CredentialStatus, CredentialUsage, CredentialUsageWindow, DeviceAuthorization, EntityListOptions, EntityTable, ExistingAgentTaskSessionOptions, FileCreator, FileDownloadOptions, FileKind, FileMetadata, FileReadUrl, FileReadUrlItem, FileReadUrlOptions, FileReadUrls, FileStatus, FileTransferError, FileTransferStep, FileUpload, FileUploadInput, FileUploadOptions, FileVisibility, FilesModule, FunctionExecution, IncludedAiQuota, IncludedAiQuotaWindow, ListTemplateConfigsOptions, ManagedAiProfile, AgentMessage as NativeAgentMessage, AgentModel as NativeAgentModel, AgentTaskSession as NativeAgentTaskSession, AgentTimelineItem as NativeAgentTimelineItem, AgentToolEvent as NativeAgentToolEvent, NewAgentTaskSessionOptions, OAuthExchangeInput, OAuthStartResult, OpencodeAiProvider, 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';
@@ -233,6 +233,19 @@ type MicrosoftSignInOptions = AuthPageSignInOptions;
233
233
  type EmailSignInOptions = AuthPageSignInOptions;
234
234
  /** Language of the message IAM sends. The platform writes it in these two. */
235
235
  type EmailCodeLanguage = 'pt-BR' | 'en';
236
+ /** Options for `auth.signInWithIdentityConnection()`. */
237
+ interface IdentityConnectionSignInOptions {
238
+ /** Navigates the current page to the identity provider of the connection. */
239
+ mode: 'redirect';
240
+ /**
241
+ * Where the identity provider sends the browser back. Defaults to the
242
+ * current origin and path, without query or fragment. It has to be one of
243
+ * the redirect URIs the connection client accepts.
244
+ */
245
+ redirectUri?: string;
246
+ /** Defaults to the browser language, and to `pt-BR` when that is neither. */
247
+ language?: EmailCodeLanguage;
248
+ }
236
249
  /** The address to send a one-time code to, and the language to write it in. */
237
250
  interface EmailCodeRequest {
238
251
  email: string;
@@ -349,10 +362,12 @@ interface AuthModuleOptions {
349
362
  /**
350
363
  * Authentication module for managing user sessions.
351
364
  *
352
- * Handles Google and Microsoft SSO, email and password sign-in, trusted session adoption, sign-out,
365
+ * Handles Google and Microsoft SSO, email and password sign-in, the auth page screen that offers
366
+ * them all, trusted session adoption, sign-out,
353
367
  * and automatic token refresh.
354
368
  * Auth state is persisted to localStorage with key `mitra_auth_{appId}`
355
- * and restored on page reload.
369
+ * and restored on page reload; a session from an identity connection is kept
370
+ * in sessionStorage under the same key instead, so it lives in its tab only.
356
371
  *
357
372
  * @example
358
373
  * ```typescript
@@ -378,9 +393,14 @@ declare class AuthModule {
378
393
  private readonly microsoftAuth;
379
394
  private readonly emailAuth;
380
395
  private readonly passwordAuth;
396
+ private readonly authPage;
381
397
  private readonly emailCode;
382
398
  private readonly passwordForm;
399
+ private readonly identityConnection;
400
+ private readonly identityConnectionRedirect;
383
401
  private brand;
402
+ /** Session kept in sessionStorage: an identity connection opens one app per host account, and sharing localStorage would hand one account's session to another tab's reload. */
403
+ private sessionScoped;
384
404
  constructor(appId: string, iamBaseUrl: string, options?: AuthModuleOptions);
385
405
  /** The currently authenticated user, or null. */
386
406
  get currentUser(): User | null;
@@ -603,6 +623,109 @@ declare class AuthModule {
603
623
  * `MAGIC_LINK_INVALID` when the link belongs here but cannot be used.
604
624
  */
605
625
  completeEmailSignInRedirect(): Promise<User | null>;
626
+ /**
627
+ * Signs in on a single screen of the Mitra auth page that offers every method
628
+ * the app has on: Google and Microsoft always, plus password and the email
629
+ * code when the app has them enabled. The person picks one there, and
630
+ * the page reports which; the code is redeemed at that method's IAM route,
631
+ * exactly as the method's own sign-in would.
632
+ *
633
+ * Popup by default; redirect mode navigates away, and
634
+ * {@link completeAuthPageSignInRedirect} finishes it at startup. Since the
635
+ * person may choose the email code, whose message carries a link that opens
636
+ * a new tab, the pending request is kept in `localStorage` under
637
+ * `mitra_all_redirect_{appId}` for 10 minutes - the one-time state and the
638
+ * auth page URL, never a token - as {@link signInWithEmail} does.
639
+ *
640
+ * Call it straight from the click handler, before any `await`, or the browser
641
+ * blocks the popup.
642
+ *
643
+ * @param options - Popup or redirect mode.
644
+ * @returns The authenticated and hydrated user in popup mode.
645
+ * @throws {MitraApiError} When IAM rejects the exchange code.
646
+ * @throws {Error} When the browser blocks or cancels the popup, the flow times
647
+ * out, the response fails origin, source, state, or shape validation, or the
648
+ * page does not say which method produced the code. A person who finishes
649
+ * through the email link instead of the popup leaves this call to time out,
650
+ * which the application should treat as a cancelled popup.
651
+ *
652
+ * @example
653
+ * ```typescript
654
+ * const user = await mitra.auth.signInWithAuthPage();
655
+ * ```
656
+ */
657
+ signInWithAuthPage(options?: AuthPageSignInOptions): Promise<User>;
658
+ /**
659
+ * Completes a sign-in started by {@link signInWithAuthPage} from `#codeMitra`,
660
+ * `#stateMitra` and `#providerMitra`, during application startup: the redirect
661
+ * back to the tab that started it, or the tab the email link opened. The state
662
+ * must match the request pending in this browser, as in
663
+ * {@link completeEmailSignInRedirect}.
664
+ *
665
+ * @returns The authenticated user, or `null` when the URL carries no result,
666
+ * or carries one that belongs to another sign-in method's flow.
667
+ * @throws When the fragment belongs to this flow but its state does not match,
668
+ * the request expired, the page reports an error, or it does not say which
669
+ * method produced the code. The fragment is removed first.
670
+ *
671
+ * @example
672
+ * ```typescript
673
+ * const redirectedUser = await mitra.auth.completeAuthPageSignInRedirect();
674
+ * ```
675
+ */
676
+ completeAuthPageSignInRedirect(): Promise<User | null>;
677
+ /**
678
+ * Completes a sign-in made through an identity connection, such as Sankhya
679
+ * Pass, from the single-use code the platform bridge page leaves in the
680
+ * fragment (`#codeMitra`, `#stateMitra=connection.*`, `#connectionMitra`).
681
+ *
682
+ * `init()` already calls it, so an application only calls it itself when it
683
+ * does not call `init()`. The session is kept in `sessionStorage`, not
684
+ * `localStorage`, and so lives only as long as its tab.
685
+ *
686
+ * @returns The authenticated user, or `null` when the URL carries no
687
+ * identity connection result. A fragment of another sign-in method is left
688
+ * untouched.
689
+ * @throws When the fragment belongs to an identity connection but cannot be
690
+ * redeemed: outside an iframe, with an invalid connection, an error from the
691
+ * bridge, no code, or a code IAM refuses. The fragment is removed first, and
692
+ * the session this page held is dropped from memory, though not from storage.
693
+ */
694
+ completeIdentityConnectionSignInRedirect(): Promise<User | null>;
695
+ /**
696
+ * Signs in through an identity connection, such as Sankhya Pass, outside a
697
+ * host system iframe: the page is sent to the connection's identity provider
698
+ * (Authorization Code with PKCE) and comes back to `redirectUri` with a code.
699
+ * `init()` finishes it on the way back, or {@link completeIdentityConnectionRedirect}
700
+ * when the app does not call `init()`. The returned promise never resolves,
701
+ * because the page navigates away.
702
+ *
703
+ * @param slug - The connection, such as `sankhya-pass`.
704
+ * @throws When the slug is invalid, the connection is unknown or does not
705
+ * support redirect sign-in, or `sessionStorage` is unavailable.
706
+ *
707
+ * @example
708
+ * ```typescript
709
+ * await mitra.auth.signInWithIdentityConnection('sankhya-pass', { mode: 'redirect' });
710
+ * ```
711
+ */
712
+ signInWithIdentityConnection(slug: string, options: IdentityConnectionSignInOptions): Promise<User>;
713
+ /**
714
+ * Completes a redirect started by {@link signInWithIdentityConnection} from
715
+ * the query the identity provider sent back (`?code=...&state=connection.*`).
716
+ *
717
+ * `init()` already calls it. The session is kept in `sessionStorage`, like
718
+ * the one from the host system iframe, and lives only as long as its tab.
719
+ *
720
+ * @returns The authenticated user, or `null` when the query carries no
721
+ * identity connection redirect. Another query is left untouched.
722
+ * @throws When the query belongs to this flow but no pending request in this
723
+ * tab matches its state, the provider reports an error, or the provider or
724
+ * IAM refuses the code. The query is removed first. When a sign-in was
725
+ * pending in this tab, the session this page held is dropped from memory,
726
+ * though not from storage; a callback with no pending sign-in leaves it.
727
+ */
728
+ completeIdentityConnectionRedirect(): Promise<User | null>;
606
729
  /**
607
730
  * @deprecated Use signUpWithPassword(), which opens the Mitra auth page,
608
731
  * startPasswordSignUp() in an app with the form mode on, signInWithEmail() or SSO.
@@ -876,7 +999,7 @@ declare class AuthModule {
876
999
  */
877
1000
  confirmPasswordReset(confirmation: PasswordResetConfirmation): Promise<void>;
878
1001
  /**
879
- * Signs out the current user, clearing all auth state and localStorage.
1002
+ * Signs out the current user, clearing all auth state and the stored session.
880
1003
  *
881
1004
  * In an app whose accounts are its own, the session also ends on the server:
882
1005
  * the refresh token is sent to IAM's logout, so it can no longer be renewed.
@@ -953,6 +1076,9 @@ declare class AuthModule {
953
1076
  *
954
1077
  * Call `me()` afterwards to fetch the associated user data. {@link allTokens}
955
1078
  * goes back to `null`, because it belongs to the session being replaced.
1079
+ * The token starts a session of its own, so it is kept in `localStorage`
1080
+ * even when the one it replaces lived in its tab, and that tab copy is
1081
+ * removed in any case.
956
1082
  *
957
1083
  * @param token - JWT access token.
958
1084
  * @param saveToStorage - Whether to persist to localStorage (default: true).
@@ -1116,6 +1242,8 @@ declare class AuthModule {
1116
1242
  private notifyListeners;
1117
1243
  private saveToStorage;
1118
1244
  private loadFromStorage;
1245
+ /** An unusable entry is removed from this storage only, so a broken tab session does not take the shared one with it. */
1246
+ private restoreFrom;
1119
1247
  private removeFromStorage;
1120
1248
  }
1121
1249
 
@@ -1290,7 +1418,14 @@ interface MitraClient {
1290
1418
  * passwordLoginEnabled, and the brand `requestEmailCode()` sends with, from
1291
1419
  * the public app info endpoint.
1292
1420
  *
1293
- * Safe to call multiple times. Subsequent calls are no-ops.
1421
+ * In a browser it also finishes a sign-in through an identity connection
1422
+ * (see `auth.completeIdentityConnectionSignInRedirect()` and
1423
+ * `auth.completeIdentityConnectionRedirect()`) when the URL carries one, and
1424
+ * rejects when that sign-in fails. Without such a fragment or query it makes
1425
+ * no extra request.
1426
+ *
1427
+ * Safe to call multiple times. A call made while another runs waits for it;
1428
+ * once the app info is read, later calls are no-ops.
1294
1429
  *
1295
1430
  * @example
1296
1431
  * ```typescript
@@ -1344,6 +1479,26 @@ interface MitraClient {
1344
1479
  /** Browser-safe credential status, model discovery, and provider auth flows. */
1345
1480
  agentCredentials: AgentCredentialsModule;
1346
1481
  readonly aiProviders: AiProvidersModule;
1482
+ /**
1483
+ * App files kept by the Data Manager: `upload` a `File` or `Blob`, read its
1484
+ * metadata with `get`, ask for signed read links with `getUrl` or `getUrls`,
1485
+ * `download` and `delete`.
1486
+ *
1487
+ * The API calls carry the session token and `X-App-Id`. The bytes go straight
1488
+ * to storage through the signed link, with the browser `fetch` and without
1489
+ * those headers.
1490
+ *
1491
+ * @example
1492
+ * ```typescript
1493
+ * // `picked` is a File from an <input type="file">
1494
+ * const file = await mitra.files.upload(picked, {
1495
+ * kind: 'PERMANENT',
1496
+ * visibility: 'PRIVATE',
1497
+ * });
1498
+ * const { url } = await mitra.files.getUrl(file.id);
1499
+ * ```
1500
+ */
1501
+ readonly files: FilesModule;
1347
1502
  /**
1348
1503
  * Integration module for proxying HTTP requests to external APIs.
1349
1504
  *
@@ -1402,6 +1557,7 @@ interface MitraClient {
1402
1557
  * - **functions**: Serverless function invocation
1403
1558
  * - **integration**: Proxy HTTP requests to external APIs
1404
1559
  * - **queries**: Custom query management and execution
1560
+ * - **files**: App file upload, signed read links and download
1405
1561
  *
1406
1562
  * After creating the client, call `init()` to resolve the app's public config
1407
1563
  * (dataSourceId, allowSignup, emailLoginEnabled, passwordLoginEnabled) automatically from the server.
@@ -1610,4 +1766,4 @@ type StopServerFunctionExecutionResponse = LegacyTypes.StopServerFunctionExecuti
1610
1766
  /** @deprecated Legacy compatibility type. */
1611
1767
  type UpdateRecordOptions = LegacyTypes.UpdateRecordOptions;
1612
1768
 
1613
- 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 AllTokens, type AuthAgentCredentialResult, type AuthPageSignInOptions, type BackofficeToken, 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 MitraSpaceToken, type PasswordChange, type PasswordResetConfirmation, type PasswordResetOptions, type PasswordResetRequestResult, type PasswordSignUpCompletion, type PasswordSignUpRequest, type PasswordSignUpRequestResult, type PatchRecordOptions, type PlatformSessionTokens, type QueuedItem, type RenameAgentChatResult, type SendOptions, type SignInCredentials, type SignUpData, type StopServerFunctionExecutionOptions, type StopServerFunctionExecutionResponse, type UpdateRecordOptions, type User, createClient, exchangeSsoCodeMitra, loginMitra, loginWithGoogleMitra, loginWithMicrosoftMitra };
1769
+ 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 AllTokens, type AuthAgentCredentialResult, type AuthPageSignInOptions, type BackofficeToken, 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 IdentityConnectionSignInOptions, 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 MitraSpaceToken, type PasswordChange, type PasswordResetConfirmation, type PasswordResetOptions, type PasswordResetRequestResult, type PasswordSignUpCompletion, type PasswordSignUpRequest, type PasswordSignUpRequestResult, type PatchRecordOptions, type PlatformSessionTokens, type QueuedItem, type RenameAgentChatResult, type SendOptions, type SignInCredentials, type SignUpData, type StopServerFunctionExecutionOptions, type StopServerFunctionExecutionResponse, type UpdateRecordOptions, type User, createClient, exchangeSsoCodeMitra, loginMitra, loginWithGoogleMitra, loginWithMicrosoftMitra };