@mitralab.io/platform-sdk 1.7.0-beta.2 → 1.8.0-beta.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/CHANGELOG.md +44 -0
- package/README.md +15 -4
- package/dist/index.cjs +272 -33
- package/dist/index.d.cts +130 -7
- package/dist/index.d.ts +130 -7
- package/dist/index.js +275 -36
- package/package.json +2 -2
package/dist/index.d.cts
CHANGED
|
@@ -38,6 +38,8 @@ interface RequestOptions extends Omit<TransportRequestOptions, 'method'> {
|
|
|
38
38
|
params?: Record<string, QueryParamValue>;
|
|
39
39
|
/** @internal Flag to prevent infinite retry loops on 401 */
|
|
40
40
|
isRetry?: boolean;
|
|
41
|
+
/** Lets the request outlive the page that sent it, as `fetch` `keepalive` does. */
|
|
42
|
+
keepalive?: boolean;
|
|
41
43
|
}
|
|
42
44
|
/**
|
|
43
45
|
* HTTP client for making authenticated API requests.
|
|
@@ -247,6 +249,19 @@ interface EmailCodeRequestResult {
|
|
|
247
249
|
/** How long to wait before offering to send another message. */
|
|
248
250
|
resendAfterSeconds: number;
|
|
249
251
|
}
|
|
252
|
+
/** Options for `auth.requestPasswordReset()`. */
|
|
253
|
+
interface PasswordResetOptions {
|
|
254
|
+
/** Defaults to the browser language, and to `pt-BR` when that is neither. */
|
|
255
|
+
language?: EmailCodeLanguage;
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* What IAM accepted for a reset. Neutral like {@link EmailCodeRequestResult}:
|
|
259
|
+
* it says nothing about whether the address has an account.
|
|
260
|
+
*/
|
|
261
|
+
interface PasswordResetRequestResult {
|
|
262
|
+
/** How long to wait before offering to send another message. */
|
|
263
|
+
resendAfterSeconds: number;
|
|
264
|
+
}
|
|
250
265
|
/** The code the person read in the message, against the request that sent it. */
|
|
251
266
|
interface EmailCodeVerification {
|
|
252
267
|
receipt: string;
|
|
@@ -306,7 +321,7 @@ interface AuthModuleOptions {
|
|
|
306
321
|
/**
|
|
307
322
|
* Authentication module for managing user sessions.
|
|
308
323
|
*
|
|
309
|
-
* Handles Google and Microsoft SSO, email sign-in, trusted session adoption, sign-out,
|
|
324
|
+
* Handles Google and Microsoft SSO, email and password sign-in, trusted session adoption, sign-out,
|
|
310
325
|
* and automatic token refresh.
|
|
311
326
|
* Auth state is persisted to localStorage with key `mitra_auth_{appId}`
|
|
312
327
|
* and restored on page reload.
|
|
@@ -334,6 +349,7 @@ declare class AuthModule {
|
|
|
334
349
|
private readonly googleAuth;
|
|
335
350
|
private readonly microsoftAuth;
|
|
336
351
|
private readonly emailAuth;
|
|
352
|
+
private readonly passwordAuth;
|
|
337
353
|
private readonly emailCode;
|
|
338
354
|
private brand;
|
|
339
355
|
constructor(appId: string, iamBaseUrl: string, options?: AuthModuleOptions);
|
|
@@ -359,7 +375,10 @@ declare class AuthModule {
|
|
|
359
375
|
get allTokens(): AllTokens | null;
|
|
360
376
|
/** Whether a user is currently authenticated (local check, not server-validated). */
|
|
361
377
|
get isAuthenticated(): boolean;
|
|
362
|
-
/**
|
|
378
|
+
/**
|
|
379
|
+
* @deprecated The password never goes through the app's code. Use
|
|
380
|
+
* signInWithPassword(), which opens the Mitra auth page, signInWithEmail() or SSO.
|
|
381
|
+
*/
|
|
363
382
|
signIn(_credentials: SignInCredentials): Promise<User>;
|
|
364
383
|
/**
|
|
365
384
|
* Signs in with Google SSO.
|
|
@@ -555,11 +574,106 @@ declare class AuthModule {
|
|
|
555
574
|
* `MAGIC_LINK_INVALID` when the link belongs here but cannot be used.
|
|
556
575
|
*/
|
|
557
576
|
completeEmailSignInRedirect(): Promise<User | null>;
|
|
558
|
-
/**
|
|
577
|
+
/**
|
|
578
|
+
* @deprecated The password never goes through the app's code. Use
|
|
579
|
+
* signUpWithPassword(), which opens the Mitra auth page, signInWithEmail() or SSO.
|
|
580
|
+
*/
|
|
559
581
|
signUp(_data: SignUpData): Promise<User>;
|
|
582
|
+
/**
|
|
583
|
+
* Signs in with email and password, typed into the Mitra auth page in a popup.
|
|
584
|
+
* The password never reaches the app's code: the page sends it to IAM and
|
|
585
|
+
* hands back a single-use exchange code, redeemed like the email sign-in.
|
|
586
|
+
*
|
|
587
|
+
* Offer it only when `mitra.passwordLoginEnabled` is `true`, which needs an
|
|
588
|
+
* app whose accounts are its own (exclusive login mode). Call it straight
|
|
589
|
+
* from the click handler, before any `await`, or the browser blocks the popup.
|
|
590
|
+
*
|
|
591
|
+
* @returns The authenticated and hydrated user.
|
|
592
|
+
* @throws {MitraApiError} When IAM rejects the exchange code.
|
|
593
|
+
* @throws {Error} When the browser blocks or cancels the popup, the flow times
|
|
594
|
+
* out, or the response fails origin, source, state, or shape validation. Wrong
|
|
595
|
+
* credentials are answered on the auth page itself, not here.
|
|
596
|
+
*
|
|
597
|
+
* @example
|
|
598
|
+
* ```typescript
|
|
599
|
+
* const user = await mitra.auth.signInWithPassword();
|
|
600
|
+
* ```
|
|
601
|
+
*/
|
|
602
|
+
signInWithPassword(): Promise<User>;
|
|
603
|
+
/**
|
|
604
|
+
* Creates a password for an app account, on the Mitra auth page in a popup:
|
|
605
|
+
* the page asks for the address, sends a code to it to prove the mailbox is
|
|
606
|
+
* the person's, and takes the password with that code. The person ends signed
|
|
607
|
+
* in, as with {@link signInWithPassword}.
|
|
608
|
+
*
|
|
609
|
+
* @returns The authenticated and hydrated user.
|
|
610
|
+
* @throws The same errors as {@link signInWithPassword}.
|
|
611
|
+
*
|
|
612
|
+
* @example
|
|
613
|
+
* ```typescript
|
|
614
|
+
* const user = await mitra.auth.signUpWithPassword();
|
|
615
|
+
* ```
|
|
616
|
+
*/
|
|
617
|
+
signUpWithPassword(): Promise<User>;
|
|
618
|
+
/**
|
|
619
|
+
* Changes the password of the signed-in person, on the Mitra auth page in a
|
|
620
|
+
* popup. The page asks for the current and the new password itself, so the
|
|
621
|
+
* app never sees either one.
|
|
622
|
+
*
|
|
623
|
+
* The page acts on this session, so it asks for the access token once it
|
|
624
|
+
* loads, and the SDK answers with `postMessage` to the auth page origin only:
|
|
625
|
+
* the token never goes in the popup URL.
|
|
626
|
+
*
|
|
627
|
+
* IAM ends every session of the account when the password changes, this one
|
|
628
|
+
* included, so the page signs in again with the new password and hands back a
|
|
629
|
+
* new session, which replaces the current one.
|
|
630
|
+
*
|
|
631
|
+
* When the change goes through but that new sign-in fails, the call rejects
|
|
632
|
+
* with `PASSWORD_CHANGED_SIGN_IN_AGAIN` and the local session is cleared,
|
|
633
|
+
* since IAM already ended it: send the person to sign in with the new password.
|
|
634
|
+
*
|
|
635
|
+
* @returns The user of the new session.
|
|
636
|
+
* @throws {MitraApiError} `401` when nobody is signed in, and
|
|
637
|
+
* `PASSWORD_CHANGED_SIGN_IN_AGAIN` (status `401`) as above.
|
|
638
|
+
* @throws The same errors as {@link signInWithPassword}, and an error when the
|
|
639
|
+
* session ends while the popup is open.
|
|
640
|
+
*
|
|
641
|
+
* @example
|
|
642
|
+
* ```typescript
|
|
643
|
+
* await mitra.auth.changePassword();
|
|
644
|
+
* ```
|
|
645
|
+
*/
|
|
646
|
+
changePassword(): Promise<User>;
|
|
647
|
+
/**
|
|
648
|
+
* Asks IAM to email a link to set a new password. Only the address goes: the
|
|
649
|
+
* link opens the Mitra auth page, where the new password is typed, so there
|
|
650
|
+
* is no method here to confirm the reset.
|
|
651
|
+
*
|
|
652
|
+
* IAM answers the same whether or not the address has an account, so this
|
|
653
|
+
* resolves without saying which.
|
|
654
|
+
*
|
|
655
|
+
* @param email - The address of the account.
|
|
656
|
+
* @param options - The language of the message.
|
|
657
|
+
* @returns How long the application should wait before offering to resend.
|
|
658
|
+
* @throws {MitraApiError} `RATE_LIMITED` when this address asked too often,
|
|
659
|
+
* and `RATE_LIMIT_EXCEEDED` when this network did, both with
|
|
660
|
+
* `retryAfterSeconds` when IAM sends it.
|
|
661
|
+
*
|
|
662
|
+
* @example
|
|
663
|
+
* ```typescript
|
|
664
|
+
* const { resendAfterSeconds } = await mitra.auth.requestPasswordReset('person@example.com');
|
|
665
|
+
* ```
|
|
666
|
+
*/
|
|
667
|
+
requestPasswordReset(email: string, options?: PasswordResetOptions): Promise<PasswordResetRequestResult>;
|
|
560
668
|
/**
|
|
561
669
|
* Signs out the current user, clearing all auth state and localStorage.
|
|
562
670
|
*
|
|
671
|
+
* In an app whose accounts are its own, the session also ends on the server:
|
|
672
|
+
* the refresh token is sent to IAM's logout, so it can no longer be renewed.
|
|
673
|
+
* The local state is cleared right away whatever IAM answers, and the request
|
|
674
|
+
* survives a navigation to `redirectUrl`. The access token already issued
|
|
675
|
+
* stays valid until it expires.
|
|
676
|
+
*
|
|
563
677
|
* @param redirectUrl - Optional URL to navigate to after sign-out.
|
|
564
678
|
*
|
|
565
679
|
* @example
|
|
@@ -772,6 +886,8 @@ declare class AuthModule {
|
|
|
772
886
|
* ```
|
|
773
887
|
*/
|
|
774
888
|
onAuthStateChange(callback: AuthStateChangeCallback): () => void;
|
|
889
|
+
/** Best effort: the person asked to leave, and that already happened locally. */
|
|
890
|
+
private endServerSession;
|
|
775
891
|
private doRefresh;
|
|
776
892
|
private establishSession;
|
|
777
893
|
private setAuthState;
|
|
@@ -955,8 +1071,9 @@ interface MitraClient {
|
|
|
955
1071
|
/**
|
|
956
1072
|
* Initializes the client by resolving app config from the server.
|
|
957
1073
|
*
|
|
958
|
-
* Fetches the compatibility dataSourceId, allowSignup, emailLoginEnabled,
|
|
959
|
-
* the brand `requestEmailCode()` sends with, from
|
|
1074
|
+
* Fetches the compatibility dataSourceId, allowSignup, emailLoginEnabled,
|
|
1075
|
+
* passwordLoginEnabled, and the brand `requestEmailCode()` sends with, from
|
|
1076
|
+
* the public app info endpoint.
|
|
960
1077
|
*
|
|
961
1078
|
* Safe to call multiple times. Subsequent calls are no-ops.
|
|
962
1079
|
*
|
|
@@ -1049,6 +1166,12 @@ interface MitraClient {
|
|
|
1049
1166
|
* server does not answer the field.
|
|
1050
1167
|
*/
|
|
1051
1168
|
readonly emailLoginEnabled: boolean;
|
|
1169
|
+
/**
|
|
1170
|
+
* Whether this app offers sign-in by email and password, which only an app
|
|
1171
|
+
* whose accounts are its own can. Defaults to `false` before `init()` is
|
|
1172
|
+
* called, and stays `false` when the server does not answer the field.
|
|
1173
|
+
*/
|
|
1174
|
+
readonly passwordLoginEnabled: boolean;
|
|
1052
1175
|
/**
|
|
1053
1176
|
* The configuration used to create this client.
|
|
1054
1177
|
*/
|
|
@@ -1065,7 +1188,7 @@ interface MitraClient {
|
|
|
1065
1188
|
* - **queries**: Custom query management and execution
|
|
1066
1189
|
*
|
|
1067
1190
|
* After creating the client, call `init()` to resolve the app's public config
|
|
1068
|
-
* (dataSourceId, allowSignup, emailLoginEnabled) automatically from the server.
|
|
1191
|
+
* (dataSourceId, allowSignup, emailLoginEnabled, passwordLoginEnabled) automatically from the server.
|
|
1069
1192
|
*
|
|
1070
1193
|
* @param config - Configuration options for the client.
|
|
1071
1194
|
* @returns A configured MitraClient instance.
|
|
@@ -1271,4 +1394,4 @@ type StopServerFunctionExecutionResponse = LegacyTypes.StopServerFunctionExecuti
|
|
|
1271
1394
|
/** @deprecated Legacy compatibility type. */
|
|
1272
1395
|
type UpdateRecordOptions = LegacyTypes.UpdateRecordOptions;
|
|
1273
1396
|
|
|
1274
|
-
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 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 };
|
|
1397
|
+
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 PasswordResetOptions, type PasswordResetRequestResult, 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
|
@@ -38,6 +38,8 @@ interface RequestOptions extends Omit<TransportRequestOptions, 'method'> {
|
|
|
38
38
|
params?: Record<string, QueryParamValue>;
|
|
39
39
|
/** @internal Flag to prevent infinite retry loops on 401 */
|
|
40
40
|
isRetry?: boolean;
|
|
41
|
+
/** Lets the request outlive the page that sent it, as `fetch` `keepalive` does. */
|
|
42
|
+
keepalive?: boolean;
|
|
41
43
|
}
|
|
42
44
|
/**
|
|
43
45
|
* HTTP client for making authenticated API requests.
|
|
@@ -247,6 +249,19 @@ interface EmailCodeRequestResult {
|
|
|
247
249
|
/** How long to wait before offering to send another message. */
|
|
248
250
|
resendAfterSeconds: number;
|
|
249
251
|
}
|
|
252
|
+
/** Options for `auth.requestPasswordReset()`. */
|
|
253
|
+
interface PasswordResetOptions {
|
|
254
|
+
/** Defaults to the browser language, and to `pt-BR` when that is neither. */
|
|
255
|
+
language?: EmailCodeLanguage;
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* What IAM accepted for a reset. Neutral like {@link EmailCodeRequestResult}:
|
|
259
|
+
* it says nothing about whether the address has an account.
|
|
260
|
+
*/
|
|
261
|
+
interface PasswordResetRequestResult {
|
|
262
|
+
/** How long to wait before offering to send another message. */
|
|
263
|
+
resendAfterSeconds: number;
|
|
264
|
+
}
|
|
250
265
|
/** The code the person read in the message, against the request that sent it. */
|
|
251
266
|
interface EmailCodeVerification {
|
|
252
267
|
receipt: string;
|
|
@@ -306,7 +321,7 @@ interface AuthModuleOptions {
|
|
|
306
321
|
/**
|
|
307
322
|
* Authentication module for managing user sessions.
|
|
308
323
|
*
|
|
309
|
-
* Handles Google and Microsoft SSO, email sign-in, trusted session adoption, sign-out,
|
|
324
|
+
* Handles Google and Microsoft SSO, email and password sign-in, trusted session adoption, sign-out,
|
|
310
325
|
* and automatic token refresh.
|
|
311
326
|
* Auth state is persisted to localStorage with key `mitra_auth_{appId}`
|
|
312
327
|
* and restored on page reload.
|
|
@@ -334,6 +349,7 @@ declare class AuthModule {
|
|
|
334
349
|
private readonly googleAuth;
|
|
335
350
|
private readonly microsoftAuth;
|
|
336
351
|
private readonly emailAuth;
|
|
352
|
+
private readonly passwordAuth;
|
|
337
353
|
private readonly emailCode;
|
|
338
354
|
private brand;
|
|
339
355
|
constructor(appId: string, iamBaseUrl: string, options?: AuthModuleOptions);
|
|
@@ -359,7 +375,10 @@ declare class AuthModule {
|
|
|
359
375
|
get allTokens(): AllTokens | null;
|
|
360
376
|
/** Whether a user is currently authenticated (local check, not server-validated). */
|
|
361
377
|
get isAuthenticated(): boolean;
|
|
362
|
-
/**
|
|
378
|
+
/**
|
|
379
|
+
* @deprecated The password never goes through the app's code. Use
|
|
380
|
+
* signInWithPassword(), which opens the Mitra auth page, signInWithEmail() or SSO.
|
|
381
|
+
*/
|
|
363
382
|
signIn(_credentials: SignInCredentials): Promise<User>;
|
|
364
383
|
/**
|
|
365
384
|
* Signs in with Google SSO.
|
|
@@ -555,11 +574,106 @@ declare class AuthModule {
|
|
|
555
574
|
* `MAGIC_LINK_INVALID` when the link belongs here but cannot be used.
|
|
556
575
|
*/
|
|
557
576
|
completeEmailSignInRedirect(): Promise<User | null>;
|
|
558
|
-
/**
|
|
577
|
+
/**
|
|
578
|
+
* @deprecated The password never goes through the app's code. Use
|
|
579
|
+
* signUpWithPassword(), which opens the Mitra auth page, signInWithEmail() or SSO.
|
|
580
|
+
*/
|
|
559
581
|
signUp(_data: SignUpData): Promise<User>;
|
|
582
|
+
/**
|
|
583
|
+
* Signs in with email and password, typed into the Mitra auth page in a popup.
|
|
584
|
+
* The password never reaches the app's code: the page sends it to IAM and
|
|
585
|
+
* hands back a single-use exchange code, redeemed like the email sign-in.
|
|
586
|
+
*
|
|
587
|
+
* Offer it only when `mitra.passwordLoginEnabled` is `true`, which needs an
|
|
588
|
+
* app whose accounts are its own (exclusive login mode). Call it straight
|
|
589
|
+
* from the click handler, before any `await`, or the browser blocks the popup.
|
|
590
|
+
*
|
|
591
|
+
* @returns The authenticated and hydrated user.
|
|
592
|
+
* @throws {MitraApiError} When IAM rejects the exchange code.
|
|
593
|
+
* @throws {Error} When the browser blocks or cancels the popup, the flow times
|
|
594
|
+
* out, or the response fails origin, source, state, or shape validation. Wrong
|
|
595
|
+
* credentials are answered on the auth page itself, not here.
|
|
596
|
+
*
|
|
597
|
+
* @example
|
|
598
|
+
* ```typescript
|
|
599
|
+
* const user = await mitra.auth.signInWithPassword();
|
|
600
|
+
* ```
|
|
601
|
+
*/
|
|
602
|
+
signInWithPassword(): Promise<User>;
|
|
603
|
+
/**
|
|
604
|
+
* Creates a password for an app account, on the Mitra auth page in a popup:
|
|
605
|
+
* the page asks for the address, sends a code to it to prove the mailbox is
|
|
606
|
+
* the person's, and takes the password with that code. The person ends signed
|
|
607
|
+
* in, as with {@link signInWithPassword}.
|
|
608
|
+
*
|
|
609
|
+
* @returns The authenticated and hydrated user.
|
|
610
|
+
* @throws The same errors as {@link signInWithPassword}.
|
|
611
|
+
*
|
|
612
|
+
* @example
|
|
613
|
+
* ```typescript
|
|
614
|
+
* const user = await mitra.auth.signUpWithPassword();
|
|
615
|
+
* ```
|
|
616
|
+
*/
|
|
617
|
+
signUpWithPassword(): Promise<User>;
|
|
618
|
+
/**
|
|
619
|
+
* Changes the password of the signed-in person, on the Mitra auth page in a
|
|
620
|
+
* popup. The page asks for the current and the new password itself, so the
|
|
621
|
+
* app never sees either one.
|
|
622
|
+
*
|
|
623
|
+
* The page acts on this session, so it asks for the access token once it
|
|
624
|
+
* loads, and the SDK answers with `postMessage` to the auth page origin only:
|
|
625
|
+
* the token never goes in the popup URL.
|
|
626
|
+
*
|
|
627
|
+
* IAM ends every session of the account when the password changes, this one
|
|
628
|
+
* included, so the page signs in again with the new password and hands back a
|
|
629
|
+
* new session, which replaces the current one.
|
|
630
|
+
*
|
|
631
|
+
* When the change goes through but that new sign-in fails, the call rejects
|
|
632
|
+
* with `PASSWORD_CHANGED_SIGN_IN_AGAIN` and the local session is cleared,
|
|
633
|
+
* since IAM already ended it: send the person to sign in with the new password.
|
|
634
|
+
*
|
|
635
|
+
* @returns The user of the new session.
|
|
636
|
+
* @throws {MitraApiError} `401` when nobody is signed in, and
|
|
637
|
+
* `PASSWORD_CHANGED_SIGN_IN_AGAIN` (status `401`) as above.
|
|
638
|
+
* @throws The same errors as {@link signInWithPassword}, and an error when the
|
|
639
|
+
* session ends while the popup is open.
|
|
640
|
+
*
|
|
641
|
+
* @example
|
|
642
|
+
* ```typescript
|
|
643
|
+
* await mitra.auth.changePassword();
|
|
644
|
+
* ```
|
|
645
|
+
*/
|
|
646
|
+
changePassword(): Promise<User>;
|
|
647
|
+
/**
|
|
648
|
+
* Asks IAM to email a link to set a new password. Only the address goes: the
|
|
649
|
+
* link opens the Mitra auth page, where the new password is typed, so there
|
|
650
|
+
* is no method here to confirm the reset.
|
|
651
|
+
*
|
|
652
|
+
* IAM answers the same whether or not the address has an account, so this
|
|
653
|
+
* resolves without saying which.
|
|
654
|
+
*
|
|
655
|
+
* @param email - The address of the account.
|
|
656
|
+
* @param options - The language of the message.
|
|
657
|
+
* @returns How long the application should wait before offering to resend.
|
|
658
|
+
* @throws {MitraApiError} `RATE_LIMITED` when this address asked too often,
|
|
659
|
+
* and `RATE_LIMIT_EXCEEDED` when this network did, both with
|
|
660
|
+
* `retryAfterSeconds` when IAM sends it.
|
|
661
|
+
*
|
|
662
|
+
* @example
|
|
663
|
+
* ```typescript
|
|
664
|
+
* const { resendAfterSeconds } = await mitra.auth.requestPasswordReset('person@example.com');
|
|
665
|
+
* ```
|
|
666
|
+
*/
|
|
667
|
+
requestPasswordReset(email: string, options?: PasswordResetOptions): Promise<PasswordResetRequestResult>;
|
|
560
668
|
/**
|
|
561
669
|
* Signs out the current user, clearing all auth state and localStorage.
|
|
562
670
|
*
|
|
671
|
+
* In an app whose accounts are its own, the session also ends on the server:
|
|
672
|
+
* the refresh token is sent to IAM's logout, so it can no longer be renewed.
|
|
673
|
+
* The local state is cleared right away whatever IAM answers, and the request
|
|
674
|
+
* survives a navigation to `redirectUrl`. The access token already issued
|
|
675
|
+
* stays valid until it expires.
|
|
676
|
+
*
|
|
563
677
|
* @param redirectUrl - Optional URL to navigate to after sign-out.
|
|
564
678
|
*
|
|
565
679
|
* @example
|
|
@@ -772,6 +886,8 @@ declare class AuthModule {
|
|
|
772
886
|
* ```
|
|
773
887
|
*/
|
|
774
888
|
onAuthStateChange(callback: AuthStateChangeCallback): () => void;
|
|
889
|
+
/** Best effort: the person asked to leave, and that already happened locally. */
|
|
890
|
+
private endServerSession;
|
|
775
891
|
private doRefresh;
|
|
776
892
|
private establishSession;
|
|
777
893
|
private setAuthState;
|
|
@@ -955,8 +1071,9 @@ interface MitraClient {
|
|
|
955
1071
|
/**
|
|
956
1072
|
* Initializes the client by resolving app config from the server.
|
|
957
1073
|
*
|
|
958
|
-
* Fetches the compatibility dataSourceId, allowSignup, emailLoginEnabled,
|
|
959
|
-
* the brand `requestEmailCode()` sends with, from
|
|
1074
|
+
* Fetches the compatibility dataSourceId, allowSignup, emailLoginEnabled,
|
|
1075
|
+
* passwordLoginEnabled, and the brand `requestEmailCode()` sends with, from
|
|
1076
|
+
* the public app info endpoint.
|
|
960
1077
|
*
|
|
961
1078
|
* Safe to call multiple times. Subsequent calls are no-ops.
|
|
962
1079
|
*
|
|
@@ -1049,6 +1166,12 @@ interface MitraClient {
|
|
|
1049
1166
|
* server does not answer the field.
|
|
1050
1167
|
*/
|
|
1051
1168
|
readonly emailLoginEnabled: boolean;
|
|
1169
|
+
/**
|
|
1170
|
+
* Whether this app offers sign-in by email and password, which only an app
|
|
1171
|
+
* whose accounts are its own can. Defaults to `false` before `init()` is
|
|
1172
|
+
* called, and stays `false` when the server does not answer the field.
|
|
1173
|
+
*/
|
|
1174
|
+
readonly passwordLoginEnabled: boolean;
|
|
1052
1175
|
/**
|
|
1053
1176
|
* The configuration used to create this client.
|
|
1054
1177
|
*/
|
|
@@ -1065,7 +1188,7 @@ interface MitraClient {
|
|
|
1065
1188
|
* - **queries**: Custom query management and execution
|
|
1066
1189
|
*
|
|
1067
1190
|
* After creating the client, call `init()` to resolve the app's public config
|
|
1068
|
-
* (dataSourceId, allowSignup, emailLoginEnabled) automatically from the server.
|
|
1191
|
+
* (dataSourceId, allowSignup, emailLoginEnabled, passwordLoginEnabled) automatically from the server.
|
|
1069
1192
|
*
|
|
1070
1193
|
* @param config - Configuration options for the client.
|
|
1071
1194
|
* @returns A configured MitraClient instance.
|
|
@@ -1271,4 +1394,4 @@ type StopServerFunctionExecutionResponse = LegacyTypes.StopServerFunctionExecuti
|
|
|
1271
1394
|
/** @deprecated Legacy compatibility type. */
|
|
1272
1395
|
type UpdateRecordOptions = LegacyTypes.UpdateRecordOptions;
|
|
1273
1396
|
|
|
1274
|
-
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 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 };
|
|
1397
|
+
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 PasswordResetOptions, type PasswordResetRequestResult, 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 };
|