diff --git a/.gitignore b/.gitignore index 2b58a20..17334bb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ node_modules/ dist/ docs/ +coverage/ .DS_Store \ No newline at end of file diff --git a/packages/auth0-acul-js/interfaces/models/branding.ts b/packages/auth0-acul-js/interfaces/models/branding.ts index 86de502..eed1aaa 100644 --- a/packages/auth0-acul-js/interfaces/models/branding.ts +++ b/packages/auth0-acul-js/interfaces/models/branding.ts @@ -58,6 +58,6 @@ export interface BrandingThemes{ /* @namespace Client */ export interface BrandingMembers { - getSettings(): BrandingSettings | null; - getThemes(): BrandingThemes | null; + settings: BrandingSettings | null; + themes: BrandingThemes | null; } diff --git a/packages/auth0-acul-js/interfaces/models/client.ts b/packages/auth0-acul-js/interfaces/models/client.ts index a915ed8..cf70e9a 100644 --- a/packages/auth0-acul-js/interfaces/models/client.ts +++ b/packages/auth0-acul-js/interfaces/models/client.ts @@ -14,5 +14,5 @@ export interface ClientMembers { name: string; logoUri: string | null; description: string | null; - getMetadata(): { [key: string]: string } | null; + metadata: { [key: string]: string } | null; } diff --git a/packages/auth0-acul-js/interfaces/models/organization.ts b/packages/auth0-acul-js/interfaces/models/organization.ts index e3533b9..3b9500b 100644 --- a/packages/auth0-acul-js/interfaces/models/organization.ts +++ b/packages/auth0-acul-js/interfaces/models/organization.ts @@ -20,7 +20,7 @@ export interface OrganizationMembers { name: string | null; usage: string | null; displayName: string | null; - getBranding(): + branding: | { logoUrl?: string | undefined; colors?: { @@ -29,5 +29,5 @@ export interface OrganizationMembers { }; } | null; - getMetadata(): { [key: string]: string } | null; + metadata: { [key: string]: string } | null; } diff --git a/packages/auth0-acul-js/interfaces/models/screen.ts b/packages/auth0-acul-js/interfaces/models/screen.ts index 980088a..191259a 100644 --- a/packages/auth0-acul-js/interfaces/models/screen.ts +++ b/packages/auth0-acul-js/interfaces/models/screen.ts @@ -51,8 +51,8 @@ export interface ScreenMembers { captchaSiteKey: string | null; captchaProvider: string | null; isCaptchaAvailable: boolean; - getScreenData(): Record | null; - getScreenLinks(): Record | null; - getScreenTexts(): Record | null; - getCaptchaConfig(): CaptchaContext | null; + data: Record | null; + links: Record | null; + texts: Record | null; + captcha: CaptchaContext | null; } \ No newline at end of file diff --git a/packages/auth0-acul-js/interfaces/models/tenant.ts b/packages/auth0-acul-js/interfaces/models/tenant.ts index 6337482..40937a3 100644 --- a/packages/auth0-acul-js/interfaces/models/tenant.ts +++ b/packages/auth0-acul-js/interfaces/models/tenant.ts @@ -8,6 +8,6 @@ export interface TenantContext { export interface TenantMembers { name: string | null; friendlyName: string | null; - getEnabledLocales(): string[] | null; - getEnabledFactors(): string[] | null; + enabledLocales: string[] | null; + enabledFactors: string[] | null; } diff --git a/packages/auth0-acul-js/interfaces/models/transaction.ts b/packages/auth0-acul-js/interfaces/models/transaction.ts index f33d761..a5c95a8 100644 --- a/packages/auth0-acul-js/interfaces/models/transaction.ts +++ b/packages/auth0-acul-js/interfaces/models/transaction.ts @@ -139,7 +139,7 @@ export interface TransactionMembers { countryPrefix: CountryCode['prefix'] | null; connectionStrategy: string | null; hasErrors: boolean; - getErrors(): Error[] | null; - getCurrentConnection(): Connection | null; - getAlternateConnections(): (Connection | EnterpriseConnection)[] | null; + errors: Error[] | null; + currentConnection: Connection | null; + alternateConnections: (Connection | EnterpriseConnection)[] | null; } diff --git a/packages/auth0-acul-js/interfaces/models/untrusted-data.ts b/packages/auth0-acul-js/interfaces/models/untrusted-data.ts index 0e3483f..bdfdc61 100644 --- a/packages/auth0-acul-js/interfaces/models/untrusted-data.ts +++ b/packages/auth0-acul-js/interfaces/models/untrusted-data.ts @@ -12,8 +12,8 @@ export interface UntrustedDataContext { } export interface UntrustedDataMembers { - getSubmittedFormData(): { [key: string]: any } | null; - getAuthParams(): { + submittedFormData: { [key: string]: any } | null; + authParams: { loginHint: string | undefined; screenHint: string | undefined; uiLocales: string | undefined; diff --git a/packages/auth0-acul-js/interfaces/models/user.ts b/packages/auth0-acul-js/interfaces/models/user.ts index 94912ee..1741cfb 100644 --- a/packages/auth0-acul-js/interfaces/models/user.ts +++ b/packages/auth0-acul-js/interfaces/models/user.ts @@ -22,8 +22,8 @@ export interface UserMembers { email: string | null; picture: string | null; phoneNumber: string | null; - getEnrolledFactors(): Array | null; - getOrganizations(): + enrolledFactors: Array | null; + organizations: | { organizationId: string | undefined; organizationName: string | undefined; @@ -35,6 +35,6 @@ export interface UserMembers { | undefined; }[] | null; - getUserMetadata(): { [key: string]: string } | null; - getAppMetadata(): { [key: string]: string } | null; + userMetadata: { [key: string]: string } | null; + appMetadata: { [key: string]: string } | null; } diff --git a/packages/auth0-acul-js/interfaces/screens/email-identifier-challenge.ts b/packages/auth0-acul-js/interfaces/screens/email-identifier-challenge.ts index e152b76..ba32f4d 100644 --- a/packages/auth0-acul-js/interfaces/screens/email-identifier-challenge.ts +++ b/packages/auth0-acul-js/interfaces/screens/email-identifier-challenge.ts @@ -9,7 +9,7 @@ export interface EmailChallengeOptions { } export interface ScreenMembersOnEmailIdentifierChallenge extends ScreenMembers { - getScreenData(): { + data: { messageType?: string; email?: string; } | null; diff --git a/packages/auth0-acul-js/interfaces/screens/login-id.ts b/packages/auth0-acul-js/interfaces/screens/login-id.ts index ce15824..0e52b3b 100644 --- a/packages/auth0-acul-js/interfaces/screens/login-id.ts +++ b/packages/auth0-acul-js/interfaces/screens/login-id.ts @@ -30,7 +30,7 @@ export interface LoginId extends BaseContext { export interface ScreenMembersOnLoginId extends ScreenMembers { signupLink: string | null; resetPasswordLink: string | null; - getPublicKey(): PasskeyRead['public_key'] | null; + publicKey: PasskeyRead['public_key'] | null; } export interface TransactionMembersOnLoginId extends TransactionMembers { @@ -38,8 +38,8 @@ export interface TransactionMembersOnLoginId extends TransactionMembers { isPasskeyEnabled: boolean; isForgotPasswordEnabled: boolean; isUsernameRequired: boolean; - getUsernamePolicy(): UsernamePolicy | null; - getAllowedIdentifiers(): ('email' | 'username' | 'phone')[] | null; + usernamePolicy: UsernamePolicy | null; + allowedIdentifiers: ('email' | 'username' | 'phone')[] | null; } export interface LoginOptions { diff --git a/packages/auth0-acul-js/interfaces/screens/login-password.ts b/packages/auth0-acul-js/interfaces/screens/login-password.ts index 13cce19..fb7d4b8 100644 --- a/packages/auth0-acul-js/interfaces/screens/login-password.ts +++ b/packages/auth0-acul-js/interfaces/screens/login-password.ts @@ -14,7 +14,7 @@ export interface ScreenMembersOnLoginPassword extends ScreenMembers { signupLink: string | null; resetPasswordLink: string | null; editIdentifierLink: string | null; - getScreenData(): { + data: { username: string; } | null; } diff --git a/packages/auth0-acul-js/interfaces/screens/login-passwordless-email-code.ts b/packages/auth0-acul-js/interfaces/screens/login-passwordless-email-code.ts index cbe9c8e..fe6535d 100644 --- a/packages/auth0-acul-js/interfaces/screens/login-passwordless-email-code.ts +++ b/packages/auth0-acul-js/interfaces/screens/login-passwordless-email-code.ts @@ -8,7 +8,7 @@ export interface ScreenMembersOnLoginPasswordlessEmailCode extends ScreenMembers editIdentifierLink: string | null; resetPasswordLink: string | null; signupLink: string | null; - getScreenData(): { + data: { email?: string; username?: string; } | null; diff --git a/packages/auth0-acul-js/interfaces/screens/login-passwordless-sms-otp.ts b/packages/auth0-acul-js/interfaces/screens/login-passwordless-sms-otp.ts index 3534d3b..e2ceb37 100644 --- a/packages/auth0-acul-js/interfaces/screens/login-passwordless-sms-otp.ts +++ b/packages/auth0-acul-js/interfaces/screens/login-passwordless-sms-otp.ts @@ -13,6 +13,9 @@ export interface ScreenMembersOnLoginPasswordlessSmsOtp extends ScreenMembers { signupLink: string | null; resetPasswordLink: string | null; backLink: string | null; + data: { + username: string; + } } export interface TransactionMembersOnLoginPasswordlessSmsOtp extends TransactionMembers { diff --git a/packages/auth0-acul-js/interfaces/screens/passkey-enrollment-local.ts b/packages/auth0-acul-js/interfaces/screens/passkey-enrollment-local.ts index 12169e3..58bd7a7 100644 --- a/packages/auth0-acul-js/interfaces/screens/passkey-enrollment-local.ts +++ b/packages/auth0-acul-js/interfaces/screens/passkey-enrollment-local.ts @@ -22,7 +22,7 @@ export interface AbortEnrollmentOptions { } export interface ScreenMembersOnPasskeyEnrollmentLocal extends ScreenMembers { - getPublicKey: () => PasskeyCreate['public_key'] | null; + publicKey: PasskeyCreate['public_key'] | null; } export interface PasskeyEnrollmentLocalMembers extends BaseMembers { diff --git a/packages/auth0-acul-js/interfaces/screens/passkey-enrollment.ts b/packages/auth0-acul-js/interfaces/screens/passkey-enrollment.ts index 2369f1d..7031ef5 100644 --- a/packages/auth0-acul-js/interfaces/screens/passkey-enrollment.ts +++ b/packages/auth0-acul-js/interfaces/screens/passkey-enrollment.ts @@ -19,7 +19,7 @@ export interface PasskeyEnrollment extends BaseContext { export interface ScreenMembersOnPasskeyEnrollment extends ScreenMembers { backLink: string | null; loginLink: string | null; - getPublicKey: () => PasskeyCreate['public_key'] | null; + publicKey: PasskeyCreate['public_key'] | null; } export interface PasskeyEnrollmentMembers extends BaseMembers { diff --git a/packages/auth0-acul-js/interfaces/screens/phone-identifier-challenge.ts b/packages/auth0-acul-js/interfaces/screens/phone-identifier-challenge.ts index f2ef90d..b41fbcc 100644 --- a/packages/auth0-acul-js/interfaces/screens/phone-identifier-challenge.ts +++ b/packages/auth0-acul-js/interfaces/screens/phone-identifier-challenge.ts @@ -21,7 +21,7 @@ export interface ExtendedScreenContext extends ScreenContext { } export interface ScreenMembersOnPhoneIdentifierChallenge extends ScreenMembers { - getScreenData(): { + data: { messageType?: 'text' | 'voice'; phone?: string; } | null; diff --git a/packages/auth0-acul-js/interfaces/screens/phone-identifier-enrollment.ts b/packages/auth0-acul-js/interfaces/screens/phone-identifier-enrollment.ts index d401eb9..3fcdebc 100644 --- a/packages/auth0-acul-js/interfaces/screens/phone-identifier-enrollment.ts +++ b/packages/auth0-acul-js/interfaces/screens/phone-identifier-enrollment.ts @@ -8,9 +8,9 @@ export interface ScreenDataOptions extends ScreenData { } export interface ScreenMembersOnPhoneIdentifierEnrollment extends ScreenMembers { - getScreenData(): { - messageType?: 'text' | 'voice'; + data: { phone?: 'string'; + messageType?: 'text' | 'voice'; } | null; editIdentifierLink: string | null; } diff --git a/packages/auth0-acul-js/interfaces/screens/signup-id.ts b/packages/auth0-acul-js/interfaces/screens/signup-id.ts index 3d72af4..1ee09fb 100644 --- a/packages/auth0-acul-js/interfaces/screens/signup-id.ts +++ b/packages/auth0-acul-js/interfaces/screens/signup-id.ts @@ -24,9 +24,9 @@ export interface ScreenMembersOnSignupId extends ScreenMembers { export interface TransactionMembersOnSignupId extends TransactionMembers { isPasskeyEnabled: boolean; - getUsernamePolicy(): UsernamePolicy | null; - getRequiredIdentifiers(): ('email' | 'username' | 'phone')[] | null; - getOptionalIdentifiers(): ('email' | 'username' | 'phone')[] | null; + usernamePolicy: UsernamePolicy | null; + requiredIdentifiers: ('email' | 'username' | 'phone')[] | null; + optionalIdentifiers: ('email' | 'username' | 'phone')[] | null; } export interface SignupId extends BaseContext { diff --git a/packages/auth0-acul-js/interfaces/screens/signup-password.ts b/packages/auth0-acul-js/interfaces/screens/signup-password.ts index 70f5dab..7f8c3ff 100644 --- a/packages/auth0-acul-js/interfaces/screens/signup-password.ts +++ b/packages/auth0-acul-js/interfaces/screens/signup-password.ts @@ -22,7 +22,7 @@ export interface SignupPassword extends BaseContext { export interface ScreenMembersOnSignupPassword extends ScreenMembers { loginLink: string | null; editLink: string | null; - getScreenData(): { + data: { email?: string; phone?: string; username?: string; @@ -31,9 +31,9 @@ export interface ScreenMembersOnSignupPassword extends ScreenMembers { export interface TransactionMembersOnSignupPassword extends TransactionMembers { isPasskeyEnabled: boolean; - getPasswordPolicy(): PasswordPolicy | null; - getRequiredIdentifiers(): ('email' | 'username' | 'phone')[] | null; - getOptionalIdentifiers(): ('email' | 'username' | 'phone')[] | null; + passwordPolicy: PasswordPolicy | null; + requiredIdentifiers: ('email' | 'username' | 'phone')[] | null; + optionalIdentifiers: ('email' | 'username' | 'phone')[] | null; } export interface SignupPasswordOptions { diff --git a/packages/auth0-acul-js/jest.config.js b/packages/auth0-acul-js/jest.config.js index 83d0832..bef280d 100644 --- a/packages/auth0-acul-js/jest.config.js +++ b/packages/auth0-acul-js/jest.config.js @@ -14,4 +14,12 @@ export default { ], }, roots: ['/tests/unit'], + collectCoverage: true, + coverageDirectory: '/coverage', + coverageReporters: ['text', 'lcov'], + collectCoverageFrom: [ + '**/*.{ts,tsx}', + '!**/node_modules/**', + '!**/tests/**', + ], }; diff --git a/packages/auth0-acul-js/src/models/base-context.ts b/packages/auth0-acul-js/src/models/base-context.ts index 642a216..0a6acef 100644 --- a/packages/auth0-acul-js/src/models/base-context.ts +++ b/packages/auth0-acul-js/src/models/base-context.ts @@ -14,7 +14,6 @@ import type { BaseContext as UniversalLoginContext, BaseMembers } from '../../in import { Branding, Client, Prompt, Screen, Organization, User, Transaction, Tenant, UntrustedData } from '../models'; export class BaseContext implements BaseMembers { - private context: UniversalLoginContext; branding: BrandingMembers; screen: ScreenMembers; tenant: TenantMembers; @@ -25,21 +24,32 @@ export class BaseContext implements BaseMembers { user: UserMembers; untrustedData: UntrustedDataMembers; + private static context: UniversalLoginContext | null = null; + constructor() { - this.context = (window as any).universal_login_context as UniversalLoginContext; - this.branding = new Branding(this.context.branding); - this.screen = new Screen(this.context.screen); - this.tenant = new Tenant(this.context.tenant); - this.prompt = new Prompt(this.context.prompt); - this.organization = new Organization(this.context.organization); - this.client = new Client(this.context.client); - this.transaction = new Transaction(this.context.transaction); - this.user = new User(this.context.user); - this.untrustedData = new UntrustedData(this.context.untrusted_data); + if (!BaseContext.context) { + BaseContext.context = (window as any).universal_login_context as UniversalLoginContext; + } + + const context = BaseContext.context; + + this.branding = new Branding(context.branding); + this.screen = new Screen(context.screen); + this.tenant = new Tenant(context.tenant); + this.prompt = new Prompt(context.prompt); + this.organization = new Organization(context.organization); + this.client = new Client(context.client); + this.transaction = new Transaction(context.transaction); + this.user = new User(context.user); + this.untrustedData = new UntrustedData(context.untrusted_data); } /** @ignore */ getContext(model: K): UniversalLoginContext[K] | undefined { - return this.context[model]; + if (!BaseContext.context) { + BaseContext.context = (window as any).universal_login_context as UniversalLoginContext; + } + + return BaseContext.context[model]; } } diff --git a/packages/auth0-acul-js/src/models/branding.ts b/packages/auth0-acul-js/src/models/branding.ts index 769db82..c761b98 100644 --- a/packages/auth0-acul-js/src/models/branding.ts +++ b/packages/auth0-acul-js/src/models/branding.ts @@ -1,15 +1,15 @@ import type { BrandingContext, BrandingMembers } from '../../interfaces/models/branding'; export class Branding implements BrandingMembers { - private branding: BrandingContext | undefined; + settings: BrandingMembers['settings']; + themes: BrandingMembers['themes']; - constructor(client: BrandingContext | undefined) { - this.branding = client; + constructor(branding: BrandingContext | undefined) { + this.settings = Branding.getSettings(branding); + this.themes = Branding.getThemes(branding); } - getSettings(): ReturnType { - const { branding } = this; - + static getSettings(branding: BrandingContext | undefined): BrandingMembers['settings'] { if (!branding?.settings) return null; const { colors, favicon_url, logo_url, font } = branding.settings; @@ -35,11 +35,11 @@ export class Branding implements BrandingMembers { }; } - getThemes(): ReturnType { - if (!this.branding || !this.branding?.themes) return null; + static getThemes(branding: BrandingContext | undefined): BrandingMembers['themes'] { + if (!branding || !branding?.themes) return null; const { default: { borders = {}, colors = {}, displayName = '', fonts = {}, page_background: pageBackground = {}, widget = {} } = {} } = - this.branding.themes; + branding.themes; return { default: { diff --git a/packages/auth0-acul-js/src/models/client.ts b/packages/auth0-acul-js/src/models/client.ts index 38a001c..dc5b50e 100644 --- a/packages/auth0-acul-js/src/models/client.ts +++ b/packages/auth0-acul-js/src/models/client.ts @@ -1,29 +1,17 @@ import type { ClientContext, ClientMembers } from '../../interfaces/models/client'; export class Client implements ClientMembers { - protected client: ClientContext; + id: ClientMembers['id']; + name: ClientMembers['name']; + logoUri: ClientMembers['logoUri']; + description: ClientMembers['description']; + metadata: ClientMembers['metadata']; constructor(client: ClientContext) { - this.client = client; - } - - get id(): ClientMembers['id'] { - return this.client.id; - } - - get name(): ClientMembers['name'] { - return this.client.name; - } - - get logoUri(): ClientMembers['logoUri'] { - return this.client?.logo_uri ?? null; - } - - get description(): ClientMembers['description'] { - return this.client?.description ?? null; - } - - getMetadata(): ReturnType { - return this.client?.metadata ?? null; + this.id = client.id; + this.name = client.name; + this.logoUri = client?.logo_uri ?? null; + this.description = client?.description ?? null; + this.metadata = client?.metadata ?? null; } } diff --git a/packages/auth0-acul-js/src/models/organization.ts b/packages/auth0-acul-js/src/models/organization.ts index a999f9d..38bc120 100644 --- a/packages/auth0-acul-js/src/models/organization.ts +++ b/packages/auth0-acul-js/src/models/organization.ts @@ -4,33 +4,19 @@ import type { OrganizationContext, OrganizationMembers } from '../../interfaces/ * Represents an organization. */ export class Organization implements OrganizationMembers { - protected organization: OrganizationContext; - - constructor(context: OrganizationContext) { - this.organization = context; - } - - get id(): OrganizationMembers['id'] { - return this.organization.id ?? null; - } - - get name(): OrganizationMembers['name'] { - return this.organization.name ?? null; - } - - get usage(): OrganizationMembers['usage'] { - return this.organization.usage ?? null; - } - - get displayName(): OrganizationMembers['displayName'] { - return this.organization?.display_name ?? null; - } - - getBranding(): ReturnType { - return this.organization?.branding ?? null; - } - - getMetadata(): ReturnType { - return this.organization?.metadata ?? null; + id: OrganizationMembers['id']; + name: OrganizationMembers['name']; + usage: OrganizationMembers['usage']; + displayName: OrganizationMembers['displayName']; + branding: OrganizationMembers['branding']; + metadata: OrganizationMembers['metadata']; + + constructor(organization: OrganizationContext) { + this.id = organization.id ?? null; + this.name = organization.name ?? null; + this.usage = organization.usage ?? null; + this.displayName = organization?.display_name ?? null; + this.branding = organization?.branding ?? null; + this.metadata = organization?.metadata ?? null; } } diff --git a/packages/auth0-acul-js/src/models/prompt.ts b/packages/auth0-acul-js/src/models/prompt.ts index 1c84985..83808fc 100644 --- a/packages/auth0-acul-js/src/models/prompt.ts +++ b/packages/auth0-acul-js/src/models/prompt.ts @@ -1,13 +1,9 @@ import type { PromptContext, PromptMembers } from '../../interfaces/models/prompt'; export class Prompt implements PromptMembers { - protected prompt: PromptContext; + name: PromptMembers['name']; constructor(prompt: PromptContext) { - this.prompt = prompt; - } - - get name(): PromptMembers['name'] { - return this.prompt.name; + this.name = prompt.name; } } diff --git a/packages/auth0-acul-js/src/models/screen.ts b/packages/auth0-acul-js/src/models/screen.ts index 16fa6a5..4ab8533 100644 --- a/packages/auth0-acul-js/src/models/screen.ts +++ b/packages/auth0-acul-js/src/models/screen.ts @@ -1,45 +1,33 @@ import type { ScreenContext, ScreenMembers } from '../../interfaces/models/screen'; export class Screen implements ScreenMembers { - protected screen: ScreenContext; + name: ScreenMembers['name']; + captchaImage: ScreenMembers['captchaImage']; + captchaSiteKey: ScreenMembers['captchaSiteKey']; + captchaProvider: ScreenMembers['captchaProvider']; + isCaptchaAvailable: ScreenMembers['isCaptchaAvailable']; + data: ScreenMembers['data']; + links: ScreenMembers['links']; + texts: ScreenMembers['texts']; + captcha: ScreenMembers['captcha']; constructor(screen: ScreenContext) { - this.screen = screen; + this.name = screen.name; + this.captchaImage = screen.captcha?.image ?? null; + this.captchaSiteKey = screen.captcha?.siteKey ?? null; + this.captchaProvider = screen.captcha?.provider ?? null; + this.isCaptchaAvailable = !!screen.captcha; + this.texts = screen.texts ?? null; + this.captcha = screen.captcha ?? null; + this.data = Screen.getScreenData(screen); + this.links = Screen.getScreenLinks(screen); } - get name(): ScreenMembers['name'] { - return this.screen.name; + static getScreenData(screen: ScreenContext): ScreenMembers['data'] { + return (screen.data ?? null) as ScreenMembers['data']; } - get captchaImage(): ScreenMembers['captchaImage'] { - return this.screen.captcha?.image ?? null; - } - - get captchaSiteKey(): ScreenMembers['captchaSiteKey'] { - return this.screen.captcha?.siteKey ?? null; - } - - get captchaProvider(): ScreenMembers['captchaProvider'] { - return this.screen.captcha?.provider ?? null; - } - - get isCaptchaAvailable(): ScreenMembers['isCaptchaAvailable'] { - return !!this.screen.captcha; - } - - getScreenData(): ReturnType { - return (this.screen.data ?? null) as ReturnType; - } - - getScreenLinks(): ReturnType { - return this.screen.links ?? null; - } - - getScreenTexts(): ReturnType { - return this.screen.texts ?? null; - } - - getCaptchaConfig(): ReturnType { - return this.screen.captcha ?? null; + static getScreenLinks(screen: ScreenContext): ScreenMembers['links'] { + return screen.links ?? null; } } diff --git a/packages/auth0-acul-js/src/models/tenant.ts b/packages/auth0-acul-js/src/models/tenant.ts index 663d73c..d37b0b5 100644 --- a/packages/auth0-acul-js/src/models/tenant.ts +++ b/packages/auth0-acul-js/src/models/tenant.ts @@ -1,25 +1,15 @@ import type { TenantContext, TenantMembers } from '../../interfaces/models/tenant'; export class Tenant implements TenantMembers { - protected tenant: TenantContext | undefined; + name: TenantMembers['name']; + friendlyName: TenantMembers['friendlyName']; + enabledLocales: TenantMembers['enabledLocales']; + enabledFactors: TenantMembers['enabledFactors']; constructor(tenant: TenantContext | undefined) { - this.tenant = tenant; - } - - get name(): TenantMembers['name'] { - return this.tenant?.name ?? null; - } - - get friendlyName(): TenantMembers['friendlyName'] { - return this.tenant?.friendly_name ?? null; - } - - getEnabledLocales(): ReturnType { - return this.tenant?.enabled_locales ?? null; - } - - getEnabledFactors(): ReturnType { - return this.tenant?.enabled_factors ?? null; + this.name = tenant?.name ?? null; + this.friendlyName = tenant?.friendly_name ?? null; + this.enabledLocales = tenant?.enabled_locales ?? null; + this.enabledFactors = tenant?.enabled_factors ?? null; } } diff --git a/packages/auth0-acul-js/src/models/transaction.ts b/packages/auth0-acul-js/src/models/transaction.ts index 2180331..c5fa23e 100644 --- a/packages/auth0-acul-js/src/models/transaction.ts +++ b/packages/auth0-acul-js/src/models/transaction.ts @@ -1,40 +1,32 @@ import type { TransactionContext, TransactionMembers } from '../../interfaces/models/transaction'; export class Transaction implements TransactionMembers { - protected transaction: TransactionContext; - - constructor(context: TransactionContext) { - this.transaction = context; - } - - get state(): TransactionMembers['state'] { - return this.transaction.state; - } - - get hasErrors(): TransactionMembers['hasErrors'] { - return !!this.transaction.errors?.length; - } - - get locale(): TransactionMembers['locale'] { - return this.transaction.locale; - } - - get countryCode(): TransactionMembers['countryCode'] { - return this.transaction.country_code?.code ?? null; - } - - get countryPrefix(): TransactionMembers['countryCode'] { - return this.transaction.country_code?.prefix ?? null; - } - - get connectionStrategy(): TransactionMembers['connectionStrategy'] { - return this.transaction?.connection?.strategy?.toLowerCase() ?? null; + state: TransactionMembers['state']; + hasErrors: TransactionMembers['hasErrors']; + locale: TransactionMembers['locale']; + countryCode: TransactionMembers['countryCode']; + countryPrefix: TransactionMembers['countryCode']; + connectionStrategy: TransactionMembers['connectionStrategy']; + errors: TransactionMembers['errors']; + currentConnection: TransactionMembers['currentConnection']; + alternateConnections: TransactionMembers['alternateConnections']; + + constructor(transaction: TransactionContext) { + this.state = transaction.state; + this.hasErrors = !!transaction.errors?.length; + this.locale = transaction.locale; + this.countryCode = transaction.country_code?.code ?? null; + this.countryPrefix = transaction.country_code?.prefix ?? null; + this.connectionStrategy = transaction?.connection?.strategy?.toLowerCase() ?? null; + this.errors = Transaction.getErrors(transaction); + this.currentConnection = Transaction.getCurrentConnection(transaction); + this.alternateConnections = Transaction.getAlternateConnections(transaction); } - getErrors(): ReturnType { - if (!this.transaction.errors?.length) return null; + static getErrors(transaction: TransactionContext): TransactionMembers['errors'] { + if (!transaction.errors?.length) return null; - return this.transaction.errors.map((error) => { + return transaction.errors.map((error) => { return { code: error.code, field: error.field, @@ -43,10 +35,10 @@ export class Transaction implements TransactionMembers { }); } - getCurrentConnection(): ReturnType { - if (!this.transaction?.connection) return null; + static getCurrentConnection(transaction: TransactionContext): TransactionMembers['currentConnection'] { + if (!transaction?.connection) return null; - const { name, strategy, metadata } = this.transaction.connection; + const { name, strategy, metadata } = transaction.connection; return { name, strategy, @@ -54,8 +46,8 @@ export class Transaction implements TransactionMembers { }; } - getAlternateConnections(): ReturnType { - const alternateConnections = this.transaction.alternate_connections; + static getAlternateConnections(transaction: TransactionContext): TransactionMembers['alternateConnections'] { + const alternateConnections = transaction.alternate_connections; if (!alternateConnections || !Array.isArray(alternateConnections)) return null; return alternateConnections.map((connection) => { diff --git a/packages/auth0-acul-js/src/models/untrusted-data.ts b/packages/auth0-acul-js/src/models/untrusted-data.ts index 79e3657..cb55380 100644 --- a/packages/auth0-acul-js/src/models/untrusted-data.ts +++ b/packages/auth0-acul-js/src/models/untrusted-data.ts @@ -1,25 +1,27 @@ import type { UntrustedDataContext, UntrustedDataMembers } from '../../interfaces/models/untrusted-data'; export class UntrustedData implements UntrustedDataMembers { - private untrustedData: UntrustedDataContext | undefined; + submittedFormData: UntrustedDataMembers['submittedFormData']; + authParams: UntrustedDataMembers['authParams']; constructor(untrustedData: UntrustedDataContext | undefined) { - this.untrustedData = untrustedData; + this.submittedFormData = UntrustedData.getSubmittedFormData(untrustedData); + this.authParams = UntrustedData.getAuthParams(untrustedData); } - getSubmittedFormData(): ReturnType { - if (!this.untrustedData?.submitted_form_data) return null; - return this.untrustedData?.submitted_form_data ?? null; + static getSubmittedFormData(untrustedData: UntrustedDataContext | undefined): UntrustedDataMembers['submittedFormData'] { + if (!untrustedData?.submitted_form_data) return null; + return untrustedData?.submitted_form_data ?? null; } - getAuthParams(): ReturnType { - if (!this.untrustedData?.authorization_params) return null; + static getAuthParams(untrustedData: UntrustedDataContext | undefined): UntrustedDataMembers['authParams'] { + if (!untrustedData?.authorization_params) return null; return { - loginHint: this.untrustedData?.authorization_params?.login_hint, - screenHint: this.untrustedData?.authorization_params?.screen_hint, - uiLocales: this.untrustedData?.authorization_params?.ui_locales, - ext: this.untrustedData?.authorization_params, + loginHint: untrustedData?.authorization_params?.login_hint, + screenHint: untrustedData?.authorization_params?.screen_hint, + uiLocales: untrustedData?.authorization_params?.ui_locales, + ext: untrustedData?.authorization_params, }; } } diff --git a/packages/auth0-acul-js/src/models/user.ts b/packages/auth0-acul-js/src/models/user.ts index 5f998a9..c8da6db 100644 --- a/packages/auth0-acul-js/src/models/user.ts +++ b/packages/auth0-acul-js/src/models/user.ts @@ -1,48 +1,32 @@ import type { UserContext, UserMembers } from '../../interfaces/models/user'; export class User implements UserMembers { - private user: UserContext; + id: UserMembers['id']; + username: UserMembers['username']; + email: UserMembers['email']; + picture: UserMembers['picture']; + phoneNumber: UserMembers['phoneNumber']; + userMetadata: UserMembers['userMetadata']; + appMetadata: UserMembers['appMetadata']; + enrolledFactors: UserMembers['enrolledFactors']; + organizations: UserMembers['organizations']; constructor(user: UserContext) { - this.user = user; + this.id = user?.id ?? null; + this.username = user?.username ?? null; + this.email = user?.email ?? null; + this.picture = user?.picture ?? null; + this.phoneNumber = user?.phone_number ?? null; + this.userMetadata = user?.user_metadata ?? null; + this.appMetadata = user?.app_metadata ?? null; + this.enrolledFactors = user?.enrolled_factors ?? null; + this.organizations = User.getOrganizations(user); } - get id(): UserMembers['id'] { - return this.user?.id ?? null; - } - - get username(): UserMembers['username'] { - return this.user?.username ?? null; - } - - get email(): UserMembers['email'] { - return this.user?.email ?? null; - } - - get picture(): UserMembers['picture'] { - return this.user?.picture ?? null; - } - - get phoneNumber(): UserMembers['phoneNumber'] { - return this.user?.phone_number ?? null; - } - - getUserMetadata(): ReturnType { - return this.user?.user_metadata ?? null; - } - - getAppMetadata(): ReturnType { - return this.user?.app_metadata ?? null; - } - - getEnrolledFactors(): ReturnType { - return this.user?.enrolled_factors ?? null; - } - - getOrganizations(): ReturnType { - if (!this.user?.organizations || !Array.isArray(this.user?.organizations)) return null; + static getOrganizations(user: UserContext): UserMembers['organizations'] { + if (!user?.organizations || !Array.isArray(user?.organizations)) return null; - return this.user?.organizations.map((organization) => { + return user?.organizations.map((organization) => { return { organizationId: organization.id, organizationName: organization.name, diff --git a/packages/auth0-acul-js/src/screens/email-identifier-challenge/index.ts b/packages/auth0-acul-js/src/screens/email-identifier-challenge/index.ts index 7d1548a..6f947ba 100644 --- a/packages/auth0-acul-js/src/screens/email-identifier-challenge/index.ts +++ b/packages/auth0-acul-js/src/screens/email-identifier-challenge/index.ts @@ -63,3 +63,9 @@ export default class EmailIdentifierChallenge extends BaseContext implements Ema await new FormHandler(options).submitData({ ...payload, action: 'back-action' }); } } + +export { + EmailIdentifierChallengeMembers, + EmailChallengeOptions, + ScreenOptions, +} diff --git a/packages/auth0-acul-js/src/screens/email-identifier-challenge/screen-override.ts b/packages/auth0-acul-js/src/screens/email-identifier-challenge/screen-override.ts index 92af72e..8d67119 100644 --- a/packages/auth0-acul-js/src/screens/email-identifier-challenge/screen-override.ts +++ b/packages/auth0-acul-js/src/screens/email-identifier-challenge/screen-override.ts @@ -5,15 +5,17 @@ import { Screen } from '../../models/screen'; export class ScreenOverride extends Screen implements OverrideOptions { constructor(screenContext: ScreenContext) { super(screenContext); + this.data = ScreenOverride.getScreenData(screenContext); } - getScreenData = (): ReturnType => { - const data = super.getScreenData(); - + static getScreenData = (screenContext: ScreenContext): OverrideOptions['data'] => { + const data = screenContext.data; + if (!data) return null; + return { ...data, - email: data?.email, - messageType: data?.message_type, - }; + email: data.email, + messageType: data.message_type, + } as OverrideOptions['data']; }; } diff --git a/packages/auth0-acul-js/src/screens/interstitial-captcha/index.ts b/packages/auth0-acul-js/src/screens/interstitial-captcha/index.ts index c319e5a..e338bf3 100644 --- a/packages/auth0-acul-js/src/screens/interstitial-captcha/index.ts +++ b/packages/auth0-acul-js/src/screens/interstitial-captcha/index.ts @@ -26,3 +26,8 @@ export default class InterstitialCaptcha extends BaseContext implements Intersti await new FormHandler(options).submitData(payload); } } + +export { + InterstitialCaptchaMembers, + SubmitCaptchaOptions +} diff --git a/packages/auth0-acul-js/src/screens/login-id/index.ts b/packages/auth0-acul-js/src/screens/login-id/index.ts index ca37128..72f1f65 100644 --- a/packages/auth0-acul-js/src/screens/login-id/index.ts +++ b/packages/auth0-acul-js/src/screens/login-id/index.ts @@ -91,7 +91,7 @@ export default class LoginId extends BaseContext implements LoginIdMembers { * loginIdManager.passkeyLogin(); */ async passkeyLogin(payload?: CustomOptions): Promise { - const publicKey = this.screen.getPublicKey(); + const publicKey = this.screen.publicKey; if (!publicKey) throw new Error(Errors.PASSKEY_DATA_UNAVAILABLE); const passkey = await getPasskeyCredentials(publicKey); @@ -123,3 +123,9 @@ export default class LoginId extends BaseContext implements LoginIdMembers { }); } } + +export { + LoginIdMembers, + LoginOptions, + SocialLoginOptions, +} diff --git a/packages/auth0-acul-js/src/screens/login-id/screen-override.ts b/packages/auth0-acul-js/src/screens/login-id/screen-override.ts index 98a0181..6e4bc0f 100644 --- a/packages/auth0-acul-js/src/screens/login-id/screen-override.ts +++ b/packages/auth0-acul-js/src/screens/login-id/screen-override.ts @@ -4,11 +4,14 @@ import { Screen } from '../../../src/models/screen'; import { getSignupLink, getResetPasswordLink, getPublicKey } from '../../shared/screen'; export class ScreenOverride extends Screen implements OverrideOptions { + signupLink: OverrideOptions['signupLink']; + resetPasswordLink: OverrideOptions['resetPasswordLink']; + publicKey: OverrideOptions['publicKey']; + constructor(screenContext: ScreenContext) { super(screenContext); + this.signupLink = getSignupLink(screenContext); + this.resetPasswordLink = getResetPasswordLink(screenContext); + this.publicKey = getPublicKey(screenContext) as OverrideOptions['publicKey']; } - - signupLink = getSignupLink(this.screen); - resetPasswordLink = getResetPasswordLink(this.screen); - getPublicKey = (): ReturnType => getPublicKey(this.screen); } diff --git a/packages/auth0-acul-js/src/screens/login-id/transaction-override.ts b/packages/auth0-acul-js/src/screens/login-id/transaction-override.ts index cc2227e..c22ceff 100644 --- a/packages/auth0-acul-js/src/screens/login-id/transaction-override.ts +++ b/packages/auth0-acul-js/src/screens/login-id/transaction-override.ts @@ -11,18 +11,29 @@ import { } from '../../shared/transaction'; export class TransactionOverride extends Transaction implements OverrideMembers { + isSignupEnabled: OverrideMembers['isSignupEnabled']; + isForgotPasswordEnabled: OverrideMembers['isForgotPasswordEnabled']; + isPasskeyEnabled: OverrideMembers['isPasskeyEnabled']; + isUsernameRequired: OverrideMembers['isUsernameRequired']; + usernamePolicy: OverrideMembers['usernamePolicy']; + allowedIdentifiers: OverrideMembers['allowedIdentifiers']; + constructor(transactionContext: TransactionContext) { super(transactionContext); + this.isSignupEnabled = isSignupEnabled(transactionContext); + this.isForgotPasswordEnabled = isForgotPasswordEnabled(transactionContext); + this.isPasskeyEnabled = isPasskeyEnabled(transactionContext); + this.isUsernameRequired = isUsernameRequired(transactionContext); + this.usernamePolicy = getUsernamePolicy(transactionContext); + this.allowedIdentifiers = TransactionOverride.getAllowedIdentifiers(transactionContext, this.connectionStrategy); } - isSignupEnabled = isSignupEnabled(this.transaction); - isForgotPasswordEnabled = isForgotPasswordEnabled(this.transaction); - isPasskeyEnabled = isPasskeyEnabled(this.transaction); - isUsernameRequired = isUsernameRequired(this.transaction); - getUsernamePolicy = (): ReturnType => getUsernamePolicy(this.transaction); - getAllowedIdentifiers = (): ReturnType => { - if (this.connectionStrategy === 'sms') return ['phone']; - if (this.connectionStrategy === 'email') return ['email']; - return getAllowedIdentifiers(this.transaction); - }; + static getAllowedIdentifiers( + transactionContext: TransactionContext, + connectionStrategy: string | null + ): OverrideMembers['allowedIdentifiers'] { + if (connectionStrategy === 'sms') return ['phone']; + if (connectionStrategy === 'email') return ['email']; + return getAllowedIdentifiers(transactionContext); + } } diff --git a/packages/auth0-acul-js/src/screens/login-password/index.ts b/packages/auth0-acul-js/src/screens/login-password/index.ts index 68bf01a..c63efdb 100644 --- a/packages/auth0-acul-js/src/screens/login-password/index.ts +++ b/packages/auth0-acul-js/src/screens/login-password/index.ts @@ -42,3 +42,8 @@ export default class LoginPassword extends BaseContext implements LoginPasswordM await new FormHandler(options).submitData(payload); } } + +export { + LoginPasswordMembers, + LoginPasswordOptions +} diff --git a/packages/auth0-acul-js/src/screens/login-password/screen-override.ts b/packages/auth0-acul-js/src/screens/login-password/screen-override.ts index 2cdbada..5c55de1 100644 --- a/packages/auth0-acul-js/src/screens/login-password/screen-override.ts +++ b/packages/auth0-acul-js/src/screens/login-password/screen-override.ts @@ -4,13 +4,16 @@ import { Screen } from '../../models/screen'; import { getSignupLink, getResetPasswordLink, getEditIdentifierLink } from '../../shared/screen'; export class ScreenOverride extends Screen implements OverrideOptions { + signupLink: OverrideOptions['signupLink']; + resetPasswordLink: OverrideOptions['resetPasswordLink']; + editIdentifierLink: OverrideOptions['editIdentifierLink']; + data: OverrideOptions['data']; + constructor(screenContext: ScreenContext) { super(screenContext); + this.signupLink = getSignupLink(screenContext); + this.resetPasswordLink = getResetPasswordLink(screenContext); + this.editIdentifierLink = getEditIdentifierLink(screenContext); + this.data = Screen.getScreenData(screenContext) as OverrideOptions['data']; } - - signupLink = getSignupLink(this.screen); - resetPasswordLink = getResetPasswordLink(this.screen); - editIdentifierLink = getEditIdentifierLink(this.screen); - - getScreenData = super.getScreenData.bind(this) as OverrideOptions['getScreenData']; } diff --git a/packages/auth0-acul-js/src/screens/login-passwordless-email-code/index.ts b/packages/auth0-acul-js/src/screens/login-passwordless-email-code/index.ts index 4088145..2a33845 100644 --- a/packages/auth0-acul-js/src/screens/login-passwordless-email-code/index.ts +++ b/packages/auth0-acul-js/src/screens/login-passwordless-email-code/index.ts @@ -62,3 +62,8 @@ export default class LoginPasswordlessEmailCode extends BaseContext implements L await new FormHandler(options).submitData({ ...payload, action: 'resend' }); } } + +export { + LoginPasswordlessEmailCodeMembers, + SubmitCodeOptions +} diff --git a/packages/auth0-acul-js/src/screens/login-passwordless-email-code/screen-override.ts b/packages/auth0-acul-js/src/screens/login-passwordless-email-code/screen-override.ts index 7b2dd06..e90eda0 100644 --- a/packages/auth0-acul-js/src/screens/login-passwordless-email-code/screen-override.ts +++ b/packages/auth0-acul-js/src/screens/login-passwordless-email-code/screen-override.ts @@ -4,13 +4,16 @@ import { Screen } from '../../models/screen'; import { getSignupLink, getResetPasswordLink, getEditIdentifierLink } from '../../shared/screen'; export class ScreenOverride extends Screen implements OverrideOptions { + signupLink: OverrideOptions['signupLink']; + resetPasswordLink: OverrideOptions['resetPasswordLink']; + editIdentifierLink: OverrideOptions['editIdentifierLink']; + data: OverrideOptions['data']; + constructor(screenContext: ScreenContext) { super(screenContext); + this.signupLink = getSignupLink(screenContext); + this.resetPasswordLink = getResetPasswordLink(screenContext); + this.editIdentifierLink = getEditIdentifierLink(screenContext); + this.data = Screen.getScreenData(screenContext) as OverrideOptions['data']; } - - signupLink = getSignupLink(this.screen); - resetPasswordLink = getResetPasswordLink(this.screen); - editIdentifierLink = getEditIdentifierLink(this.screen); - - getScreenData = super.getScreenData.bind(this) as OverrideOptions['getScreenData']; } diff --git a/packages/auth0-acul-js/src/screens/login-passwordless-email-code/transaction-override.ts b/packages/auth0-acul-js/src/screens/login-passwordless-email-code/transaction-override.ts index 49ded29..e927673 100644 --- a/packages/auth0-acul-js/src/screens/login-passwordless-email-code/transaction-override.ts +++ b/packages/auth0-acul-js/src/screens/login-passwordless-email-code/transaction-override.ts @@ -4,9 +4,10 @@ import { Transaction } from '../../models/transaction'; import { isSignupEnabled } from '../../shared/transaction'; export class TransactionOverride extends Transaction implements OverrideOptions { + isSignupEnabled: OverrideOptions['isSignupEnabled']; + constructor(transactionContext: TransactionContext) { super(transactionContext); + this.isSignupEnabled = isSignupEnabled(transactionContext); } - - isSignupEnabled = isSignupEnabled(this.transaction); } diff --git a/packages/auth0-acul-js/src/screens/login-passwordless-sms-otp/index.ts b/packages/auth0-acul-js/src/screens/login-passwordless-sms-otp/index.ts index 67dc333..74268d9 100644 --- a/packages/auth0-acul-js/src/screens/login-passwordless-sms-otp/index.ts +++ b/packages/auth0-acul-js/src/screens/login-passwordless-sms-otp/index.ts @@ -59,3 +59,8 @@ export default class LoginPasswordlessSmsOtp extends BaseContext implements Logi await new FormHandler(options).submitData({ ...payload, action: 'resend' }); } } + +export { + LoginPasswordlessSmsOtpMembers, + SubmitOTPOptions, +} diff --git a/packages/auth0-acul-js/src/screens/login-passwordless-sms-otp/screen-override.ts b/packages/auth0-acul-js/src/screens/login-passwordless-sms-otp/screen-override.ts index ac557fe..404df1b 100644 --- a/packages/auth0-acul-js/src/screens/login-passwordless-sms-otp/screen-override.ts +++ b/packages/auth0-acul-js/src/screens/login-passwordless-sms-otp/screen-override.ts @@ -4,12 +4,16 @@ import { Screen } from '../../models/screen'; import { getSignupLink, getResetPasswordLink, getBackLink } from '../../shared/screen'; export class ScreenOverride extends Screen implements OverrideOptions { + signupLink: OverrideOptions['signupLink']; + resetPasswordLink: OverrideOptions['resetPasswordLink']; + backLink: OverrideOptions['backLink']; + data: OverrideOptions['data']; + constructor(screenContext: ScreenContext) { super(screenContext); - } - - signupLink = getSignupLink(this.screen); - resetPasswordLink = getResetPasswordLink(this.screen); - backLink = getBackLink(this.screen); - getScreenData = super.getScreenData.bind(this) as OverrideOptions['getScreenData']; + this.signupLink = getSignupLink(screenContext); + this.resetPasswordLink = getResetPasswordLink(screenContext); + this.backLink = getBackLink(screenContext); + this.data = Screen.getScreenData(screenContext) as OverrideOptions['data']; + } } diff --git a/packages/auth0-acul-js/src/screens/login-passwordless-sms-otp/transaction-override.ts b/packages/auth0-acul-js/src/screens/login-passwordless-sms-otp/transaction-override.ts index 18ca95c..5bbbb79 100644 --- a/packages/auth0-acul-js/src/screens/login-passwordless-sms-otp/transaction-override.ts +++ b/packages/auth0-acul-js/src/screens/login-passwordless-sms-otp/transaction-override.ts @@ -4,9 +4,10 @@ import { Transaction } from '../../models/transaction'; import { isSignupEnabled } from '../../shared/transaction'; export class TransactionOverride extends Transaction implements OverrideOptions { + isSignupEnabled: OverrideOptions['isSignupEnabled']; + constructor(transactionContext: TransactionContext) { super(transactionContext); + this.isSignupEnabled = isSignupEnabled(transactionContext); } - - isSignupEnabled = isSignupEnabled(this.transaction); } diff --git a/packages/auth0-acul-js/src/screens/passkey-enrollment-local/index.ts b/packages/auth0-acul-js/src/screens/passkey-enrollment-local/index.ts index 1782502..560b0ae 100644 --- a/packages/auth0-acul-js/src/screens/passkey-enrollment-local/index.ts +++ b/packages/auth0-acul-js/src/screens/passkey-enrollment-local/index.ts @@ -34,7 +34,7 @@ export default class PasskeyEnrollmentLocal extends BaseContext implements Passk state: this.transaction.state, }; - const publicKey = this.screen.getPublicKey(); + const publicKey = this.screen.publicKey; const encoded = publicKey && createPasskeyCredentials(publicKey); await new FormHandler(options).submitData({ ...payload, passkey: JSON.stringify(encoded) }); @@ -61,3 +61,8 @@ export default class PasskeyEnrollmentLocal extends BaseContext implements Passk await new FormHandler(options).submitData({ ...payload, action: 'abort-passkey-enrollment', ...userActions }); } } + +export { + PasskeyEnrollmentLocalMembers, + AbortEnrollmentOptions +} diff --git a/packages/auth0-acul-js/src/screens/passkey-enrollment-local/screen-override.ts b/packages/auth0-acul-js/src/screens/passkey-enrollment-local/screen-override.ts index b89ca6b..5955c22 100644 --- a/packages/auth0-acul-js/src/screens/passkey-enrollment-local/screen-override.ts +++ b/packages/auth0-acul-js/src/screens/passkey-enrollment-local/screen-override.ts @@ -4,11 +4,10 @@ import { Screen } from '../../models/screen'; import { getPublicKey } from '../../shared/screen'; export class ScreenOverride extends Screen implements OverrideOptions { + publicKey: OverrideOptions['publicKey']; + constructor(screenContext: ScreenContext) { super(screenContext); + this.publicKey = getPublicKey(screenContext) as OverrideOptions['publicKey']; } - - getPublicKey = (): ReturnType => { - return getPublicKey(this.screen) as ReturnType; - }; } diff --git a/packages/auth0-acul-js/src/screens/passkey-enrollment/index.ts b/packages/auth0-acul-js/src/screens/passkey-enrollment/index.ts index f7af5a7..4263a9c 100644 --- a/packages/auth0-acul-js/src/screens/passkey-enrollment/index.ts +++ b/packages/auth0-acul-js/src/screens/passkey-enrollment/index.ts @@ -30,7 +30,7 @@ export default class PasskeyEnrollment extends BaseContext implements PasskeyEnr state: this.transaction.state, }; - const publicKey = this.screen.getPublicKey(); + const publicKey = this.screen.publicKey; const encoded = publicKey && createPasskeyCredentials(publicKey); await new FormHandler(options).submitData({ ...payload, passkey: JSON.stringify(encoded) }); @@ -51,3 +51,7 @@ export default class PasskeyEnrollment extends BaseContext implements PasskeyEnr await new FormHandler(options).submitData({ ...payload, action: 'abort-passkey-enrollment' }); } } + +export { + PasskeyEnrollmentMembers +} diff --git a/packages/auth0-acul-js/src/screens/passkey-enrollment/screen-override.ts b/packages/auth0-acul-js/src/screens/passkey-enrollment/screen-override.ts index 4a336c7..f6ab082 100644 --- a/packages/auth0-acul-js/src/screens/passkey-enrollment/screen-override.ts +++ b/packages/auth0-acul-js/src/screens/passkey-enrollment/screen-override.ts @@ -4,13 +4,19 @@ import { Screen } from '../../models/screen'; import { getBackLink, getLoginLink, getPublicKey } from '../../shared/screen'; export class ScreenOverride extends Screen implements OverrideOptions { + loginLink: OverrideOptions['loginLink']; + backLink: OverrideOptions['backLink']; + publicKey: OverrideOptions['publicKey']; + constructor(screenContext: ScreenContext) { super(screenContext); + + this.loginLink = getLoginLink(screenContext); + this.backLink = getBackLink(screenContext); + this.publicKey = ScreenOverride.getPublicKey(screenContext); } - loginLink = getLoginLink(this.screen); - backLink = getBackLink(this.screen); - getPublicKey = (): ReturnType => { - return getPublicKey(this.screen) as ReturnType; + static getPublicKey = (screenContext: ScreenContext): OverrideOptions['publicKey'] => { + return getPublicKey(screenContext) as OverrideOptions['publicKey']; }; } diff --git a/packages/auth0-acul-js/src/screens/phone-identifier-challenge/index.ts b/packages/auth0-acul-js/src/screens/phone-identifier-challenge/index.ts index b29ff7e..7d7a6a9 100644 --- a/packages/auth0-acul-js/src/screens/phone-identifier-challenge/index.ts +++ b/packages/auth0-acul-js/src/screens/phone-identifier-challenge/index.ts @@ -64,3 +64,8 @@ export default class PhoneIdentifierChallenge extends BaseContext implements Pho await new FormHandler(options).submitData({ ...payload, action: 'back-action' }); } } + +export { + PhoneIdentifierChallengeMembers, + PhoneChallengeOptions, +} diff --git a/packages/auth0-acul-js/src/screens/phone-identifier-challenge/screen-override.ts b/packages/auth0-acul-js/src/screens/phone-identifier-challenge/screen-override.ts index d19de0d..2716fce 100644 --- a/packages/auth0-acul-js/src/screens/phone-identifier-challenge/screen-override.ts +++ b/packages/auth0-acul-js/src/screens/phone-identifier-challenge/screen-override.ts @@ -3,17 +3,22 @@ import type { ScreenMembersOnPhoneIdentifierChallenge as OverrideOptions } from import { Screen } from '../../models/screen'; export class ScreenOverride extends Screen implements OverrideOptions { + data: OverrideOptions['data']; + constructor(screenContext: ScreenContext) { super(screenContext); + this.data = ScreenOverride.getScreenData(screenContext); } - getScreenData = (): ReturnType => { - const data = super.getScreenData(); + static getScreenData(screenContext: ScreenContext): OverrideOptions['data'] { + const data = screenContext.data; + + if (!data) return null; return { ...data, phone: data?.phone_number, messageType: data?.message_type, - } as ReturnType; - }; + } as OverrideOptions['data']; + } } diff --git a/packages/auth0-acul-js/src/screens/phone-identifier-enrollment/index.ts b/packages/auth0-acul-js/src/screens/phone-identifier-enrollment/index.ts index 67a42a1..6413e09 100644 --- a/packages/auth0-acul-js/src/screens/phone-identifier-enrollment/index.ts +++ b/packages/auth0-acul-js/src/screens/phone-identifier-enrollment/index.ts @@ -51,3 +51,8 @@ export default class PhoneIdentifierEnrollment extends BaseContext implements Ph await new FormHandler(options).submitData({ ...payload, action: 'back-action' }); } } + +export { + PhoneIdentifierEnrollmentMembers, + PhoneEnrollmentOptions +} diff --git a/packages/auth0-acul-js/src/screens/phone-identifier-enrollment/screen-override.ts b/packages/auth0-acul-js/src/screens/phone-identifier-enrollment/screen-override.ts index 580afd0..f6da0e3 100644 --- a/packages/auth0-acul-js/src/screens/phone-identifier-enrollment/screen-override.ts +++ b/packages/auth0-acul-js/src/screens/phone-identifier-enrollment/screen-override.ts @@ -4,19 +4,23 @@ import { getEditIdentifierLink } from '../../../src/shared/screen'; import { Screen } from '../../models/screen'; export class ScreenOverride extends Screen implements OverrideOptions { + editIdentifierLink: OverrideOptions['editIdentifierLink']; + data: OverrideOptions['data']; + constructor(screenContext: ScreenContext) { super(screenContext); + this.editIdentifierLink = getEditIdentifierLink(screenContext); + this.data = ScreenOverride.getScreenData(screenContext); } - editIdentifierLink = getEditIdentifierLink(this.screen); - - getScreenData = (): ReturnType => { - const data = super.getScreenData(); - + static getScreenData(screenContext: ScreenContext): OverrideOptions['data'] { + const data = screenContext.data; + if (!data) return null; + return { ...data, phone: data?.phone_number, messageType: data?.message_type, - } as ReturnType; - }; -} + } as OverrideOptions['data']; + } +} \ No newline at end of file diff --git a/packages/auth0-acul-js/src/screens/signup-id/index.ts b/packages/auth0-acul-js/src/screens/signup-id/index.ts index ad9f4ac..7c48a1a 100644 --- a/packages/auth0-acul-js/src/screens/signup-id/index.ts +++ b/packages/auth0-acul-js/src/screens/signup-id/index.ts @@ -54,7 +54,7 @@ export default class SignupId extends BaseContext implements SignupIdMembers { state: this.transaction.state, }; - const activeIdentifiers = this.transaction.getRequiredIdentifiers() || []; + const activeIdentifiers = this.transaction.requiredIdentifiers || []; const missingParameters = activeIdentifiers.filter((param) => !Object.keys(payload).includes(param)); if (missingParameters.length) { throw new Error(`Missing parameter(s): ${missingParameters.join(', ')}`); @@ -95,3 +95,9 @@ export default class SignupId extends BaseContext implements SignupIdMembers { await new FormHandler(options).submitData(payload); } } + +export { + SignupIdMembers, + SignupOptions, + SocialSignupOptions +} diff --git a/packages/auth0-acul-js/src/screens/signup-id/screen-override.ts b/packages/auth0-acul-js/src/screens/signup-id/screen-override.ts index f4830fd..6a2c9ff 100644 --- a/packages/auth0-acul-js/src/screens/signup-id/screen-override.ts +++ b/packages/auth0-acul-js/src/screens/signup-id/screen-override.ts @@ -4,9 +4,10 @@ import { getLoginLink } from '../../../src/shared/screen'; import { Screen } from '../../models/screen'; export class ScreenOverride extends Screen implements OverrideOptions { + loginLink: OverrideOptions['loginLink']; + constructor(screenContext: ScreenContext) { super(screenContext); + this.loginLink = getLoginLink(screenContext); } - - loginLink = getLoginLink(this.screen); } diff --git a/packages/auth0-acul-js/src/screens/signup-id/transaction-override.ts b/packages/auth0-acul-js/src/screens/signup-id/transaction-override.ts index 6b473d9..e50f104 100644 --- a/packages/auth0-acul-js/src/screens/signup-id/transaction-override.ts +++ b/packages/auth0-acul-js/src/screens/signup-id/transaction-override.ts @@ -1,19 +1,33 @@ import type { TransactionContext } from '../../../interfaces/models/transaction'; import type { TransactionMembersOnSignupId as OverrideOptions } from '../../../interfaces/screens/signup-id'; import { Transaction } from '../../models/transaction'; -import { isPasskeyEnabled, getUsernamePolicy, getRequiredIdentifiers, getOptionalIdentifiers } from '../../shared/transaction'; +import { + isPasskeyEnabled, + getUsernamePolicy, + getRequiredIdentifiers, + getOptionalIdentifiers, +} from '../../shared/transaction'; export class TransactionOverride extends Transaction implements OverrideOptions { + isPasskeyEnabled: OverrideOptions['isPasskeyEnabled']; + usernamePolicy: OverrideOptions['usernamePolicy']; + optionalIdentifiers: OverrideOptions['optionalIdentifiers']; + requiredIdentifiers: OverrideOptions['requiredIdentifiers']; + constructor(transactionContext: TransactionContext) { super(transactionContext); + this.isPasskeyEnabled = isPasskeyEnabled(transactionContext); + this.usernamePolicy = getUsernamePolicy(transactionContext); + this.optionalIdentifiers = getOptionalIdentifiers(transactionContext); + this.requiredIdentifiers = TransactionOverride.getRequiredIdentifiers(transactionContext, this.connectionStrategy); } - isPasskeyEnabled = isPasskeyEnabled(this.transaction); - getUsernamePolicy = (): ReturnType => getUsernamePolicy(this.transaction); - getOptionalIdentifiers = (): ReturnType => getOptionalIdentifiers(this.transaction); - getRequiredIdentifiers = (): ReturnType => { - if (this.connectionStrategy === 'sms') return ['phone']; - if (this.connectionStrategy === 'email') return ['email']; - return getRequiredIdentifiers(this.transaction); - }; + static getRequiredIdentifiers( + transactionContext: TransactionContext, + connectionStrategy: string | null + ): OverrideOptions['requiredIdentifiers'] { + if (connectionStrategy === 'sms') return ['phone']; + if (connectionStrategy === 'email') return ['email']; + return getRequiredIdentifiers(transactionContext); + } } diff --git a/packages/auth0-acul-js/src/screens/signup-password/index.ts b/packages/auth0-acul-js/src/screens/signup-password/index.ts index 0fbc95a..9c40c1a 100644 --- a/packages/auth0-acul-js/src/screens/signup-password/index.ts +++ b/packages/auth0-acul-js/src/screens/signup-password/index.ts @@ -65,3 +65,8 @@ export default class SignupPassword extends BaseContext implements SignupPasswor await new FormHandler(options).submitData(payload); } } + +export { + SignupPasswordMembers, + SignupPasswordOptions +} diff --git a/packages/auth0-acul-js/src/screens/signup-password/screen-override.ts b/packages/auth0-acul-js/src/screens/signup-password/screen-override.ts index 25b75c8..243a0d3 100644 --- a/packages/auth0-acul-js/src/screens/signup-password/screen-override.ts +++ b/packages/auth0-acul-js/src/screens/signup-password/screen-override.ts @@ -1,14 +1,16 @@ -import type { ScreenContextOnSignupPassword } from '../../../interfaces/screens/signup-password'; +import type { ScreenContextOnSignupPassword, ScreenMembersOnSignupPassword as OverrideOptions } from '../../../interfaces/screens/signup-password'; import { Screen } from '../../models/screen'; import { getLoginLink, getEditIdentifierLink } from '../../shared/screen'; -export class ScreenOverride extends Screen { - loginLink = getLoginLink(this.screen); - editLink = getEditIdentifierLink(this.screen); +export class ScreenOverride extends Screen implements OverrideOptions { + loginLink: OverrideOptions['loginLink']; + editLink: OverrideOptions['editLink']; + data: OverrideOptions['data']; constructor(screenContext: ScreenContextOnSignupPassword) { super(screenContext); + this.loginLink = getLoginLink(screenContext); + this.editLink = getEditIdentifierLink(screenContext); + this.data = Screen.getScreenData(screenContext); } - - getScreenData = super.getScreenData.bind(this); } diff --git a/packages/auth0-acul-js/src/screens/signup-password/transaction-override.ts b/packages/auth0-acul-js/src/screens/signup-password/transaction-override.ts index 4f2cd68..b03d5c1 100644 --- a/packages/auth0-acul-js/src/screens/signup-password/transaction-override.ts +++ b/packages/auth0-acul-js/src/screens/signup-password/transaction-override.ts @@ -1,19 +1,33 @@ import type { TransactionContext } from '../../../interfaces/models/transaction'; import type { TransactionMembersOnSignupPassword as OverrideOptions } from '../../../interfaces/screens/signup-password'; import { Transaction } from '../../models/transaction'; -import { isPasskeyEnabled, getPasswordPolicy, getRequiredIdentifiers, getOptionalIdentifiers } from '../../shared/transaction'; +import { + isPasskeyEnabled, + getPasswordPolicy, + getRequiredIdentifiers, + getOptionalIdentifiers, +} from '../../shared/transaction'; export class TransactionOverride extends Transaction implements OverrideOptions { + isPasskeyEnabled: OverrideOptions['isPasskeyEnabled']; + passwordPolicy: OverrideOptions['passwordPolicy']; + optionalIdentifiers: OverrideOptions['optionalIdentifiers']; + requiredIdentifiers: OverrideOptions['requiredIdentifiers']; + constructor(transactionContext: TransactionContext) { super(transactionContext); + this.isPasskeyEnabled = isPasskeyEnabled(transactionContext); + this.passwordPolicy = getPasswordPolicy(transactionContext); + this.optionalIdentifiers = getOptionalIdentifiers(transactionContext); + this.requiredIdentifiers = TransactionOverride.getRequiredIdentifiers(transactionContext, this.connectionStrategy); } - isPasskeyEnabled = isPasskeyEnabled(this.transaction); - getPasswordPolicy = (): ReturnType => getPasswordPolicy(this.transaction); - getOptionalIdentifiers = (): ReturnType => getOptionalIdentifiers(this.transaction); - getRequiredIdentifiers = (): ReturnType => { - if (this.connectionStrategy === 'sms') return ['phone']; - if (this.connectionStrategy === 'email') return ['email']; - return getRequiredIdentifiers(this.transaction); - }; + static getRequiredIdentifiers( + transactionContext: TransactionContext, + connectionStrategy: string | null + ): OverrideOptions['requiredIdentifiers'] { + if (connectionStrategy === 'sms') return ['phone']; + if (connectionStrategy === 'email') return ['email']; + return getRequiredIdentifiers(transactionContext); + } } diff --git a/packages/auth0-acul-js/src/shared/transaction.ts b/packages/auth0-acul-js/src/shared/transaction.ts index 13a8139..f0141d1 100644 --- a/packages/auth0-acul-js/src/shared/transaction.ts +++ b/packages/auth0-acul-js/src/shared/transaction.ts @@ -55,8 +55,8 @@ export function getPasswordPolicy(transaction: TransactionContext) { }; } -export function getAllowedIdentifiers(transaction: TransactionContext): ReturnType { - const identifiers: ReturnType = []; +export function getAllowedIdentifiers(transaction: TransactionContext): TransactionMembersOnLoginId['allowedIdentifiers'] { + const identifiers: TransactionMembersOnLoginId['allowedIdentifiers'] = []; const connection = transaction?.connection as DBConnection; @@ -79,7 +79,7 @@ export function getRequiredIdentifiers(transaction: TransactionContext) { return getIdentifiersByStatus(transaction, 'required'); } -export function getOptionalIdentifiers(transaction: TransactionContext): ReturnType { +export function getOptionalIdentifiers(transaction: TransactionContext): TransactionMembersOnSignupId['optionalIdentifiers'] { return getIdentifiersByStatus(transaction, 'optional'); } diff --git a/packages/auth0-acul-js/tests/unit/models/client.test.ts b/packages/auth0-acul-js/tests/unit/models/client.test.ts index 6f40ab9..551e071 100644 --- a/packages/auth0-acul-js/tests/unit/models/client.test.ts +++ b/packages/auth0-acul-js/tests/unit/models/client.test.ts @@ -38,7 +38,7 @@ describe(':: models/client | when all fields are available', () => { }); it('should return the correct clientMetadata', () => { - expect(client.getMetadata()).toEqual(clientContext.metadata); + expect(client.metadata).toEqual(clientContext.metadata); }); }); @@ -63,6 +63,6 @@ describe(':: models/client | when optional fields are not available', () => { }); it('should return undefined for clientMetadata if not available', () => { - expect(client.getMetadata()).toBeNull(); + expect(client.metadata).toBeNull(); }); }); \ No newline at end of file diff --git a/packages/auth0-acul-js/tests/unit/models/organization.test.ts b/packages/auth0-acul-js/tests/unit/models/organization.test.ts index 1930f40..8f66bb9 100644 --- a/packages/auth0-acul-js/tests/unit/models/organization.test.ts +++ b/packages/auth0-acul-js/tests/unit/models/organization.test.ts @@ -44,11 +44,11 @@ describe(':: models/organization | when all fields are available', () => { }); it('should return the correct branding', () => { - expect(organization.getBranding()).toEqual(organizationContext.branding); + expect(organization.branding).toEqual(organizationContext.branding); }); it('should return the correct metadata', () => { - expect(organization.getMetadata()).toEqual(organizationContext.metadata); + expect(organization.metadata).toEqual(organizationContext.metadata); }); }); @@ -66,11 +66,11 @@ describe(':: models/organization | when optional fields are not available', () = }); it('should return null for branding if not available', () => { - expect(organization.getBranding()).toBeNull(); + expect(organization.branding).toBeNull(); }); it('should return null for metadata if not available', () => { - expect(organization.getMetadata()).toBeNull(); + expect(organization.metadata).toBeNull(); }); it('should return null for display name if not available', () => { diff --git a/packages/auth0-acul-js/tests/unit/models/screen.test.ts b/packages/auth0-acul-js/tests/unit/models/screen.test.ts index 823ade7..0897647 100644 --- a/packages/auth0-acul-js/tests/unit/models/screen.test.ts +++ b/packages/auth0-acul-js/tests/unit/models/screen.test.ts @@ -48,19 +48,19 @@ describe(':: models/screen | when all fields are available', () => { }); it('should return the correct screen data', () => { - expect(screen.getScreenData()).toEqual(screenContext.data); + expect(screen.data).toEqual(screenContext.data); }); it('should return the correct screen links', () => { - expect(screen.getScreenLinks()).toEqual(screenContext.links); + expect(screen.links).toEqual(screenContext.links); }); it('should return the correct screen texts', () => { - expect(screen.getScreenTexts()).toEqual(screenContext.texts); + expect(screen.texts).toEqual(screenContext.texts); }); it('should return the correct captcha configuration', () => { - expect(screen.getCaptchaConfig()).toEqual(screenContext.captcha); + expect(screen.captcha).toEqual(screenContext.captcha); }); }); @@ -92,18 +92,18 @@ describe(':: models/screen | when optional fields are not available', () => { }); it('should return null for screenData if not available', () => { - expect(screen.getScreenData()).toBeNull(); + expect(screen.data).toBeNull(); }); it('should return null for screenLinks if not available', () => { - expect(screen.getScreenLinks()).toBeNull(); + expect(screen.links).toBeNull(); }); it('should return null for screenTexts if not available', () => { - expect(screen.getScreenTexts()).toBeNull(); + expect(screen.texts).toBeNull(); }); it('should return null for captchaConfig if not available', () => { - expect(screen.getCaptchaConfig()).toBeNull(); + expect(screen.captcha).toBeNull(); }); }); diff --git a/packages/auth0-acul-js/tests/unit/models/tenant.test.ts b/packages/auth0-acul-js/tests/unit/models/tenant.test.ts index 49581bb..3c6b19b 100644 --- a/packages/auth0-acul-js/tests/unit/models/tenant.test.ts +++ b/packages/auth0-acul-js/tests/unit/models/tenant.test.ts @@ -25,11 +25,11 @@ describe(':: models/tenant | when all fields are available', () => { }); it('should return the correct enabled locales', () => { - expect(tenant.getEnabledLocales()).toEqual(tenantContext.enabled_locales); + expect(tenant.enabledLocales).toEqual(tenantContext.enabled_locales); }); it('should return the correct enabled factors', () => { - expect(tenant.getEnabledFactors()).toEqual(tenantContext.enabled_factors); + expect(tenant.enabledFactors).toEqual(tenantContext.enabled_factors); }); }); @@ -51,10 +51,10 @@ describe(':: models/tenant | when optional fields are not available', () => { }); it('should return null for enabled locales if not available', () => { - expect(tenant.getEnabledLocales()).toBeNull(); + expect(tenant.enabledLocales).toBeNull(); }); it('should return null for enabled factors if not available', () => { - expect(tenant.getEnabledFactors()).toBeNull(); + expect(tenant.enabledFactors).toBeNull(); }); }); diff --git a/packages/auth0-acul-js/tests/unit/models/user.test.ts b/packages/auth0-acul-js/tests/unit/models/user.test.ts index b0de561..058afa4 100644 --- a/packages/auth0-acul-js/tests/unit/models/user.test.ts +++ b/packages/auth0-acul-js/tests/unit/models/user.test.ts @@ -61,19 +61,19 @@ describe(':: models/user | when all fields are available', () => { }); it('should return the correct enrolled factors', () => { - expect(user.getEnrolledFactors()).toEqual(userContext.enrolled_factors); + expect(user.enrolledFactors).toEqual(userContext.enrolled_factors); }); it('should return the correct user metadata', () => { - expect(user.getUserMetadata()).toEqual(userContext.user_metadata); + expect(user.userMetadata).toEqual(userContext.user_metadata); }); it('should return the correct app metadata', () => { - expect(user.getAppMetadata()).toEqual(userContext.app_metadata); + expect(user.appMetadata).toEqual(userContext.app_metadata); }); it('should return correct organization details', () => { - const organizations = user.getOrganizations(); + const organizations = user.organizations; expect(organizations).toHaveLength(1); expect(organizations?.[0].organizationId).toBe('org123'); expect(organizations?.[0].organizationName).toBe('Auth0'); @@ -100,16 +100,16 @@ describe(':: models/user | when optional fields are not available', () => { }); it('should return null for user metadata if not available', () => { - expect(user.getUserMetadata()).toBeNull(); + expect(user.userMetadata).toBeNull(); }); it('should return null for app metadata if not available', () => { - expect(user.getAppMetadata()).toBeNull(); + expect(user.appMetadata).toBeNull(); }); it('should return null for organizations if not available', () => { userContext.organizations = undefined; user = new User(userContext); - expect(user.getOrganizations()).toBeNull(); + expect(user.organizations).toBeNull(); }); }); diff --git a/packages/auth0-acul-js/tests/unit/screens/passkey-enrollment-local.test.ts b/packages/auth0-acul-js/tests/unit/screens/passkey-enrollment-local.test.ts index 1773e00..52619f9 100644 --- a/packages/auth0-acul-js/tests/unit/screens/passkey-enrollment-local.test.ts +++ b/packages/auth0-acul-js/tests/unit/screens/passkey-enrollment-local.test.ts @@ -28,9 +28,10 @@ describe("PasskeyEnrollmentLocal", () => { it("should handle continuePasskeyEnrollment with valid payload correctly", async () => { const mockPublicKey = { key: "publicKey" }; const mockEncoded = { id: "encodedId" }; - passkeyEnrollmentLocal.screen.getPublicKey = jest - .fn() - .mockReturnValue(mockPublicKey); + Object.defineProperty(passkeyEnrollmentLocal.screen, 'publicKey', { + value: mockPublicKey, + }); + (createPasskeyCredentials as jest.Mock).mockReturnValue(mockEncoded); const payload: CustomOptions = { @@ -50,9 +51,10 @@ describe("PasskeyEnrollmentLocal", () => { it("should handle continuePasskeyEnrollment without payload correctly", async () => { const mockPublicKey = { key: "publicKey" }; const mockEncoded = { id: "encodedId" }; - passkeyEnrollmentLocal.screen.getPublicKey = jest - .fn() - .mockReturnValue(mockPublicKey); + Object.defineProperty(passkeyEnrollmentLocal.screen, 'publicKey', { + value: mockPublicKey, + }); + (createPasskeyCredentials as jest.Mock).mockReturnValue(mockEncoded); await passkeyEnrollmentLocal.continuePasskeyEnrollment(); @@ -76,9 +78,9 @@ describe("PasskeyEnrollmentLocal", () => { }); it("should handle continuePasskeyEnrollment when publicKey is null", async () => { - passkeyEnrollmentLocal.screen.getPublicKey = jest - .fn() - .mockReturnValue(null); + Object.defineProperty(passkeyEnrollmentLocal.screen, 'publicKey', { + value: null, + }); const payload: CustomOptions = { email: "test@example.com", diff --git a/packages/auth0-acul-js/tests/unit/screens/passkey-enrollment.test.ts b/packages/auth0-acul-js/tests/unit/screens/passkey-enrollment.test.ts index 982686c..6ca196b 100644 --- a/packages/auth0-acul-js/tests/unit/screens/passkey-enrollment.test.ts +++ b/packages/auth0-acul-js/tests/unit/screens/passkey-enrollment.test.ts @@ -27,9 +27,9 @@ describe("PasskeyEnrollment", () => { it("should handle continuePasskeyEnrollment with valid payload correctly", async () => { const mockPublicKey = { key: "publicKey" }; const mockEncoded = { id: "encodedId" }; - passkeyEnrollment.screen.getPublicKey = jest - .fn() - .mockReturnValue(mockPublicKey); + Object.defineProperty(passkeyEnrollment.screen, 'publicKey', { + value: mockPublicKey, + }); (createPasskeyCredentials as jest.Mock).mockReturnValue(mockEncoded); const payload: CustomOptions = { @@ -49,9 +49,9 @@ describe("PasskeyEnrollment", () => { it("should handle continuePasskeyEnrollment without payload correctly", async () => { const mockPublicKey = { key: "publicKey" }; const mockEncoded = { id: "encodedId" }; - passkeyEnrollment.screen.getPublicKey = jest - .fn() - .mockReturnValue(mockPublicKey); + Object.defineProperty(passkeyEnrollment.screen, 'publicKey', { + value: mockPublicKey, + }); (createPasskeyCredentials as jest.Mock).mockReturnValue(mockEncoded); await passkeyEnrollment.continuePasskeyEnrollment(); @@ -75,7 +75,9 @@ describe("PasskeyEnrollment", () => { }); it("should handle continuePasskeyEnrollment when publicKey is null", async () => { - passkeyEnrollment.screen.getPublicKey = jest.fn().mockReturnValue(null); + Object.defineProperty(passkeyEnrollment.screen, 'publicKey', { + value: null, + }); const payload: CustomOptions = { email: "test@example.com",