Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ interface AcuantCameraUIOptions {
text: AcuantCameraUIText;
}

/**
* We call String.toLowerCase() on these when sending analytics events to the server
*/
export enum AcuantDocumentType {
NONE = 0,
ID = 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,15 @@ import type { ReactNode, MouseEvent, Ref } from 'react';
import AnalyticsContext from '../context/analytics';
import AcuantContext from '../context/acuant';
import FailedCaptureAttemptsContext from '../context/failed-capture-attempts';
import AcuantCamera from './acuant-camera';
import AcuantCamera, { AcuantDocumentType } from './acuant-camera';
import AcuantCaptureCanvas from './acuant-capture-canvas';
import FileInput from './file-input';
import DeviceContext from '../context/device';
import UploadContext from '../context/upload';
import useCounter from '../hooks/use-counter';
import useCookie from '../hooks/use-cookie';
import type {
AcuantSuccessResponse,
AcuantDocumentType,
AcuantCaptureFailureError,
} from './acuant-camera';
import type { AcuantSuccessResponse, AcuantCaptureFailureError } from './acuant-camera';

type AcuantDocumentTypeLabel = 'id' | 'passport' | 'none';
type AcuantImageAssessment = 'success' | 'glare' | 'blurry' | 'unsupported';
type ImageSource = 'acuant' | 'upload';

Expand Down Expand Up @@ -61,7 +56,7 @@ interface ImageAnalyticsPayload {
}

interface AcuantImageAnalyticsPayload extends ImageAnalyticsPayload {
documentType: AcuantDocumentTypeLabel | string;
documentType: string;
dpi: number;
moire: number;
glare: number;
Expand Down Expand Up @@ -132,21 +127,12 @@ export const isAcuantCameraAccessFailure = (error: AcuantCaptureFailureError): e
error instanceof Error;

/**
* Returns a human-readable document label corresponding to the given document type constant.
*
* Returns a human-readable document label corresponding to the given document type constant,
* such as "id" "passport" or "none"
*/
function getDocumentTypeLabel(documentType: AcuantDocumentType): AcuantDocumentTypeLabel | string {
switch (documentType) {
case 0:
return 'none';
case 1:
return 'id';
case 2:
return 'passport';
default:
return `An error in document type returned: ${documentType}`;
}
}
const getDocumentTypeLabel = (documentType: AcuantDocumentType): string =>
AcuantDocumentType[documentType]?.toLowerCase() ??
`An error in document type returned: ${documentType}`;

export function getNormalizedAcuantCaptureFailureMessage(
error: AcuantCaptureFailureError,
Expand Down Expand Up @@ -438,7 +424,7 @@ function AcuantCapture(
const { image, cardtype, dpi, moire, glare, sharpness } = nextCapture;
const isAssessedAsGlare = glare < glareThreshold;
const isAssessedAsBlurry = sharpness < sharpnessThreshold;
const isAssessedAsUnsupported = cardtype !== 1;
const isAssessedAsUnsupported = cardtype !== AcuantDocumentType.ID;
const { width, height, data } = image;

let assessment: AcuantImageAssessment;
Expand Down Expand Up @@ -593,3 +579,4 @@ function AcuantCapture(
}

export default forwardRef(AcuantCapture);
export { AcuantDocumentType };
Comment thread
zachmargolis marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import AcuantCapture, {
isAcuantCameraAccessFailure,
getNormalizedAcuantCaptureFailureMessage,
getDecodedBase64ByteSize,
AcuantDocumentType,
} from '@18f/identity-document-capture/components/acuant-capture';
import { AcuantContextProvider, AnalyticsContext } from '@18f/identity-document-capture';
import DeviceContext from '@18f/identity-document-capture/context/device';
Expand All @@ -20,7 +21,7 @@ const ACUANT_CAPTURE_SUCCESS_RESULT = {
width: 1748,
height: 1104,
},
cardtype: 1,
cardtype: AcuantDocumentType.ID,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯

dpi: 519,
moire: 99,
moireraw: 99,
Expand Down Expand Up @@ -566,7 +567,7 @@ describe('document-capture/components/acuant-capture', () => {
await Promise.resolve();
callbacks.onCropped({
...ACUANT_CAPTURE_SUCCESS_RESULT,
cardtype: 2,
cardtype: AcuantDocumentType.PASSPORT,
});
}),
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import DocumentCapture from '@18f/identity-document-capture/components/document-
import { FlowContext } from '@18f/identity-verify-flow';
import { expect } from 'chai';
import { useSandbox } from '@18f/identity-test-helpers';
import { AcuantDocumentType } from '@18f/identity-document-capture/components/acuant-camera';
import { render, useAcuant, useDocumentCaptureForm } from '../../../support/document-capture';
import { getFixtureFile } from '../../../support/file';

Expand Down Expand Up @@ -91,7 +92,7 @@ describe('document-capture/components/document-capture', () => {
image: {
data: validUpload,
},
cardtype: 1,
cardtype: AcuantDocumentType.ID,
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
UploadContextProvider,
} from '@18f/identity-document-capture';
import DocumentsStep from '@18f/identity-document-capture/components/documents-step';
import { AcuantDocumentType } from '@18f/identity-document-capture/components/acuant-camera';
import { render, useAcuant } from '../../../support/document-capture';
import { getFixtureFile } from '../../../support/file';

Expand Down Expand Up @@ -66,7 +67,7 @@ describe('document-capture/components/documents-step', () => {
);

initialize();
const result = { sharpness: 100, image: { data: '' }, cardtype: 1 };
const result = { sharpness: 100, image: { data: '' }, cardtype: AcuantDocumentType.ID };

window.AcuantCameraUI.start.callsFake(({ onCropped }) => onCropped({ ...result, glare: 10 }));
await userEvent.click(getByLabelText('doc_auth.headings.document_capture_front'));
Expand Down