Skip to content

Commit

Permalink
feat: add retrieve method, data reference types for reveal elements (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
lcschy committed Oct 18, 2022
1 parent a9d8143 commit 12fc3c3
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 9 deletions.
11 changes: 11 additions & 0 deletions src/elements/services/tokens.ts
Expand Up @@ -45,6 +45,17 @@ const delegateTokens = (

return super.update(id, payload as UpdateToken, requestOptions);
}

public retrieve(
id: string,
requestOptions?: RequestOptions
): Promise<Token> {
if (elements !== undefined) {
return elements.tokens.retrieve(id, requestOptions);
}

return super.retrieve(id, requestOptions);
}
};

export { delegateTokens };
15 changes: 8 additions & 7 deletions 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 = [
Expand All @@ -7,6 +7,7 @@ const ELEMENTS_TYPES = [
'cardNumber',
'cardExpirationDate',
'cardVerificationCode',
'data',
] as const;

type ElementType = typeof ELEMENTS_TYPES[number];
Expand Down Expand Up @@ -49,18 +50,18 @@ type CustomizableElementOptions = Pick<ElementOptions, 'style' | 'disabled'> &
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 & {
Expand Down
6 changes: 4 additions & 2 deletions src/types/elements/services/tokens.ts
Expand Up @@ -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<ElementValue>;
type UpdateToken = UpdateTokenModel<ElementValue>;

type Tokens = Create<Token, CreateToken> & Update<Token, UpdateToken>;
type Tokens = Create<Token, CreateToken> &
Retrieve<Token> &
Update<Token, UpdateToken>;

export type { Tokens, CreateToken, UpdateToken };
10 changes: 10 additions & 0 deletions src/types/elements/shared.ts
Expand Up @@ -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,
Expand All @@ -57,4 +66,5 @@ export type {
Brand,
CardIconPosition,
AutoCompleteValue,
DataElementReference,
};

0 comments on commit 12fc3c3

Please sign in to comment.