@metamask-previews/profile-sync-controller 32.2.0-preview-fb486948f → 32.2.0-preview-aecbce4ff
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 +7 -0
- package/README.md +5 -1
- package/dist/controllers/authentication/AuthenticationController.d.ts.map +1 -1
- package/dist/controllers/authentication/AuthenticationController.js +4 -0
- package/dist/controllers/authentication/AuthenticationController.js.map +1 -1
- package/dist/sdk/authentication-jwt-bearer/flow-srp.d.ts +3 -0
- package/dist/sdk/authentication-jwt-bearer/flow-srp.d.ts.map +1 -1
- package/dist/sdk/authentication-jwt-bearer/flow-srp.js +3 -1
- package/dist/sdk/authentication-jwt-bearer/flow-srp.js.map +1 -1
- package/dist/sdk/authentication-jwt-bearer/mfa/schemas.d.ts +2 -0
- package/dist/sdk/authentication-jwt-bearer/mfa/schemas.d.ts.map +1 -1
- package/dist/sdk/authentication-jwt-bearer/mfa/schemas.js +1 -0
- package/dist/sdk/authentication-jwt-bearer/mfa/schemas.js.map +1 -1
- package/dist/sdk/authentication-jwt-bearer/mfa/services.d.ts.map +1 -1
- package/dist/sdk/authentication-jwt-bearer/mfa/services.js +16 -11
- package/dist/sdk/authentication-jwt-bearer/mfa/services.js.map +1 -1
- package/dist/sdk/authentication-jwt-bearer/mfa/types.d.ts +1 -1
- package/dist/sdk/authentication-jwt-bearer/mfa/types.d.ts.map +1 -1
- package/dist/sdk/authentication-jwt-bearer/mfa/types.js.map +1 -1
- package/dist/sdk/authentication.d.ts +1 -0
- package/dist/sdk/authentication.d.ts.map +1 -1
- package/dist/sdk/authentication.js.map +1 -1
- package/dist/sdk/constants.d.ts +1 -0
- package/dist/sdk/constants.d.ts.map +1 -1
- package/dist/sdk/constants.js +1 -0
- package/dist/sdk/constants.js.map +1 -1
- package/dist/sdk/errors.d.ts +16 -1
- package/dist/sdk/errors.d.ts.map +1 -1
- package/dist/sdk/errors.js +18 -0
- package/dist/sdk/errors.js.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AC;CACF;AAED,OAAO,EAAE,iBAAiB,EAAE,MAAM,0CAA0C,CAAC;AAC7E,OAAO,EAAE,gBAAgB,EAAE,MAAM,yCAAyC,CAAC;AAC3E,cAAc,sCAAsC,CAAC","sourcesContent":["import type { PublicInterface } from '@metamask/utils';\nimport type { Eip1193Provider } from 'ethers';\n\nimport type { Env } from '../shared/env.js';\nimport { SIWEJwtBearerAuth } from './authentication-jwt-bearer/flow-siwe.js';\nimport { SRPJwtBearerAuth } from './authentication-jwt-bearer/flow-srp.js';\nimport type { MfaStepUpAssertion } from './authentication-jwt-bearer/mfa/services.js';\nimport type {\n EnrolledCredential,\n EnrollmentChallenge,\n EnrollmentProof,\n MfaCredentialType,\n StepUpChallenge,\n StepUpProof,\n} from './authentication-jwt-bearer/mfa/types.js';\nimport {\n getNonce,\n pairIdentifiers,\n} from './authentication-jwt-bearer/services.js';\nimport type { PairProfilesResponse } from './authentication-jwt-bearer/services.js';\nimport type {\n AccessToken,\n UserProfile,\n Pair,\n PairSocialIdentifierParams,\n OidcTokenAudience,\n OidcTokenClaims,\n UserProfileLineage,\n} from './authentication-jwt-bearer/types.js';\nimport { AuthType } from './authentication-jwt-bearer/types.js';\nimport { PairError, UnsupportedAuthTypeError } from './errors.js';\n\n// Computing the Classes, so we only get back the public methods for the interface.\n\ntype SIWEInterface = PublicInterface<SIWEJwtBearerAuth>;\nexport type SRPInterface = PublicInterface<SRPJwtBearerAuth>;\n\ntype SiweParams = ConstructorParameters<typeof SIWEJwtBearerAuth>;\ntype SRPParams = ConstructorParameters<typeof SRPJwtBearerAuth>;\ntype JwtBearerAuthParams = SiweParams | SRPParams;\n\nexport class JwtBearerAuth implements SIWEInterface, SRPInterface {\n readonly #type: AuthType;\n\n readonly #env: Env;\n\n readonly #sdk: SIWEJwtBearerAuth | SRPJwtBearerAuth;\n\n constructor(...args: JwtBearerAuthParams) {\n this.#type = args[0].type;\n this.#env = args[0].env;\n\n if (args[0].type === AuthType.SRP) {\n this.#sdk = new SRPJwtBearerAuth(args[0], args[1]);\n return;\n }\n\n if (args[0].type === AuthType.SiWE) {\n this.#sdk = new SIWEJwtBearerAuth(args[0], args[1]);\n return;\n }\n\n throw new UnsupportedAuthTypeError('unsupported auth type');\n }\n\n setCustomProvider(provider: Eip1193Provider) {\n this.#assertSRP(this.#type, this.#sdk);\n this.#sdk.setCustomProvider(provider);\n }\n\n async getAccessToken(entropySourceId?: string): Promise<string> {\n return await this.#sdk.getAccessToken(entropySourceId);\n }\n\n async connectSnap(): Promise<string> {\n this.#assertSRP(this.#type, this.#sdk);\n return this.#sdk.connectSnap();\n }\n\n async isSnapConnected(): Promise<boolean> {\n this.#assertSRP(this.#type, this.#sdk);\n return this.#sdk.isSnapConnected();\n }\n\n async getUserProfile(entropySourceId?: string): Promise<UserProfile> {\n return await this.#sdk.getUserProfile(entropySourceId);\n }\n\n async getIdentifier(entropySourceId?: string): Promise<string> {\n return await this.#sdk.getIdentifier(entropySourceId);\n }\n\n async getUserProfileLineage(\n entropySourceId?: string,\n ): Promise<UserProfileLineage> {\n return await this.#sdk.getUserProfileLineage(entropySourceId);\n }\n\n async getCustomerServiceToken(entropySourceId?: string): Promise<string> {\n return await this.#sdk.getCustomerServiceToken(entropySourceId);\n }\n\n async getPartnerIdentityToken(\n claims: OidcTokenClaims,\n audience: OidcTokenAudience,\n entropySourceId?: string,\n ): Promise<string> {\n return await this.#sdk.getPartnerIdentityToken(\n claims,\n audience,\n entropySourceId,\n );\n }\n\n async beginMfaEnrollment(\n type: MfaCredentialType,\n options?: { email?: string; entropySourceId?: string },\n ): Promise<EnrollmentChallenge> {\n this.#assertSRP(this.#type, this.#sdk);\n return await this.#sdk.beginMfaEnrollment(type, options);\n }\n\n async completeMfaEnrollment(\n flowId: string,\n proof: EnrollmentProof,\n entropySourceId?: string,\n ): Promise<void> {\n this.#assertSRP(this.#type, this.#sdk);\n await this.#sdk.completeMfaEnrollment(flowId, proof, entropySourceId);\n }\n\n async beginMfaVerification(\n type: MfaCredentialType,\n entropySourceId?: string,\n ): Promise<StepUpChallenge> {\n this.#assertSRP(this.#type, this.#sdk);\n return await this.#sdk.beginMfaVerification(type, entropySourceId);\n }\n\n async completeMfaVerification(\n flowId: string,\n proof: StepUpProof,\n entropySourceId?: string,\n ): Promise<MfaStepUpAssertion> {\n this.#assertSRP(this.#type, this.#sdk);\n return await this.#sdk.completeMfaVerification(\n flowId,\n proof,\n entropySourceId,\n );\n }\n\n async getMfaCredentials(\n entropySourceId?: string,\n ): Promise<EnrolledCredential[]> {\n this.#assertSRP(this.#type, this.#sdk);\n return await this.#sdk.getMfaCredentials(entropySourceId);\n }\n\n async exchangeMfaAssertion(assertionJwt: string): Promise<AccessToken> {\n this.#assertSRP(this.#type, this.#sdk);\n return await this.#sdk.exchangeMfaAssertion(assertionJwt);\n }\n\n async pairSrpProfiles(\n accessTokens: string[],\n authAccessToken: string,\n ): Promise<PairProfilesResponse> {\n this.#assertSRP(this.#type, this.#sdk);\n return await this.#sdk.pairSrpProfiles(accessTokens, authAccessToken);\n }\n\n async pairSocialIdentifier(\n params: PairSocialIdentifierParams,\n authAccessToken: string,\n ): Promise<void> {\n this.#assertSRP(this.#type, this.#sdk);\n await this.#sdk.pairSocialIdentifier(params, authAccessToken);\n }\n\n async signMessage(\n message: string,\n entropySourceId?: string,\n ): Promise<string> {\n return await this.#sdk.signMessage(message, entropySourceId);\n }\n\n async pairIdentifiers(pairing: Pair[]): Promise<void> {\n const profile = await this.getUserProfile();\n const n = await getNonce(profile.profileId, this.#env);\n\n const logins = await Promise.all(\n pairing.map(async (p) => {\n try {\n const raw = `metamask:${n.nonce}:${p.identifier}`;\n const sig = await p.signMessage(raw);\n return {\n signature: sig,\n raw_message: raw,\n encrypted_storage_key: p.encryptedStorageKey,\n identifier_type: p.identifierType,\n };\n } catch (e) {\n /* istanbul ignore next */\n const errorMessage =\n e instanceof Error ? e.message : JSON.stringify(e ?? '');\n throw new PairError(\n `failed to sign pairing message: ${errorMessage}`,\n );\n }\n }),\n );\n\n const accessToken = await this.getAccessToken();\n await pairIdentifiers(n.nonce, logins, accessToken, this.#env);\n }\n\n prepare(signer: {\n address: string;\n chainId: number;\n signMessage: (message: string) => Promise<string>;\n domain: string;\n }): void {\n this.#assertSIWE(this.#type, this.#sdk);\n this.#sdk.prepare(signer);\n }\n\n #assertSIWE(\n type: AuthType,\n _sdk: SIWEJwtBearerAuth | SRPJwtBearerAuth,\n ): asserts _sdk is SIWEJwtBearerAuth {\n if (type === AuthType.SiWE) {\n return;\n }\n\n throw new UnsupportedAuthTypeError(\n 'This method is only available via SIWE auth type',\n );\n }\n\n #assertSRP(\n type: AuthType,\n _sdk: SIWEJwtBearerAuth | SRPJwtBearerAuth,\n ): asserts _sdk is SRPJwtBearerAuth {\n if (type === AuthType.SRP) {\n return;\n }\n\n throw new UnsupportedAuthTypeError(\n 'This method is only available via SRP auth type',\n );\n }\n}\n\nexport { SIWEJwtBearerAuth } from './authentication-jwt-bearer/flow-siwe.js';\nexport { SRPJwtBearerAuth } from './authentication-jwt-bearer/flow-srp.js';\nexport * from './authentication-jwt-bearer/types.js';\n"]}
|
|
1
|
+
{"version":3,"file":"authentication.js","sourceRoot":"","sources":["../../src/sdk/authentication.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,iBAAiB,EAAE,MAAM,0CAA0C,CAAC;AAC7E,OAAO,EAAE,gBAAgB,EAAE,MAAM,yCAAyC,CAAC;AAU3E,OAAO,EACL,QAAQ,EACR,eAAe,GAChB,MAAM,yCAAyC,CAAC;AAWjD,OAAO,EAAE,QAAQ,EAAE,MAAM,sCAAsC,CAAC;AAChE,OAAO,EAAE,SAAS,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAC;AAWlE,MAAM,OAAO,aAAa;IACf,KAAK,CAAW;IAEhB,IAAI,CAAM;IAEV,IAAI,CAAuC;IAEpD,YAAY,GAAG,IAAyB;QACtC,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;QA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MAAM,eAAe,CAAC,CAAC,CAAC,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;IACjE,CAAC;IAED,OAAO,CAAC,MAKP;QACC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;QACxC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IAC5B,CAAC;IAED,WAAW,CACT,IAAc,EACd,IAA0C;QAE1C,IAAI,IAAI,KAAK,QAAQ,CAAC,IAAI,EAAE,CAAC;YAC3B,OAAO;QACT,CAAC;QAED,MAAM,IAAI,wBAAwB,CAChC,kDAAkD,CACnD,CAAC;IACJ,CAAC;IAED,UAAU,CACR,IAAc,EACd,IAA0C;QAE1C,IAAI,IAAI,KAAK,QAAQ,CAAC,GAAG,EAAE,CAAC;YAC1B,OAAO;QACT,CAAC;QAED,MAAM,IAAI,wBAAwB,CAChC,iDAAiD,CAClD,CAAC;IACJ,CAAC;CACF;AAED,OAAO,EAAE,iBAAiB,EAAE,MAAM,0CAA0C,CAAC;AAC7E,OAAO,EAAE,gBAAgB,EAAE,MAAM,yCAAyC,CAAC;AAC3E,cAAc,sCAAsC,CAAC","sourcesContent":["import type { PublicInterface } from '@metamask/utils';\nimport type { Eip1193Provider } from 'ethers';\n\nimport type { Env } from '../shared/env.js';\nimport { SIWEJwtBearerAuth } from './authentication-jwt-bearer/flow-siwe.js';\nimport { SRPJwtBearerAuth } from './authentication-jwt-bearer/flow-srp.js';\nimport type { MfaStepUpAssertion } from './authentication-jwt-bearer/mfa/services.js';\nimport type {\n EnrolledCredential,\n EnrollmentChallenge,\n EnrollmentProof,\n MfaCredentialType,\n StepUpChallenge,\n StepUpProof,\n} from './authentication-jwt-bearer/mfa/types.js';\nimport {\n getNonce,\n pairIdentifiers,\n} from './authentication-jwt-bearer/services.js';\nimport type { PairProfilesResponse } from './authentication-jwt-bearer/services.js';\nimport type {\n AccessToken,\n UserProfile,\n Pair,\n PairSocialIdentifierParams,\n OidcTokenAudience,\n OidcTokenClaims,\n UserProfileLineage,\n} from './authentication-jwt-bearer/types.js';\nimport { AuthType } from './authentication-jwt-bearer/types.js';\nimport { PairError, UnsupportedAuthTypeError } from './errors.js';\n\n// Computing the Classes, so we only get back the public methods for the interface.\n\ntype SIWEInterface = PublicInterface<SIWEJwtBearerAuth>;\nexport type SRPInterface = PublicInterface<SRPJwtBearerAuth>;\n\ntype SiweParams = ConstructorParameters<typeof SIWEJwtBearerAuth>;\ntype SRPParams = ConstructorParameters<typeof SRPJwtBearerAuth>;\ntype JwtBearerAuthParams = SiweParams | SRPParams;\n\nexport class JwtBearerAuth implements SIWEInterface, SRPInterface {\n readonly #type: AuthType;\n\n readonly #env: Env;\n\n readonly #sdk: SIWEJwtBearerAuth | SRPJwtBearerAuth;\n\n constructor(...args: JwtBearerAuthParams) {\n this.#type = args[0].type;\n this.#env = args[0].env;\n\n if (args[0].type === AuthType.SRP) {\n this.#sdk = new SRPJwtBearerAuth(args[0], args[1]);\n return;\n }\n\n if (args[0].type === AuthType.SiWE) {\n this.#sdk = new SIWEJwtBearerAuth(args[0], args[1]);\n return;\n }\n\n throw new UnsupportedAuthTypeError('unsupported auth type');\n }\n\n setCustomProvider(provider: Eip1193Provider) {\n this.#assertSRP(this.#type, this.#sdk);\n this.#sdk.setCustomProvider(provider);\n }\n\n async getAccessToken(entropySourceId?: string): Promise<string> {\n return await this.#sdk.getAccessToken(entropySourceId);\n }\n\n async connectSnap(): Promise<string> {\n this.#assertSRP(this.#type, this.#sdk);\n return this.#sdk.connectSnap();\n }\n\n async isSnapConnected(): Promise<boolean> {\n this.#assertSRP(this.#type, this.#sdk);\n return this.#sdk.isSnapConnected();\n }\n\n async getUserProfile(entropySourceId?: string): Promise<UserProfile> {\n return await this.#sdk.getUserProfile(entropySourceId);\n }\n\n async getIdentifier(entropySourceId?: string): Promise<string> {\n return await this.#sdk.getIdentifier(entropySourceId);\n }\n\n async getUserProfileLineage(\n entropySourceId?: string,\n ): Promise<UserProfileLineage> {\n return await this.#sdk.getUserProfileLineage(entropySourceId);\n }\n\n async getCustomerServiceToken(entropySourceId?: string): Promise<string> {\n return await this.#sdk.getCustomerServiceToken(entropySourceId);\n }\n\n async getPartnerIdentityToken(\n claims: OidcTokenClaims,\n audience: OidcTokenAudience,\n entropySourceId?: string,\n ): Promise<string> {\n return await this.#sdk.getPartnerIdentityToken(\n claims,\n audience,\n entropySourceId,\n );\n }\n\n async beginMfaEnrollment(\n type: MfaCredentialType,\n options?: {\n email?: string;\n entropySourceId?: string;\n accessToken?: string;\n },\n ): Promise<EnrollmentChallenge> {\n this.#assertSRP(this.#type, this.#sdk);\n return await this.#sdk.beginMfaEnrollment(type, options);\n }\n\n async completeMfaEnrollment(\n flowId: string,\n proof: EnrollmentProof,\n entropySourceId?: string,\n ): Promise<void> {\n this.#assertSRP(this.#type, this.#sdk);\n await this.#sdk.completeMfaEnrollment(flowId, proof, entropySourceId);\n }\n\n async beginMfaVerification(\n type: MfaCredentialType,\n entropySourceId?: string,\n ): Promise<StepUpChallenge> {\n this.#assertSRP(this.#type, this.#sdk);\n return await this.#sdk.beginMfaVerification(type, entropySourceId);\n }\n\n async completeMfaVerification(\n flowId: string,\n proof: StepUpProof,\n entropySourceId?: string,\n ): Promise<MfaStepUpAssertion> {\n this.#assertSRP(this.#type, this.#sdk);\n return await this.#sdk.completeMfaVerification(\n flowId,\n proof,\n entropySourceId,\n );\n }\n\n async getMfaCredentials(\n entropySourceId?: string,\n ): Promise<EnrolledCredential[]> {\n this.#assertSRP(this.#type, this.#sdk);\n return await this.#sdk.getMfaCredentials(entropySourceId);\n }\n\n async exchangeMfaAssertion(assertionJwt: string): Promise<AccessToken> {\n this.#assertSRP(this.#type, this.#sdk);\n return await this.#sdk.exchangeMfaAssertion(assertionJwt);\n }\n\n async pairSrpProfiles(\n accessTokens: string[],\n authAccessToken: string,\n ): Promise<PairProfilesResponse> {\n this.#assertSRP(this.#type, this.#sdk);\n return await this.#sdk.pairSrpProfiles(accessTokens, authAccessToken);\n }\n\n async pairSocialIdentifier(\n params: PairSocialIdentifierParams,\n authAccessToken: string,\n ): Promise<void> {\n this.#assertSRP(this.#type, this.#sdk);\n await this.#sdk.pairSocialIdentifier(params, authAccessToken);\n }\n\n async signMessage(\n message: string,\n entropySourceId?: string,\n ): Promise<string> {\n return await this.#sdk.signMessage(message, entropySourceId);\n }\n\n async pairIdentifiers(pairing: Pair[]): Promise<void> {\n const profile = await this.getUserProfile();\n const n = await getNonce(profile.profileId, this.#env);\n\n const logins = await Promise.all(\n pairing.map(async (p) => {\n try {\n const raw = `metamask:${n.nonce}:${p.identifier}`;\n const sig = await p.signMessage(raw);\n return {\n signature: sig,\n raw_message: raw,\n encrypted_storage_key: p.encryptedStorageKey,\n identifier_type: p.identifierType,\n };\n } catch (e) {\n /* istanbul ignore next */\n const errorMessage =\n e instanceof Error ? e.message : JSON.stringify(e ?? '');\n throw new PairError(\n `failed to sign pairing message: ${errorMessage}`,\n );\n }\n }),\n );\n\n const accessToken = await this.getAccessToken();\n await pairIdentifiers(n.nonce, logins, accessToken, this.#env);\n }\n\n prepare(signer: {\n address: string;\n chainId: number;\n signMessage: (message: string) => Promise<string>;\n domain: string;\n }): void {\n this.#assertSIWE(this.#type, this.#sdk);\n this.#sdk.prepare(signer);\n }\n\n #assertSIWE(\n type: AuthType,\n _sdk: SIWEJwtBearerAuth | SRPJwtBearerAuth,\n ): asserts _sdk is SIWEJwtBearerAuth {\n if (type === AuthType.SiWE) {\n return;\n }\n\n throw new UnsupportedAuthTypeError(\n 'This method is only available via SIWE auth type',\n );\n }\n\n #assertSRP(\n type: AuthType,\n _sdk: SIWEJwtBearerAuth | SRPJwtBearerAuth,\n ): asserts _sdk is SRPJwtBearerAuth {\n if (type === AuthType.SRP) {\n return;\n }\n\n throw new UnsupportedAuthTypeError(\n 'This method is only available via SRP auth type',\n );\n }\n}\n\nexport { SIWEJwtBearerAuth } from './authentication-jwt-bearer/flow-siwe.js';\nexport { SRPJwtBearerAuth } from './authentication-jwt-bearer/flow-srp.js';\nexport * from './authentication-jwt-bearer/types.js';\n"]}
|
package/dist/sdk/constants.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/sdk/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,iBAAiB;IAC5B,YAAY;IACZ,QAAQ;IACR,oBAAoB;IACpB,iBAAiB;IACjB,WAAW;CACZ,CAAC"}
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/sdk/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,iBAAiB;IAC5B,YAAY;IACZ,SAAS;IACT,QAAQ;IACR,oBAAoB;IACpB,iBAAiB;IACjB,WAAW;CACZ,CAAC"}
|
package/dist/sdk/constants.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/sdk/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC/B,YAAY,EAAE,GAAG;IACjB,QAAQ,EAAE,GAAG;IACb,oBAAoB,EAAE,GAAG;IACzB,iBAAiB,EAAE,GAAG;IACtB,WAAW,EAAE,GAAG;CACjB,CAAC","sourcesContent":["export const HTTP_STATUS_CODES = {\n UNAUTHORIZED: 401,\n CONFLICT: 409,\n UNPROCESSABLE_ENTITY: 422,\n TOO_MANY_REQUESTS: 429,\n BAD_GATEWAY: 502,\n};\n"]}
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/sdk/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC/B,YAAY,EAAE,GAAG;IACjB,SAAS,EAAE,GAAG;IACd,QAAQ,EAAE,GAAG;IACb,oBAAoB,EAAE,GAAG;IACzB,iBAAiB,EAAE,GAAG;IACtB,WAAW,EAAE,GAAG;CACjB,CAAC","sourcesContent":["export const HTTP_STATUS_CODES = {\n UNAUTHORIZED: 401,\n FORBIDDEN: 403,\n CONFLICT: 409,\n UNPROCESSABLE_ENTITY: 422,\n TOO_MANY_REQUESTS: 429,\n BAD_GATEWAY: 502,\n};\n"]}
|
package/dist/sdk/errors.d.ts
CHANGED
|
@@ -15,8 +15,23 @@ export declare class MfaError extends Error {
|
|
|
15
15
|
retryAfterMs?: number;
|
|
16
16
|
});
|
|
17
17
|
}
|
|
18
|
+
/**
|
|
19
|
+
* The credential cannot be enrolled because an equivalent one already exists:
|
|
20
|
+
* `email_already_enrolled` (this profile already has a verified email),
|
|
21
|
+
* `email_socially_verified` (the email is verified through a social login), or
|
|
22
|
+
* `credential_already_enrolled` (the email or passkey is enrolled on another
|
|
23
|
+
* profile; the profiles must be paired or the credential removed).
|
|
24
|
+
*/
|
|
18
25
|
export declare class CredentialAlreadyEnrolledError extends MfaError {
|
|
19
|
-
constructor(code: 'credential_already_enrolled' | 'email_already_enrolled', message: string, status?: number);
|
|
26
|
+
constructor(code: 'credential_already_enrolled' | 'email_already_enrolled' | 'email_socially_verified', message: string, status?: number);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* The profile already has MFA credentials, so enrolling another requires an
|
|
30
|
+
* `aal:2` access token; the client must complete a step-up and retry with the
|
|
31
|
+
* same flow.
|
|
32
|
+
*/
|
|
33
|
+
export declare class StepUpRequiredError extends MfaError {
|
|
34
|
+
constructor(message: string, status?: number);
|
|
20
35
|
}
|
|
21
36
|
export declare class CredentialNotEnrolledError extends MfaError {
|
|
22
37
|
constructor(message: string, status?: number);
|
package/dist/sdk/errors.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/sdk/errors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0CAA0C,CAAC;AAI7E,KA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F;AAED,qBAAa,gBAAiB,SAAQ,KAAK;IACzC,QAAQ,CAAC,MAAM,SAAuC;IAEtD,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;IAE/B,YAAY,OAAO,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,MAAM,EAIjD;IAED;;;;;OAKG;IACH,MAAM,CAAC,gBAAgB,CAAC,CAAC,EAAE,OAAO,GAAG,CAAC,IAAI,gBAAgB,CAQzD;CACF"}
|
package/dist/sdk/errors.js
CHANGED
|
@@ -18,12 +18,30 @@ export class MfaError extends Error {
|
|
|
18
18
|
this.retryAfterMs = options?.retryAfterMs;
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
|
+
/**
|
|
22
|
+
* The credential cannot be enrolled because an equivalent one already exists:
|
|
23
|
+
* `email_already_enrolled` (this profile already has a verified email),
|
|
24
|
+
* `email_socially_verified` (the email is verified through a social login), or
|
|
25
|
+
* `credential_already_enrolled` (the email or passkey is enrolled on another
|
|
26
|
+
* profile; the profiles must be paired or the credential removed).
|
|
27
|
+
*/
|
|
21
28
|
export class CredentialAlreadyEnrolledError extends MfaError {
|
|
22
29
|
constructor(code, message, status = HTTP_STATUS_CODES.CONFLICT) {
|
|
23
30
|
super(code, message, { status });
|
|
24
31
|
this.name = 'CredentialAlreadyEnrolledError';
|
|
25
32
|
}
|
|
26
33
|
}
|
|
34
|
+
/**
|
|
35
|
+
* The profile already has MFA credentials, so enrolling another requires an
|
|
36
|
+
* `aal:2` access token; the client must complete a step-up and retry with the
|
|
37
|
+
* same flow.
|
|
38
|
+
*/
|
|
39
|
+
export class StepUpRequiredError extends MfaError {
|
|
40
|
+
constructor(message, status = HTTP_STATUS_CODES.FORBIDDEN) {
|
|
41
|
+
super('aal2_required', message, { status });
|
|
42
|
+
this.name = 'StepUpRequiredError';
|
|
43
|
+
}
|
|
44
|
+
}
|
|
27
45
|
export class CredentialNotEnrolledError extends MfaError {
|
|
28
46
|
constructor(message, status = HTTP_STATUS_CODES.CONFLICT) {
|
|
29
47
|
super('credential_not_enrolled', message, { status });
|
package/dist/sdk/errors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/sdk/errors.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAIhD;;;;;GAKG;AACH,MAAM,OAAO,QAAS,SAAQ,KAAK;IACxB,OAAO,CAAyB;IAEhC,MAAM,CAAU;IAEhB,YAAY,CAAU;IAE/B,YACE,OAA+B,EAC/B,OAAe,EACf,OAAoD;QAEpD,KAAK,CAAC,OAAO,OAAO,MAAM,OAAO,EAAE,CAAC,CAAC;QACrC,IAAI,CAAC,IAAI,GAAG,UAAU,CAAC;QACvB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,MAAM,GAAG,OAAO,EAAE,MAAM,CAAC;QAC9B,IAAI,CAAC,YAAY,GAAG,OAAO,EAAE,YAAY,CAAC;IAC5C,CAAC;CACF;AAED,MAAM,OAAO,8BAA+B,SAAQ,QAAQ;IAC1D,YACE,IAA8D,EAC9D,OAAe,EACf,MAAM,GAAG,iBAAiB,CAAC,QAAQ;QAEnC,KAAK,CAAC,IAAI,EAAE,OAAO,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC;QACjC,IAAI,CAAC,IAAI,GAAG,gCAAgC,CAAC;IAC/C,CAAC;CACF;AAED,MAAM,OAAO,0BAA2B,SAAQ,QAAQ;IACtD,YAAY,OAAe,EAAE,MAAM,GAAG,iBAAiB,CAAC,QAAQ;QAC9D,KAAK,CAAC,yBAAyB,EAAE,OAAO,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC;QACtD,IAAI,CAAC,IAAI,GAAG,4BAA4B,CAAC;IAC3C,CAAC;CACF;AAED;;GAEG;AACH,MAAM,OAAO,mBAAoB,SAAQ,QAA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AAQ,KAAK;IACxC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAC;IAChC,CAAC;CACF;AAED,MAAM,OAAO,wBAAyB,SAAQ,KAAK;IACjD,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,0BAA0B,CAAC;IACzC,CAAC;CACF;AAED,MAAM,OAAO,aAAc,SAAQ,KAAK;IACtC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,eAAe,CAAC;IAC9B,CAAC;CACF;AAED,MAAM,OAAO,gBAAiB,SAAQ,KAAK;IAChC,MAAM,GAAG,iBAAiB,CAAC,iBAAiB,CAAC;IAE7C,YAAY,CAAU;IAE/B,YAAY,OAAe,EAAE,YAAqB;QAChD,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,kBAAkB,CAAC;QAC/B,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;IACnC,CAAC;IAED;;;;;OAKG;IACH,MAAM,CAAC,gBAAgB,CAAC,CAAU;QAChC,OAAO,CACL,CAAC,YAAY,gBAAgB;YAC7B,CAAC,OAAO,CAAC,KAAK,QAAQ;gBACpB,CAAC,KAAK,IAAI;gBACV,QAAQ,IAAI,CAAC;gBACb,CAAC,CAAC,MAAM,KAAK,iBAAiB,CAAC,iBAAiB,CAAC,CACpD,CAAC;IACJ,CAAC;CACF","sourcesContent":["import type { MfaErrorCode } from './authentication-jwt-bearer/mfa/types.js';\nimport { HTTP_STATUS_CODES } from './constants.js';\nimport { asRecord } from './utils/as-record.js';\n\ntype ExtensibleMfaErrorCode = MfaErrorCode | (string & {});\n\n/**\n * Base error for MFA operations.\n *\n * The machine-readable code is an enumerable own property so it survives\n * JSON-RPC error serialization.\n */\nexport class MfaError extends Error {\n readonly mfaCode: ExtensibleMfaErrorCode;\n\n readonly status?: number;\n\n readonly retryAfterMs?: number;\n\n constructor(\n mfaCode: ExtensibleMfaErrorCode,\n message: string,\n options?: { status?: number; retryAfterMs?: number },\n ) {\n super(`MFA[${mfaCode}]: ${message}`);\n this.name = 'MfaError';\n this.mfaCode = mfaCode;\n this.status = options?.status;\n this.retryAfterMs = options?.retryAfterMs;\n }\n}\n\nexport class CredentialAlreadyEnrolledError extends MfaError {\n constructor(\n code: 'credential_already_enrolled' | 'email_already_enrolled',\n message: string,\n status = HTTP_STATUS_CODES.CONFLICT,\n ) {\n super(code, message, { status });\n this.name = 'CredentialAlreadyEnrolledError';\n }\n}\n\nexport class CredentialNotEnrolledError extends MfaError {\n constructor(message: string, status = HTTP_STATUS_CODES.CONFLICT) {\n super('credential_not_enrolled', message, { status });\n this.name = 'CredentialNotEnrolledError';\n }\n}\n\n/**\n * The begin/complete flow is stale or unknown; the client must restart it.\n */\nexport class MfaFlowExpiredError extends MfaError {\n constructor(\n code: 'flow_expired' | 'invalid_flow',\n message: string,\n status?: number,\n ) {\n super(code, message, { status });\n this.name = 'MfaFlowExpiredError';\n }\n}\n\n/**\n * The profile has no identity-provider record yet. Not a stale flow: the\n * user must enroll a first credential before verifying.\n */\nexport class MfaIdentityMissingError extends MfaError {\n constructor(message: string, status = HTTP_STATUS_CODES.CONFLICT) {\n super('mfa_identity_missing', message, { status });\n this.name = 'MfaIdentityMissingError';\n }\n}\n\nexport class MfaVerificationFailedError extends MfaError {\n constructor(\n code: 'invalid_code' | 'invalid_attestation' | 'invalid_assertion',\n message: string,\n status?: number,\n ) {\n super(code, message, { status });\n this.name = 'MfaVerificationFailedError';\n }\n}\n\nexport class TooManyAttemptsError extends MfaError {\n constructor(message: string, status?: number) {\n super('too_many_attempts', message, { status });\n this.name = 'TooManyAttemptsError';\n }\n}\n\nexport class MaxPasskeysReachedError extends MfaError {\n constructor(\n message: string,\n status = HTTP_STATUS_CODES.UNPROCESSABLE_ENTITY,\n ) {\n super('max_passkeys_reached', message, { status });\n this.name = 'MaxPasskeysReachedError';\n }\n}\n\nexport class MaxIdentifiersReachedError extends MfaError {\n constructor(message: string, status = HTTP_STATUS_CODES.CONFLICT) {\n super('max_identifiers_reached', message, { status });\n this.name = 'MaxIdentifiersReachedError';\n }\n}\n\nexport class OtpResendCooldownError extends MfaError {\n constructor(\n message: string,\n retryAfterMs?: number,\n status = HTTP_STATUS_CODES.TOO_MANY_REQUESTS,\n ) {\n super('otp_resend_cooldown', message, { status, retryAfterMs });\n this.name = 'OtpResendCooldownError';\n }\n}\n\n/**\n * A 429 without an MFA-specific code: generic throttling, not an OTP resend\n * cooldown.\n */\nexport class MfaRateLimitedError extends MfaError {\n constructor(\n message: string,\n retryAfterMs?: number,\n status = HTTP_STATUS_CODES.TOO_MANY_REQUESTS,\n ) {\n super('rate_limited', message, { status, retryAfterMs });\n this.name = 'MfaRateLimitedError';\n }\n}\n\n/**\n * The identity provider or the network is unreachable. Safe to retry.\n * `status` is only set when the service answered.\n */\nexport class MfaUnavailableError extends MfaError {\n constructor(message: string, status?: number) {\n super('kratos_unavailable', message, { status });\n this.name = 'MfaUnavailableError';\n }\n}\n\nexport class ElevatedTokenInvalidError extends MfaError {\n constructor(message: string) {\n super('elevated_token_invalid', message);\n this.name = 'ElevatedTokenInvalidError';\n }\n}\n\n/**\n * Gets an MFA code from direct, serialized, or message-only errors.\n *\n * @param error - Value to inspect.\n * @returns The stable code, if present.\n */\nexport function getMfaErrorCode(\n error: unknown,\n): ExtensibleMfaErrorCode | undefined {\n const direct = asRecord(error);\n if (typeof direct?.mfaCode === 'string') {\n return direct.mfaCode;\n }\n\n const data = asRecord(direct?.data);\n const cause = asRecord(data?.cause);\n if (typeof cause?.mfaCode === 'string') {\n return cause.mfaCode;\n }\n\n const messages = [direct?.message, cause?.message];\n for (const message of messages) {\n if (typeof message === 'string') {\n const match = /^MFA\\[([^\\]]+)\\]:/u.exec(message);\n if (match?.[1]) {\n return match[1];\n }\n }\n }\n return undefined;\n}\n\n/**\n * Checks whether a value carries an MFA error code.\n *\n * @param error - Value to inspect.\n * @param codes - Optional codes to match.\n * @returns Whether the value is an MFA error with a requested code.\n */\nexport function isMfaError(\n error: unknown,\n ...codes: ExtensibleMfaErrorCode[]\n): boolean {\n const code = getMfaErrorCode(error);\n return code !== undefined && (codes.length === 0 || codes.includes(code));\n}\n\n/**\n * Gets a retry delay from direct or serialized MFA errors.\n *\n * @param error - Value to inspect.\n * @returns Retry delay in milliseconds, if present.\n */\nexport function getMfaRetryAfterMs(error: unknown): number | undefined {\n const direct = asRecord(error);\n if (typeof direct?.retryAfterMs === 'number') {\n return direct.retryAfterMs;\n }\n const data = asRecord(direct?.data);\n const cause = asRecord(data?.cause);\n return typeof cause?.retryAfterMs === 'number'\n ? cause.retryAfterMs\n : undefined;\n}\n\nexport class NonceRetrievalError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'NonceRetrievalError';\n }\n}\n\nexport class SignInError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'SignInError';\n }\n}\n\nexport class PairError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'PairError';\n }\n}\n\n/**\n * Thrown when `POST /api/v2/profile/pair/identifier` returns 409 Conflict:\n * the social identifier already belongs to another canonical profile.\n * Retrying the same request cannot succeed.\n */\nexport class PairConflictError extends PairError {\n readonly status = HTTP_STATUS_CODES.CONFLICT;\n\n constructor(message: string) {\n super(message);\n this.name = 'PairConflictError';\n }\n}\n\n/**\n * Thrown when `POST /api/v2/oidc/token` returns 422: this profile has no\n * verified email on record. Consumers should send the user through email\n * OTP (or Google pair) and retry.\n */\nexport class EmailRequiredError extends Error {\n readonly status = HTTP_STATUS_CODES.UNPROCESSABLE_ENTITY;\n\n constructor(message: string) {\n super(message);\n this.name = 'EmailRequiredError';\n }\n}\n\nexport class UserStorageError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'UserStorageError';\n }\n}\n\nexport class ValidationError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'ValidationError';\n }\n}\n\nexport class UnsupportedAuthTypeError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'UnsupportedAuthTypeError';\n }\n}\n\nexport class NotFoundError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'NotFoundError';\n }\n}\n\nexport class RateLimitedError extends Error {\n readonly status = HTTP_STATUS_CODES.TOO_MANY_REQUESTS;\n\n readonly retryAfterMs?: number;\n\n constructor(message: string, retryAfterMs?: number) {\n super(message);\n this.name = 'RateLimitedError';\n this.retryAfterMs = retryAfterMs;\n }\n\n /**\n * Check if an unknown error is a rate limit error (429 status).\n *\n * @param e - The error to check\n * @returns True if the error is a rate limit error\n */\n static isRateLimitError(e: unknown): e is RateLimitedError {\n return (\n e instanceof RateLimitedError ||\n (typeof e === 'object' &&\n e !== null &&\n 'status' in e &&\n e.status === HTTP_STATUS_CODES.TOO_MANY_REQUESTS)\n );\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/sdk/errors.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAIhD;;;;;GAKG;AACH,MAAM,OAAO,QAAS,SAAQ,KAAK;IACxB,OAAO,CAAyB;IAEhC,MAAM,CAAU;IAEhB,YAAY,CAAU;IAE/B,YACE,OAA+B,EAC/B,OAAe,EACf,OAAoD;QAEpD,KAAK,CAAC,OAAO,OAAO,MAAM,OAAO,EAAE,CAAC,CAAC;QACrC,IAAI,CAAC,IAAI,GAAG,UAAU,CAAC;QACvB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,MAAM,GAAG,OAAO,EAAE,MAAM,CAAC;QAC9B,IAAI,CAAC,YAAY,GAAG,OAAO,EAAE,YAAY,CAAC;IAC5C,CAAC;CACF;AAED;;;;;;GAMG;AACH,MAAM,OAAO,8BAA+B,SAAQ,QAAQ;IA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AC,iBAAiB,CAAC;IAE7C,YAAY,CAAU;IAE/B,YAAY,OAAe,EAAE,YAAqB;QAChD,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,kBAAkB,CAAC;QAC/B,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;IACnC,CAAC;IAED;;;;;OAKG;IACH,MAAM,CAAC,gBAAgB,CAAC,CAAU;QAChC,OAAO,CACL,CAAC,YAAY,gBAAgB;YAC7B,CAAC,OAAO,CAAC,KAAK,QAAQ;gBACpB,CAAC,KAAK,IAAI;gBACV,QAAQ,IAAI,CAAC;gBACb,CAAC,CAAC,MAAM,KAAK,iBAAiB,CAAC,iBAAiB,CAAC,CACpD,CAAC;IACJ,CAAC;CACF","sourcesContent":["import type { MfaErrorCode } from './authentication-jwt-bearer/mfa/types.js';\nimport { HTTP_STATUS_CODES } from './constants.js';\nimport { asRecord } from './utils/as-record.js';\n\ntype ExtensibleMfaErrorCode = MfaErrorCode | (string & {});\n\n/**\n * Base error for MFA operations.\n *\n * The machine-readable code is an enumerable own property so it survives\n * JSON-RPC error serialization.\n */\nexport class MfaError extends Error {\n readonly mfaCode: ExtensibleMfaErrorCode;\n\n readonly status?: number;\n\n readonly retryAfterMs?: number;\n\n constructor(\n mfaCode: ExtensibleMfaErrorCode,\n message: string,\n options?: { status?: number; retryAfterMs?: number },\n ) {\n super(`MFA[${mfaCode}]: ${message}`);\n this.name = 'MfaError';\n this.mfaCode = mfaCode;\n this.status = options?.status;\n this.retryAfterMs = options?.retryAfterMs;\n }\n}\n\n/**\n * The credential cannot be enrolled because an equivalent one already exists:\n * `email_already_enrolled` (this profile already has a verified email),\n * `email_socially_verified` (the email is verified through a social login), or\n * `credential_already_enrolled` (the email or passkey is enrolled on another\n * profile; the profiles must be paired or the credential removed).\n */\nexport class CredentialAlreadyEnrolledError extends MfaError {\n constructor(\n code:\n | 'credential_already_enrolled'\n | 'email_already_enrolled'\n | 'email_socially_verified',\n message: string,\n status = HTTP_STATUS_CODES.CONFLICT,\n ) {\n super(code, message, { status });\n this.name = 'CredentialAlreadyEnrolledError';\n }\n}\n\n/**\n * The profile already has MFA credentials, so enrolling another requires an\n * `aal:2` access token; the client must complete a step-up and retry with the\n * same flow.\n */\nexport class StepUpRequiredError extends MfaError {\n constructor(message: string, status = HTTP_STATUS_CODES.FORBIDDEN) {\n super('aal2_required', message, { status });\n this.name = 'StepUpRequiredError';\n }\n}\n\nexport class CredentialNotEnrolledError extends MfaError {\n constructor(message: string, status = HTTP_STATUS_CODES.CONFLICT) {\n super('credential_not_enrolled', message, { status });\n this.name = 'CredentialNotEnrolledError';\n }\n}\n\n/**\n * The begin/complete flow is stale or unknown; the client must restart it.\n */\nexport class MfaFlowExpiredError extends MfaError {\n constructor(\n code: 'flow_expired' | 'invalid_flow',\n message: string,\n status?: number,\n ) {\n super(code, message, { status });\n this.name = 'MfaFlowExpiredError';\n }\n}\n\n/**\n * The profile has no identity-provider record yet. Not a stale flow: the\n * user must enroll a first credential before verifying.\n */\nexport class MfaIdentityMissingError extends MfaError {\n constructor(message: string, status = HTTP_STATUS_CODES.CONFLICT) {\n super('mfa_identity_missing', message, { status });\n this.name = 'MfaIdentityMissingError';\n }\n}\n\nexport class MfaVerificationFailedError extends MfaError {\n constructor(\n code: 'invalid_code' | 'invalid_attestation' | 'invalid_assertion',\n message: string,\n status?: number,\n ) {\n super(code, message, { status });\n this.name = 'MfaVerificationFailedError';\n }\n}\n\nexport class TooManyAttemptsError extends MfaError {\n constructor(message: string, status?: number) {\n super('too_many_attempts', message, { status });\n this.name = 'TooManyAttemptsError';\n }\n}\n\nexport class MaxPasskeysReachedError extends MfaError {\n constructor(\n message: string,\n status = HTTP_STATUS_CODES.UNPROCESSABLE_ENTITY,\n ) {\n super('max_passkeys_reached', message, { status });\n this.name = 'MaxPasskeysReachedError';\n }\n}\n\nexport class MaxIdentifiersReachedError extends MfaError {\n constructor(message: string, status = HTTP_STATUS_CODES.CONFLICT) {\n super('max_identifiers_reached', message, { status });\n this.name = 'MaxIdentifiersReachedError';\n }\n}\n\nexport class OtpResendCooldownError extends MfaError {\n constructor(\n message: string,\n retryAfterMs?: number,\n status = HTTP_STATUS_CODES.TOO_MANY_REQUESTS,\n ) {\n super('otp_resend_cooldown', message, { status, retryAfterMs });\n this.name = 'OtpResendCooldownError';\n }\n}\n\n/**\n * A 429 without an MFA-specific code: generic throttling, not an OTP resend\n * cooldown.\n */\nexport class MfaRateLimitedError extends MfaError {\n constructor(\n message: string,\n retryAfterMs?: number,\n status = HTTP_STATUS_CODES.TOO_MANY_REQUESTS,\n ) {\n super('rate_limited', message, { status, retryAfterMs });\n this.name = 'MfaRateLimitedError';\n }\n}\n\n/**\n * The identity provider or the network is unreachable. Safe to retry.\n * `status` is only set when the service answered.\n */\nexport class MfaUnavailableError extends MfaError {\n constructor(message: string, status?: number) {\n super('kratos_unavailable', message, { status });\n this.name = 'MfaUnavailableError';\n }\n}\n\nexport class ElevatedTokenInvalidError extends MfaError {\n constructor(message: string) {\n super('elevated_token_invalid', message);\n this.name = 'ElevatedTokenInvalidError';\n }\n}\n\n/**\n * Gets an MFA code from direct, serialized, or message-only errors.\n *\n * @param error - Value to inspect.\n * @returns The stable code, if present.\n */\nexport function getMfaErrorCode(\n error: unknown,\n): ExtensibleMfaErrorCode | undefined {\n const direct = asRecord(error);\n if (typeof direct?.mfaCode === 'string') {\n return direct.mfaCode;\n }\n\n const data = asRecord(direct?.data);\n const cause = asRecord(data?.cause);\n if (typeof cause?.mfaCode === 'string') {\n return cause.mfaCode;\n }\n\n const messages = [direct?.message, cause?.message];\n for (const message of messages) {\n if (typeof message === 'string') {\n const match = /^MFA\\[([^\\]]+)\\]:/u.exec(message);\n if (match?.[1]) {\n return match[1];\n }\n }\n }\n return undefined;\n}\n\n/**\n * Checks whether a value carries an MFA error code.\n *\n * @param error - Value to inspect.\n * @param codes - Optional codes to match.\n * @returns Whether the value is an MFA error with a requested code.\n */\nexport function isMfaError(\n error: unknown,\n ...codes: ExtensibleMfaErrorCode[]\n): boolean {\n const code = getMfaErrorCode(error);\n return code !== undefined && (codes.length === 0 || codes.includes(code));\n}\n\n/**\n * Gets a retry delay from direct or serialized MFA errors.\n *\n * @param error - Value to inspect.\n * @returns Retry delay in milliseconds, if present.\n */\nexport function getMfaRetryAfterMs(error: unknown): number | undefined {\n const direct = asRecord(error);\n if (typeof direct?.retryAfterMs === 'number') {\n return direct.retryAfterMs;\n }\n const data = asRecord(direct?.data);\n const cause = asRecord(data?.cause);\n return typeof cause?.retryAfterMs === 'number'\n ? cause.retryAfterMs\n : undefined;\n}\n\nexport class NonceRetrievalError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'NonceRetrievalError';\n }\n}\n\nexport class SignInError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'SignInError';\n }\n}\n\nexport class PairError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'PairError';\n }\n}\n\n/**\n * Thrown when `POST /api/v2/profile/pair/identifier` returns 409 Conflict:\n * the social identifier already belongs to another canonical profile.\n * Retrying the same request cannot succeed.\n */\nexport class PairConflictError extends PairError {\n readonly status = HTTP_STATUS_CODES.CONFLICT;\n\n constructor(message: string) {\n super(message);\n this.name = 'PairConflictError';\n }\n}\n\n/**\n * Thrown when `POST /api/v2/oidc/token` returns 422: this profile has no\n * verified email on record. Consumers should send the user through email\n * OTP (or Google pair) and retry.\n */\nexport class EmailRequiredError extends Error {\n readonly status = HTTP_STATUS_CODES.UNPROCESSABLE_ENTITY;\n\n constructor(message: string) {\n super(message);\n this.name = 'EmailRequiredError';\n }\n}\n\nexport class UserStorageError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'UserStorageError';\n }\n}\n\nexport class ValidationError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'ValidationError';\n }\n}\n\nexport class UnsupportedAuthTypeError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'UnsupportedAuthTypeError';\n }\n}\n\nexport class NotFoundError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'NotFoundError';\n }\n}\n\nexport class RateLimitedError extends Error {\n readonly status = HTTP_STATUS_CODES.TOO_MANY_REQUESTS;\n\n readonly retryAfterMs?: number;\n\n constructor(message: string, retryAfterMs?: number) {\n super(message);\n this.name = 'RateLimitedError';\n this.retryAfterMs = retryAfterMs;\n }\n\n /**\n * Check if an unknown error is a rate limit error (429 status).\n *\n * @param e - The error to check\n * @returns True if the error is a rate limit error\n */\n static isRateLimitError(e: unknown): e is RateLimitedError {\n return (\n e instanceof RateLimitedError ||\n (typeof e === 'object' &&\n e !== null &&\n 'status' in e &&\n e.status === HTTP_STATUS_CODES.TOO_MANY_REQUESTS)\n );\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask-previews/profile-sync-controller",
|
|
3
|
-
"version": "32.2.0-preview-
|
|
3
|
+
"version": "32.2.0-preview-aecbce4ff",
|
|
4
4
|
"description": "The profile sync helps developers synchronize data across multiple clients and devices in a privacy-preserving way. All data saved in the user storage database is encrypted client-side to preserve privacy. The user storage provides a modular design, giving developers the flexibility to construct and manage their storage spaces in a way that best suits their needs",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Ethereum",
|