(
{
applicationId,
organizationId,
userId,
user,
}: {
applicationId?: string;
organizationId?: string;
userId?: string;
/*
* If available in the request context, directly providing the user object
* is more efficient than providing the userId.
*/
user?: User;
},
ctx?: WithLogContext
)
| 174 | */ |
| 175 | // eslint-disable-next-line complexity |
| 176 | const buildVerificationCodeContext = async ( |
| 177 | { |
| 178 | applicationId, |
| 179 | organizationId, |
| 180 | userId, |
| 181 | user, |
| 182 | }: { |
| 183 | applicationId?: string; |
| 184 | organizationId?: string; |
| 185 | userId?: string; |
| 186 | /* |
| 187 | * If available in the request context, directly providing the user object |
| 188 | * is more efficient than providing the userId. |
| 189 | */ |
| 190 | user?: User; |
| 191 | }, |
| 192 | ctx?: WithLogContext |
| 193 | ): Promise<VerificationCodeContextInfo> => { |
| 194 | try { |
| 195 | const [application, applicationSignInExperience, organization, userData] = await Promise.all([ |
| 196 | applicationId |
| 197 | ? isBuiltInApplicationId(applicationId) |
| 198 | ? Promise.resolve(buildBuiltInApplicationDataForTenant('', applicationId)) |
| 199 | : queries.applications.findApplicationById(applicationId) |
| 200 | : undefined, |
| 201 | applicationId |
| 202 | ? queries.applicationSignInExperiences.safeFindSignInExperienceByApplicationId( |
| 203 | applicationId |
| 204 | ) |
| 205 | : undefined, |
| 206 | organizationId ? queries.organizations.findById(organizationId) : undefined, |
| 207 | user ?? (userId ? queries.users.findUserById(userId) : undefined), |
| 208 | ]); |
| 209 | |
| 210 | return { |
| 211 | ...conditional( |
| 212 | application && { |
| 213 | application: buildApplicationContextInfo(application, applicationSignInExperience), |
| 214 | } |
| 215 | ), |
| 216 | ...conditional( |
| 217 | organization && { organization: buildOrganizationContextInfo(organization) } |
| 218 | ), |
| 219 | ...conditional(userData && { user: buildUserContextInfo(userData) }), |
| 220 | }; |
| 221 | } catch (error: unknown) { |
| 222 | void appInsights.trackException(error, ctx ? buildAppInsightsTelemetry(ctx) : undefined); |
| 223 | |
| 224 | // Should not block the verification code sending if the context information is not available. |
| 225 | return {}; |
| 226 | } |
| 227 | }; |
| 228 | |
| 229 | return { createPasscode, sendPasscode, verifyPasscode, buildVerificationCodeContext }; |
| 230 | }; |
no test coverage detected