Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add retrieve method, data reference types for reveal elements #239

Merged
merged 1 commit into from Oct 18, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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,
};