@mitralab.io/platform-sdk 1.8.0-beta.0 → 1.8.0-beta.1
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 +36 -0
- package/README.md +44 -5
- package/dist/index.cjs +369 -26
- package/dist/index.d.cts +218 -8
- package/dist/index.d.ts +218 -8
- package/dist/index.js +369 -26
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -262,6 +262,34 @@ interface PasswordResetRequestResult {
|
|
|
262
262
|
/** How long to wait before offering to send another message. */
|
|
263
263
|
resendAfterSeconds: number;
|
|
264
264
|
}
|
|
265
|
+
/** The address to create a password for, and the language of the message with the code. */
|
|
266
|
+
type PasswordSignUpRequest = EmailCodeRequest;
|
|
267
|
+
/** What IAM accepted for a password sign-up, as neutral as {@link EmailCodeRequestResult}. */
|
|
268
|
+
type PasswordSignUpRequestResult = EmailCodeRequestResult;
|
|
269
|
+
/** The code the person read in the message, and the password they chose. */
|
|
270
|
+
interface PasswordSignUpCompletion {
|
|
271
|
+
/** From `auth.startPasswordSignUp()`. */
|
|
272
|
+
receipt: string;
|
|
273
|
+
/** The six digits sent to the address. */
|
|
274
|
+
code: string;
|
|
275
|
+
password: string;
|
|
276
|
+
}
|
|
277
|
+
/** The password to replace, and the new one. */
|
|
278
|
+
interface PasswordChange {
|
|
279
|
+
/**
|
|
280
|
+
* Required by IAM whenever the account already has a password. Only an
|
|
281
|
+
* account that never had one, such as one born from the email code, goes
|
|
282
|
+
* without it.
|
|
283
|
+
*/
|
|
284
|
+
currentPassword?: string;
|
|
285
|
+
newPassword: string;
|
|
286
|
+
}
|
|
287
|
+
/** The token from the reset link, and the new password. */
|
|
288
|
+
interface PasswordResetConfirmation {
|
|
289
|
+
/** From `auth.readPasswordResetToken()`. */
|
|
290
|
+
token: string;
|
|
291
|
+
newPassword: string;
|
|
292
|
+
}
|
|
265
293
|
/** The code the person read in the message, against the request that sent it. */
|
|
266
294
|
interface EmailCodeVerification {
|
|
267
295
|
receipt: string;
|
|
@@ -351,6 +379,7 @@ declare class AuthModule {
|
|
|
351
379
|
private readonly emailAuth;
|
|
352
380
|
private readonly passwordAuth;
|
|
353
381
|
private readonly emailCode;
|
|
382
|
+
private readonly passwordForm;
|
|
354
383
|
private brand;
|
|
355
384
|
constructor(appId: string, iamBaseUrl: string, options?: AuthModuleOptions);
|
|
356
385
|
/** The currently authenticated user, or null. */
|
|
@@ -376,8 +405,8 @@ declare class AuthModule {
|
|
|
376
405
|
/** Whether a user is currently authenticated (local check, not server-validated). */
|
|
377
406
|
get isAuthenticated(): boolean;
|
|
378
407
|
/**
|
|
379
|
-
* @deprecated
|
|
380
|
-
*
|
|
408
|
+
* @deprecated Use signInWithPassword(), which opens the Mitra auth page,
|
|
409
|
+
* signInWithPasswordForm() in an app with the form mode on, signInWithEmail() or SSO.
|
|
381
410
|
*/
|
|
382
411
|
signIn(_credentials: SignInCredentials): Promise<User>;
|
|
383
412
|
/**
|
|
@@ -575,8 +604,8 @@ declare class AuthModule {
|
|
|
575
604
|
*/
|
|
576
605
|
completeEmailSignInRedirect(): Promise<User | null>;
|
|
577
606
|
/**
|
|
578
|
-
* @deprecated
|
|
579
|
-
*
|
|
607
|
+
* @deprecated Use signUpWithPassword(), which opens the Mitra auth page,
|
|
608
|
+
* startPasswordSignUp() in an app with the form mode on, signInWithEmail() or SSO.
|
|
580
609
|
*/
|
|
581
610
|
signUp(_data: SignUpData): Promise<User>;
|
|
582
611
|
/**
|
|
@@ -645,9 +674,12 @@ declare class AuthModule {
|
|
|
645
674
|
*/
|
|
646
675
|
changePassword(): Promise<User>;
|
|
647
676
|
/**
|
|
648
|
-
* Asks IAM to email a link to set a new password. Only the address goes
|
|
649
|
-
* link opens the
|
|
650
|
-
*
|
|
677
|
+
* Asks IAM to email a link to set a new password. Only the address goes.
|
|
678
|
+
* Where the link opens depends on the app's mode of the password login: with
|
|
679
|
+
* the Mitra auth page, the default, the new password is typed there; with the
|
|
680
|
+
* form in the app itself, the link opens `/reset-password` on this app's
|
|
681
|
+
* origin, which reads it with {@link readPasswordResetToken} and finishes
|
|
682
|
+
* with {@link confirmPasswordReset}.
|
|
651
683
|
*
|
|
652
684
|
* IAM answers the same whether or not the address has an account, so this
|
|
653
685
|
* resolves without saying which.
|
|
@@ -665,6 +697,184 @@ declare class AuthModule {
|
|
|
665
697
|
* ```
|
|
666
698
|
*/
|
|
667
699
|
requestPasswordReset(email: string, options?: PasswordResetOptions): Promise<PasswordResetRequestResult>;
|
|
700
|
+
/**
|
|
701
|
+
* The password goes through the app's code. Do not store it, do not log it
|
|
702
|
+
* and do not send it anywhere other than this method. The safer default is
|
|
703
|
+
* signInWithPassword(), which uses the Mitra auth page.
|
|
704
|
+
*
|
|
705
|
+
* Works only when the app has the "form in the app itself" mode of the
|
|
706
|
+
* password login turned on. Otherwise IAM refuses it with
|
|
707
|
+
* `PASSWORD_FORM_NOT_ENABLED` (status `403`). Browser only.
|
|
708
|
+
*
|
|
709
|
+
* Signs in with the address and password typed into the app's own form.
|
|
710
|
+
*
|
|
711
|
+
* @returns The authenticated and hydrated user.
|
|
712
|
+
* @throws {MitraApiError} `INVALID_CREDENTIALS` (status `401`) for a wrong
|
|
713
|
+
* address or password, a locked account or one without a password, all
|
|
714
|
+
* answered alike, `SIGNUP_NOT_ALLOWED` (status `403`) when the account lost
|
|
715
|
+
* its access to an app that takes no new accounts, `RATE_LIMIT_EXCEEDED`
|
|
716
|
+
* (status `429`, with `retryAfterSeconds` when IAM sends it) when this
|
|
717
|
+
* network called the password routes too often or IAM is at its limit of
|
|
718
|
+
* passwords being hashed, so wait `retryAfterSeconds`, and
|
|
719
|
+
* `PASSWORD_FORM_NOT_ENABLED` as above.
|
|
720
|
+
*
|
|
721
|
+
* @example
|
|
722
|
+
* ```typescript
|
|
723
|
+
* const user = await mitra.auth.signInWithPasswordForm({ email, password });
|
|
724
|
+
* ```
|
|
725
|
+
*/
|
|
726
|
+
signInWithPasswordForm(credentials: SignInCredentials): Promise<User>;
|
|
727
|
+
/**
|
|
728
|
+
* The password goes through the app's code. Do not store it, do not log it
|
|
729
|
+
* and do not send it anywhere other than this method. The safer default is
|
|
730
|
+
* signInWithPassword(), which uses the Mitra auth page.
|
|
731
|
+
*
|
|
732
|
+
* First step of creating a password from the app's own form: IAM emails a
|
|
733
|
+
* six-digit code to the address, to prove the mailbox is the person's. No
|
|
734
|
+
* password goes in this step, which IAM takes in either mode of the app; the
|
|
735
|
+
* "form in the app itself" mode is required at {@link completePasswordSignUp},
|
|
736
|
+
* where the password goes. Browser only.
|
|
737
|
+
*
|
|
738
|
+
* IAM answers the same whether or not the address has an account, so this
|
|
739
|
+
* resolves without saying which.
|
|
740
|
+
*
|
|
741
|
+
* @param request - The address, and the language of the message.
|
|
742
|
+
* @returns The receipt that names this request, and the resend delay.
|
|
743
|
+
* @throws {MitraApiError} `RATE_LIMITED` (with `retryAfterSeconds`) when this
|
|
744
|
+
* address asked too often, and `RATE_LIMIT_EXCEEDED` (status `429`, with
|
|
745
|
+
* `retryAfterSeconds` when IAM sends it) when this network called the
|
|
746
|
+
* password routes too often.
|
|
747
|
+
*
|
|
748
|
+
* @example
|
|
749
|
+
* ```typescript
|
|
750
|
+
* const { receipt, resendAfterSeconds } = await mitra.auth.startPasswordSignUp({ email });
|
|
751
|
+
* ```
|
|
752
|
+
*/
|
|
753
|
+
startPasswordSignUp(request: PasswordSignUpRequest): Promise<PasswordSignUpRequestResult>;
|
|
754
|
+
/**
|
|
755
|
+
* The password goes through the app's code. Do not store it, do not log it
|
|
756
|
+
* and do not send it anywhere other than this method. The safer default is
|
|
757
|
+
* signInWithPassword(), which uses the Mitra auth page.
|
|
758
|
+
*
|
|
759
|
+
* Works only when the app has the "form in the app itself" mode of the
|
|
760
|
+
* password login turned on. Otherwise IAM refuses it with
|
|
761
|
+
* `PASSWORD_FORM_NOT_ENABLED` (status `403`). Browser only.
|
|
762
|
+
*
|
|
763
|
+
* Second step of {@link startPasswordSignUp}: the code from the message and
|
|
764
|
+
* the chosen password. The person ends signed in, as with
|
|
765
|
+
* {@link signInWithPasswordForm}.
|
|
766
|
+
*
|
|
767
|
+
* @param completion - The receipt, the code and the password.
|
|
768
|
+
* @returns The authenticated and hydrated user.
|
|
769
|
+
* @throws {MitraApiError} `INVALID_CODE` when the code does not match or the
|
|
770
|
+
* request expired, `MAGIC_LINK_USED` when it was already completed,
|
|
771
|
+
* `PASSWORD_ALREADY_SET` when the account has a password (the way to replace
|
|
772
|
+
* it is the reset), `SSO_ACCOUNT` (status `409`) when the account signs in
|
|
773
|
+
* with Google or Microsoft, `SIGNUP_NOT_ALLOWED` when the app takes no new
|
|
774
|
+
* accounts, `WEAK_PASSWORD` (status `400`) with the rule the password broke,
|
|
775
|
+
* `RATE_LIMIT_EXCEEDED` (status `429`, with `retryAfterSeconds` when IAM
|
|
776
|
+
* sends it) when this network called the password routes too often or IAM is
|
|
777
|
+
* at its limit of passwords being hashed, so wait `retryAfterSeconds`, and
|
|
778
|
+
* `PASSWORD_FORM_NOT_ENABLED` as above.
|
|
779
|
+
*
|
|
780
|
+
* @example
|
|
781
|
+
* ```typescript
|
|
782
|
+
* const user = await mitra.auth.completePasswordSignUp({ receipt, code, password });
|
|
783
|
+
* ```
|
|
784
|
+
*/
|
|
785
|
+
completePasswordSignUp(completion: PasswordSignUpCompletion): Promise<User>;
|
|
786
|
+
/**
|
|
787
|
+
* The password goes through the app's code. Do not store it, do not log it
|
|
788
|
+
* and do not send it anywhere other than this method. The safer default is
|
|
789
|
+
* signInWithPassword(), which uses the Mitra auth page.
|
|
790
|
+
*
|
|
791
|
+
* Works only when the app has the "form in the app itself" mode of the
|
|
792
|
+
* password login turned on. Otherwise IAM refuses it with
|
|
793
|
+
* `PASSWORD_FORM_NOT_ENABLED` (status `403`). Browser only.
|
|
794
|
+
*
|
|
795
|
+
* Changes the password of the signed-in person from the app's own form. IAM
|
|
796
|
+
* ends every session of the account when the password changes, this one
|
|
797
|
+
* included, so the SDK signs in again with the address of this session and
|
|
798
|
+
* the new password, and that session replaces the current one.
|
|
799
|
+
*
|
|
800
|
+
* When the change goes through but that new sign-in fails, the call rejects
|
|
801
|
+
* with `PASSWORD_CHANGED_SIGN_IN_AGAIN` and the local session is cleared,
|
|
802
|
+
* since IAM already ended it: send the person to sign in with the new password.
|
|
803
|
+
*
|
|
804
|
+
* @param change - The current password, required whenever the account
|
|
805
|
+
* already has one, and the new one.
|
|
806
|
+
* @returns The user of the new session.
|
|
807
|
+
* @throws {MitraApiError} `401` when nobody is signed in,
|
|
808
|
+
* `PASSWORD_CHANGED_SIGN_IN_AGAIN` (status `401`) as above,
|
|
809
|
+
* `INVALID_CREDENTIALS` (status `401`) for a wrong current password,
|
|
810
|
+
* `CURRENT_PASSWORD_REQUIRED` and `WEAK_PASSWORD` (status `400`),
|
|
811
|
+
* `SSO_ACCOUNT` (status `409`) when the account signs in with Google or
|
|
812
|
+
* Microsoft, `RATE_LIMIT_EXCEEDED` (status `429`, with `retryAfterSeconds`
|
|
813
|
+
* when IAM sends it) when this network called the password routes too often
|
|
814
|
+
* or IAM is at its limit of passwords being hashed, so wait
|
|
815
|
+
* `retryAfterSeconds`, and `PASSWORD_FORM_NOT_ENABLED` as above.
|
|
816
|
+
*
|
|
817
|
+
* @example
|
|
818
|
+
* ```typescript
|
|
819
|
+
* await mitra.auth.changePasswordForm({ currentPassword, newPassword });
|
|
820
|
+
* ```
|
|
821
|
+
*/
|
|
822
|
+
changePasswordForm(change: PasswordChange): Promise<User>;
|
|
823
|
+
/**
|
|
824
|
+
* The password goes through the app's code. Do not store it, do not log it
|
|
825
|
+
* and do not send it anywhere other than this method. The safer default is
|
|
826
|
+
* signInWithPassword(), which uses the Mitra auth page.
|
|
827
|
+
*
|
|
828
|
+
* The reset token is single use and works as a credential until it is spent:
|
|
829
|
+
* do not log it either.
|
|
830
|
+
*
|
|
831
|
+
* Reads the token of a password reset link that landed on this app, and
|
|
832
|
+
* removes the fragment from the URL so the token does not stay in the
|
|
833
|
+
* history. With the form in the app itself turned on, IAM sends the link to
|
|
834
|
+
* `/reset-password#resetToken=...` on the origin the reset was asked from:
|
|
835
|
+
* call this when that route loads, then {@link confirmPasswordReset}.
|
|
836
|
+
*
|
|
837
|
+
* Nothing is sent to IAM here, and a URL without the link is left as it is.
|
|
838
|
+
* Browser only.
|
|
839
|
+
*
|
|
840
|
+
* @returns The token, or `null` when the URL carries none.
|
|
841
|
+
*
|
|
842
|
+
* @example
|
|
843
|
+
* ```typescript
|
|
844
|
+
* const token = mitra.auth.readPasswordResetToken();
|
|
845
|
+
* ```
|
|
846
|
+
*/
|
|
847
|
+
readPasswordResetToken(): string | null;
|
|
848
|
+
/**
|
|
849
|
+
* The password goes through the app's code. Do not store it, do not log it
|
|
850
|
+
* and do not send it anywhere other than this method. The safer default is
|
|
851
|
+
* signInWithPassword(), which uses the Mitra auth page.
|
|
852
|
+
*
|
|
853
|
+
* Works only when the app has the "form in the app itself" mode of the
|
|
854
|
+
* password login turned on. Otherwise IAM refuses it with
|
|
855
|
+
* `PASSWORD_FORM_NOT_ENABLED` (status `403`). Browser only.
|
|
856
|
+
*
|
|
857
|
+
* Sets the new password with the token from the reset link. The link is
|
|
858
|
+
* single use, and IAM ends every session of the account, so the person signs
|
|
859
|
+
* in afterwards with the new password; this method signs nobody in.
|
|
860
|
+
*
|
|
861
|
+
* @param confirmation - The token from {@link readPasswordResetToken} and the
|
|
862
|
+
* new password.
|
|
863
|
+
* @throws {MitraApiError} `RESET_TOKEN_USED` or `RESET_TOKEN_EXPIRED` (status
|
|
864
|
+
* `409`) when the link can no longer be used; a token IAM does not know also
|
|
865
|
+
* answers `RESET_TOKEN_EXPIRED`. Also `WEAK_PASSWORD` (status `400`),
|
|
866
|
+
* `SSO_ACCOUNT` (status `409`) when the account signs in with Google or
|
|
867
|
+
* Microsoft, `RATE_LIMIT_EXCEEDED` (status `429`, with `retryAfterSeconds`
|
|
868
|
+
* when IAM sends it) when this network called the password routes too often
|
|
869
|
+
* or IAM is at its limit of passwords being hashed, so wait
|
|
870
|
+
* `retryAfterSeconds`, and `PASSWORD_FORM_NOT_ENABLED` as above.
|
|
871
|
+
*
|
|
872
|
+
* @example
|
|
873
|
+
* ```typescript
|
|
874
|
+
* await mitra.auth.confirmPasswordReset({ token, newPassword });
|
|
875
|
+
* ```
|
|
876
|
+
*/
|
|
877
|
+
confirmPasswordReset(confirmation: PasswordResetConfirmation): Promise<void>;
|
|
668
878
|
/**
|
|
669
879
|
* Signs out the current user, clearing all auth state and localStorage.
|
|
670
880
|
*
|
|
@@ -1394,4 +1604,4 @@ type StopServerFunctionExecutionResponse = LegacyTypes.StopServerFunctionExecuti
|
|
|
1394
1604
|
/** @deprecated Legacy compatibility type. */
|
|
1395
1605
|
type UpdateRecordOptions = LegacyTypes.UpdateRecordOptions;
|
|
1396
1606
|
|
|
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 };
|
|
1607
|
+
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 };
|
package/dist/index.d.ts
CHANGED
|
@@ -262,6 +262,34 @@ interface PasswordResetRequestResult {
|
|
|
262
262
|
/** How long to wait before offering to send another message. */
|
|
263
263
|
resendAfterSeconds: number;
|
|
264
264
|
}
|
|
265
|
+
/** The address to create a password for, and the language of the message with the code. */
|
|
266
|
+
type PasswordSignUpRequest = EmailCodeRequest;
|
|
267
|
+
/** What IAM accepted for a password sign-up, as neutral as {@link EmailCodeRequestResult}. */
|
|
268
|
+
type PasswordSignUpRequestResult = EmailCodeRequestResult;
|
|
269
|
+
/** The code the person read in the message, and the password they chose. */
|
|
270
|
+
interface PasswordSignUpCompletion {
|
|
271
|
+
/** From `auth.startPasswordSignUp()`. */
|
|
272
|
+
receipt: string;
|
|
273
|
+
/** The six digits sent to the address. */
|
|
274
|
+
code: string;
|
|
275
|
+
password: string;
|
|
276
|
+
}
|
|
277
|
+
/** The password to replace, and the new one. */
|
|
278
|
+
interface PasswordChange {
|
|
279
|
+
/**
|
|
280
|
+
* Required by IAM whenever the account already has a password. Only an
|
|
281
|
+
* account that never had one, such as one born from the email code, goes
|
|
282
|
+
* without it.
|
|
283
|
+
*/
|
|
284
|
+
currentPassword?: string;
|
|
285
|
+
newPassword: string;
|
|
286
|
+
}
|
|
287
|
+
/** The token from the reset link, and the new password. */
|
|
288
|
+
interface PasswordResetConfirmation {
|
|
289
|
+
/** From `auth.readPasswordResetToken()`. */
|
|
290
|
+
token: string;
|
|
291
|
+
newPassword: string;
|
|
292
|
+
}
|
|
265
293
|
/** The code the person read in the message, against the request that sent it. */
|
|
266
294
|
interface EmailCodeVerification {
|
|
267
295
|
receipt: string;
|
|
@@ -351,6 +379,7 @@ declare class AuthModule {
|
|
|
351
379
|
private readonly emailAuth;
|
|
352
380
|
private readonly passwordAuth;
|
|
353
381
|
private readonly emailCode;
|
|
382
|
+
private readonly passwordForm;
|
|
354
383
|
private brand;
|
|
355
384
|
constructor(appId: string, iamBaseUrl: string, options?: AuthModuleOptions);
|
|
356
385
|
/** The currently authenticated user, or null. */
|
|
@@ -376,8 +405,8 @@ declare class AuthModule {
|
|
|
376
405
|
/** Whether a user is currently authenticated (local check, not server-validated). */
|
|
377
406
|
get isAuthenticated(): boolean;
|
|
378
407
|
/**
|
|
379
|
-
* @deprecated
|
|
380
|
-
*
|
|
408
|
+
* @deprecated Use signInWithPassword(), which opens the Mitra auth page,
|
|
409
|
+
* signInWithPasswordForm() in an app with the form mode on, signInWithEmail() or SSO.
|
|
381
410
|
*/
|
|
382
411
|
signIn(_credentials: SignInCredentials): Promise<User>;
|
|
383
412
|
/**
|
|
@@ -575,8 +604,8 @@ declare class AuthModule {
|
|
|
575
604
|
*/
|
|
576
605
|
completeEmailSignInRedirect(): Promise<User | null>;
|
|
577
606
|
/**
|
|
578
|
-
* @deprecated
|
|
579
|
-
*
|
|
607
|
+
* @deprecated Use signUpWithPassword(), which opens the Mitra auth page,
|
|
608
|
+
* startPasswordSignUp() in an app with the form mode on, signInWithEmail() or SSO.
|
|
580
609
|
*/
|
|
581
610
|
signUp(_data: SignUpData): Promise<User>;
|
|
582
611
|
/**
|
|
@@ -645,9 +674,12 @@ declare class AuthModule {
|
|
|
645
674
|
*/
|
|
646
675
|
changePassword(): Promise<User>;
|
|
647
676
|
/**
|
|
648
|
-
* Asks IAM to email a link to set a new password. Only the address goes
|
|
649
|
-
* link opens the
|
|
650
|
-
*
|
|
677
|
+
* Asks IAM to email a link to set a new password. Only the address goes.
|
|
678
|
+
* Where the link opens depends on the app's mode of the password login: with
|
|
679
|
+
* the Mitra auth page, the default, the new password is typed there; with the
|
|
680
|
+
* form in the app itself, the link opens `/reset-password` on this app's
|
|
681
|
+
* origin, which reads it with {@link readPasswordResetToken} and finishes
|
|
682
|
+
* with {@link confirmPasswordReset}.
|
|
651
683
|
*
|
|
652
684
|
* IAM answers the same whether or not the address has an account, so this
|
|
653
685
|
* resolves without saying which.
|
|
@@ -665,6 +697,184 @@ declare class AuthModule {
|
|
|
665
697
|
* ```
|
|
666
698
|
*/
|
|
667
699
|
requestPasswordReset(email: string, options?: PasswordResetOptions): Promise<PasswordResetRequestResult>;
|
|
700
|
+
/**
|
|
701
|
+
* The password goes through the app's code. Do not store it, do not log it
|
|
702
|
+
* and do not send it anywhere other than this method. The safer default is
|
|
703
|
+
* signInWithPassword(), which uses the Mitra auth page.
|
|
704
|
+
*
|
|
705
|
+
* Works only when the app has the "form in the app itself" mode of the
|
|
706
|
+
* password login turned on. Otherwise IAM refuses it with
|
|
707
|
+
* `PASSWORD_FORM_NOT_ENABLED` (status `403`). Browser only.
|
|
708
|
+
*
|
|
709
|
+
* Signs in with the address and password typed into the app's own form.
|
|
710
|
+
*
|
|
711
|
+
* @returns The authenticated and hydrated user.
|
|
712
|
+
* @throws {MitraApiError} `INVALID_CREDENTIALS` (status `401`) for a wrong
|
|
713
|
+
* address or password, a locked account or one without a password, all
|
|
714
|
+
* answered alike, `SIGNUP_NOT_ALLOWED` (status `403`) when the account lost
|
|
715
|
+
* its access to an app that takes no new accounts, `RATE_LIMIT_EXCEEDED`
|
|
716
|
+
* (status `429`, with `retryAfterSeconds` when IAM sends it) when this
|
|
717
|
+
* network called the password routes too often or IAM is at its limit of
|
|
718
|
+
* passwords being hashed, so wait `retryAfterSeconds`, and
|
|
719
|
+
* `PASSWORD_FORM_NOT_ENABLED` as above.
|
|
720
|
+
*
|
|
721
|
+
* @example
|
|
722
|
+
* ```typescript
|
|
723
|
+
* const user = await mitra.auth.signInWithPasswordForm({ email, password });
|
|
724
|
+
* ```
|
|
725
|
+
*/
|
|
726
|
+
signInWithPasswordForm(credentials: SignInCredentials): Promise<User>;
|
|
727
|
+
/**
|
|
728
|
+
* The password goes through the app's code. Do not store it, do not log it
|
|
729
|
+
* and do not send it anywhere other than this method. The safer default is
|
|
730
|
+
* signInWithPassword(), which uses the Mitra auth page.
|
|
731
|
+
*
|
|
732
|
+
* First step of creating a password from the app's own form: IAM emails a
|
|
733
|
+
* six-digit code to the address, to prove the mailbox is the person's. No
|
|
734
|
+
* password goes in this step, which IAM takes in either mode of the app; the
|
|
735
|
+
* "form in the app itself" mode is required at {@link completePasswordSignUp},
|
|
736
|
+
* where the password goes. Browser only.
|
|
737
|
+
*
|
|
738
|
+
* IAM answers the same whether or not the address has an account, so this
|
|
739
|
+
* resolves without saying which.
|
|
740
|
+
*
|
|
741
|
+
* @param request - The address, and the language of the message.
|
|
742
|
+
* @returns The receipt that names this request, and the resend delay.
|
|
743
|
+
* @throws {MitraApiError} `RATE_LIMITED` (with `retryAfterSeconds`) when this
|
|
744
|
+
* address asked too often, and `RATE_LIMIT_EXCEEDED` (status `429`, with
|
|
745
|
+
* `retryAfterSeconds` when IAM sends it) when this network called the
|
|
746
|
+
* password routes too often.
|
|
747
|
+
*
|
|
748
|
+
* @example
|
|
749
|
+
* ```typescript
|
|
750
|
+
* const { receipt, resendAfterSeconds } = await mitra.auth.startPasswordSignUp({ email });
|
|
751
|
+
* ```
|
|
752
|
+
*/
|
|
753
|
+
startPasswordSignUp(request: PasswordSignUpRequest): Promise<PasswordSignUpRequestResult>;
|
|
754
|
+
/**
|
|
755
|
+
* The password goes through the app's code. Do not store it, do not log it
|
|
756
|
+
* and do not send it anywhere other than this method. The safer default is
|
|
757
|
+
* signInWithPassword(), which uses the Mitra auth page.
|
|
758
|
+
*
|
|
759
|
+
* Works only when the app has the "form in the app itself" mode of the
|
|
760
|
+
* password login turned on. Otherwise IAM refuses it with
|
|
761
|
+
* `PASSWORD_FORM_NOT_ENABLED` (status `403`). Browser only.
|
|
762
|
+
*
|
|
763
|
+
* Second step of {@link startPasswordSignUp}: the code from the message and
|
|
764
|
+
* the chosen password. The person ends signed in, as with
|
|
765
|
+
* {@link signInWithPasswordForm}.
|
|
766
|
+
*
|
|
767
|
+
* @param completion - The receipt, the code and the password.
|
|
768
|
+
* @returns The authenticated and hydrated user.
|
|
769
|
+
* @throws {MitraApiError} `INVALID_CODE` when the code does not match or the
|
|
770
|
+
* request expired, `MAGIC_LINK_USED` when it was already completed,
|
|
771
|
+
* `PASSWORD_ALREADY_SET` when the account has a password (the way to replace
|
|
772
|
+
* it is the reset), `SSO_ACCOUNT` (status `409`) when the account signs in
|
|
773
|
+
* with Google or Microsoft, `SIGNUP_NOT_ALLOWED` when the app takes no new
|
|
774
|
+
* accounts, `WEAK_PASSWORD` (status `400`) with the rule the password broke,
|
|
775
|
+
* `RATE_LIMIT_EXCEEDED` (status `429`, with `retryAfterSeconds` when IAM
|
|
776
|
+
* sends it) when this network called the password routes too often or IAM is
|
|
777
|
+
* at its limit of passwords being hashed, so wait `retryAfterSeconds`, and
|
|
778
|
+
* `PASSWORD_FORM_NOT_ENABLED` as above.
|
|
779
|
+
*
|
|
780
|
+
* @example
|
|
781
|
+
* ```typescript
|
|
782
|
+
* const user = await mitra.auth.completePasswordSignUp({ receipt, code, password });
|
|
783
|
+
* ```
|
|
784
|
+
*/
|
|
785
|
+
completePasswordSignUp(completion: PasswordSignUpCompletion): Promise<User>;
|
|
786
|
+
/**
|
|
787
|
+
* The password goes through the app's code. Do not store it, do not log it
|
|
788
|
+
* and do not send it anywhere other than this method. The safer default is
|
|
789
|
+
* signInWithPassword(), which uses the Mitra auth page.
|
|
790
|
+
*
|
|
791
|
+
* Works only when the app has the "form in the app itself" mode of the
|
|
792
|
+
* password login turned on. Otherwise IAM refuses it with
|
|
793
|
+
* `PASSWORD_FORM_NOT_ENABLED` (status `403`). Browser only.
|
|
794
|
+
*
|
|
795
|
+
* Changes the password of the signed-in person from the app's own form. IAM
|
|
796
|
+
* ends every session of the account when the password changes, this one
|
|
797
|
+
* included, so the SDK signs in again with the address of this session and
|
|
798
|
+
* the new password, and that session replaces the current one.
|
|
799
|
+
*
|
|
800
|
+
* When the change goes through but that new sign-in fails, the call rejects
|
|
801
|
+
* with `PASSWORD_CHANGED_SIGN_IN_AGAIN` and the local session is cleared,
|
|
802
|
+
* since IAM already ended it: send the person to sign in with the new password.
|
|
803
|
+
*
|
|
804
|
+
* @param change - The current password, required whenever the account
|
|
805
|
+
* already has one, and the new one.
|
|
806
|
+
* @returns The user of the new session.
|
|
807
|
+
* @throws {MitraApiError} `401` when nobody is signed in,
|
|
808
|
+
* `PASSWORD_CHANGED_SIGN_IN_AGAIN` (status `401`) as above,
|
|
809
|
+
* `INVALID_CREDENTIALS` (status `401`) for a wrong current password,
|
|
810
|
+
* `CURRENT_PASSWORD_REQUIRED` and `WEAK_PASSWORD` (status `400`),
|
|
811
|
+
* `SSO_ACCOUNT` (status `409`) when the account signs in with Google or
|
|
812
|
+
* Microsoft, `RATE_LIMIT_EXCEEDED` (status `429`, with `retryAfterSeconds`
|
|
813
|
+
* when IAM sends it) when this network called the password routes too often
|
|
814
|
+
* or IAM is at its limit of passwords being hashed, so wait
|
|
815
|
+
* `retryAfterSeconds`, and `PASSWORD_FORM_NOT_ENABLED` as above.
|
|
816
|
+
*
|
|
817
|
+
* @example
|
|
818
|
+
* ```typescript
|
|
819
|
+
* await mitra.auth.changePasswordForm({ currentPassword, newPassword });
|
|
820
|
+
* ```
|
|
821
|
+
*/
|
|
822
|
+
changePasswordForm(change: PasswordChange): Promise<User>;
|
|
823
|
+
/**
|
|
824
|
+
* The password goes through the app's code. Do not store it, do not log it
|
|
825
|
+
* and do not send it anywhere other than this method. The safer default is
|
|
826
|
+
* signInWithPassword(), which uses the Mitra auth page.
|
|
827
|
+
*
|
|
828
|
+
* The reset token is single use and works as a credential until it is spent:
|
|
829
|
+
* do not log it either.
|
|
830
|
+
*
|
|
831
|
+
* Reads the token of a password reset link that landed on this app, and
|
|
832
|
+
* removes the fragment from the URL so the token does not stay in the
|
|
833
|
+
* history. With the form in the app itself turned on, IAM sends the link to
|
|
834
|
+
* `/reset-password#resetToken=...` on the origin the reset was asked from:
|
|
835
|
+
* call this when that route loads, then {@link confirmPasswordReset}.
|
|
836
|
+
*
|
|
837
|
+
* Nothing is sent to IAM here, and a URL without the link is left as it is.
|
|
838
|
+
* Browser only.
|
|
839
|
+
*
|
|
840
|
+
* @returns The token, or `null` when the URL carries none.
|
|
841
|
+
*
|
|
842
|
+
* @example
|
|
843
|
+
* ```typescript
|
|
844
|
+
* const token = mitra.auth.readPasswordResetToken();
|
|
845
|
+
* ```
|
|
846
|
+
*/
|
|
847
|
+
readPasswordResetToken(): string | null;
|
|
848
|
+
/**
|
|
849
|
+
* The password goes through the app's code. Do not store it, do not log it
|
|
850
|
+
* and do not send it anywhere other than this method. The safer default is
|
|
851
|
+
* signInWithPassword(), which uses the Mitra auth page.
|
|
852
|
+
*
|
|
853
|
+
* Works only when the app has the "form in the app itself" mode of the
|
|
854
|
+
* password login turned on. Otherwise IAM refuses it with
|
|
855
|
+
* `PASSWORD_FORM_NOT_ENABLED` (status `403`). Browser only.
|
|
856
|
+
*
|
|
857
|
+
* Sets the new password with the token from the reset link. The link is
|
|
858
|
+
* single use, and IAM ends every session of the account, so the person signs
|
|
859
|
+
* in afterwards with the new password; this method signs nobody in.
|
|
860
|
+
*
|
|
861
|
+
* @param confirmation - The token from {@link readPasswordResetToken} and the
|
|
862
|
+
* new password.
|
|
863
|
+
* @throws {MitraApiError} `RESET_TOKEN_USED` or `RESET_TOKEN_EXPIRED` (status
|
|
864
|
+
* `409`) when the link can no longer be used; a token IAM does not know also
|
|
865
|
+
* answers `RESET_TOKEN_EXPIRED`. Also `WEAK_PASSWORD` (status `400`),
|
|
866
|
+
* `SSO_ACCOUNT` (status `409`) when the account signs in with Google or
|
|
867
|
+
* Microsoft, `RATE_LIMIT_EXCEEDED` (status `429`, with `retryAfterSeconds`
|
|
868
|
+
* when IAM sends it) when this network called the password routes too often
|
|
869
|
+
* or IAM is at its limit of passwords being hashed, so wait
|
|
870
|
+
* `retryAfterSeconds`, and `PASSWORD_FORM_NOT_ENABLED` as above.
|
|
871
|
+
*
|
|
872
|
+
* @example
|
|
873
|
+
* ```typescript
|
|
874
|
+
* await mitra.auth.confirmPasswordReset({ token, newPassword });
|
|
875
|
+
* ```
|
|
876
|
+
*/
|
|
877
|
+
confirmPasswordReset(confirmation: PasswordResetConfirmation): Promise<void>;
|
|
668
878
|
/**
|
|
669
879
|
* Signs out the current user, clearing all auth state and localStorage.
|
|
670
880
|
*
|
|
@@ -1394,4 +1604,4 @@ type StopServerFunctionExecutionResponse = LegacyTypes.StopServerFunctionExecuti
|
|
|
1394
1604
|
/** @deprecated Legacy compatibility type. */
|
|
1395
1605
|
type UpdateRecordOptions = LegacyTypes.UpdateRecordOptions;
|
|
1396
1606
|
|
|
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 };
|
|
1607
|
+
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 };
|