From 12fc3c30040f3e99c7fdfea41d5333ac2f7ac344 Mon Sep 17 00:00:00 2001 From: Lucas Chociay Date: Tue, 18 Oct 2022 16:51:36 -0300 Subject: [PATCH] feat: add retrieve method, data reference types for reveal elements (#239) --- src/elements/services/tokens.ts | 11 +++++++++++ src/types/elements/options.ts | 15 ++++++++------- src/types/elements/services/tokens.ts | 6 ++++-- src/types/elements/shared.ts | 10 ++++++++++ 4 files changed, 33 insertions(+), 9 deletions(-) diff --git a/src/elements/services/tokens.ts b/src/elements/services/tokens.ts index 6df516f6..ba05414d 100644 --- a/src/elements/services/tokens.ts +++ b/src/elements/services/tokens.ts @@ -45,6 +45,17 @@ const delegateTokens = ( return super.update(id, payload as UpdateToken, requestOptions); } + + public retrieve( + id: string, + requestOptions?: RequestOptions + ): Promise { + if (elements !== undefined) { + return elements.tokens.retrieve(id, requestOptions); + } + + return super.retrieve(id, requestOptions); + } }; export { delegateTokens }; diff --git a/src/types/elements/options.ts b/src/types/elements/options.ts index 1e069dba..d4bd16e2 100644 --- a/src/types/elements/options.ts +++ b/src/types/elements/options.ts @@ -1,4 +1,4 @@ -import { AutoCompleteValue } from './shared'; +import { AutoCompleteValue, DataElementReference } from './shared'; import type { ElementStyle } from './styles'; const ELEMENTS_TYPES = [ @@ -7,6 +7,7 @@ const ELEMENTS_TYPES = [ 'cardNumber', 'cardExpirationDate', 'cardVerificationCode', + 'data', ] as const; type ElementType = typeof ELEMENTS_TYPES[number]; @@ -49,18 +50,18 @@ type CustomizableElementOptions = Pick & AutoCompleteOption; interface CardElementValue { - number?: string; + number?: DataElementReference; // disabling camecalse so that the element value matches the API data /* eslint-disable camelcase */ - expiration_month?: number; - expiration_year?: number; + expiration_month?: DataElementReference; + expiration_year?: DataElementReference; /* eslint-enable camelcase */ - cvc?: string; + cvc?: DataElementReference; } interface CardExpirationDateValue { - month: number; - year: number; + month: DataElementReference; + year: DataElementReference; } type CreateCardElementOptions = CustomizableElementOptions & { diff --git a/src/types/elements/services/tokens.ts b/src/types/elements/services/tokens.ts index 1c1375fe..7ccca766 100644 --- a/src/types/elements/services/tokens.ts +++ b/src/types/elements/services/tokens.ts @@ -4,11 +4,13 @@ import type { UpdateToken as UpdateTokenModel, Token, } from '@/types/models'; -import type { Create, Update } from '@/types/sdk'; +import type { Create, Retrieve, Update } from '@/types/sdk'; type CreateToken = CreateTokenModel; type UpdateToken = UpdateTokenModel; -type Tokens = Create & Update; +type Tokens = Create & + Retrieve & + Update; export type { Tokens, CreateToken, UpdateToken }; diff --git a/src/types/elements/shared.ts b/src/types/elements/shared.ts index 1a74540b..85867141 100644 --- a/src/types/elements/shared.ts +++ b/src/types/elements/shared.ts @@ -46,6 +46,15 @@ type CardIconPosition = typeof CARD_ICON_POSITIONS[number]; */ type AutoCompleteValue = typeof AUTOCOMPLETE_VALUES[number]; +/** + * Type used for detokenization responses stored on Data Elements + */ +type DataElementReference = { + correlationId: string; + elementId: string; + path: string; +}; + export type { FieldErrorType, ConfigErrorType, @@ -57,4 +66,5 @@ export type { Brand, CardIconPosition, AutoCompleteValue, + DataElementReference, };