API Reference
MetricSDKConfig​
The configuration options used to initialize the MetricSDK
.
Property | Type | Description |
---|---|---|
clientId | string | Your Metric client ID. |
secretKey | string | Your Metric secret key. |
initiateTokenVerification​
Starts a verification process and returns a React.JSX.Element
for user interaction.
async initiateTokenVerification(
token: string,
onModalClose: (data: VerificationData | null) => void
): Promise<{ VerificationModal: JSX.Element }>
Parameter | Type | Description |
---|---|---|
token | string | The verification token. |
onModalClose | (data: VerificationData \| null) => void | Callback triggered when the modal closes. |
Returns:
An object containing a React.JSX.Element
component to be rendered in your application.
checkTokenStatus​
Fetches the status of a verification token.
async checkTokenStatus(token: string): Promise<string>
Parameter | Type | Description |
---|---|---|
token | string | The verification token. |
Returns:
A string
representing the status of the token.
Methods​
initiateTokenVerification
​
Initiates the token verification process.
Parameters:
token
(string
): Required token for verification.onModalClose
((data: VerificationData) => void
): Callback executed with the result of the verification when the modal is closed.
Returns:
- An object containing a
JSX.Element
.
Example:
const { VerificationModal } = await metric.initiateTokenVerification(token, (data) => {
if (data) {
console.log("Verification completed:", data);
}
});
checkTokenStatus
​
Checks the status of a verification token.
Parameters:
token
(string
): The verification token.
Returns:
- A
Promise<string>
containing the token status message.
Example:
const status = await metric.checkTokenStatus("your-token");
console.log("Token status:", status);
Error Handling​
All methods in the MetricSDK
throw errors when something goes wrong. Errors are instances of the MetricSDKError
class, which extends the built-in Error
class.
Example:
try {
const status = await metric.checkTokenStatus("your-token");
} catch (error) {
if (error instanceof MetricSDKError) {
console.error("Metric SDK Error:", error.message);
} else {
console.error("Unexpected Error:", error);
}
}
Note: Ensure valid tokens and configurations are provided to avoid errors and ensure smooth operation.