Skip to main content
Version: Node.js

SIM Swap Reference

The SIM Swap client is scoped to a single phone number, so in-order to interact with the SIM Swap service, you need to create a SimSwapUserClient instance for the phone number you want to check.

SimSwapUserClients are creating using the SimSwapClient accessible from the GlideClient instance.

SimSwapClient Reference

Methods

1. forUser

Description: forUser creates a SimSwapUserClient instance for the specified phone number.

Syntax:

forUser(identifier: UserIdentifier): Promise<SimSwapUserClient>;

Parameters:

ParameterTypeDescription
identifierUserIdentifierAn object representing a user (can be a phonenumber, ip address or custom user id)

UserIdentifier Properties:

PropertyTypeDescription
phoneNumberstringThe phone number of the user.
ipAddressnumberThe IP address of the user.
userIdstringA custom user identifier.

Only one of the properties should be provided.

Returns:

  • SimSwapUserClient: A client instance for the specified user.

Example:

import { GlideClient } from "glide-sdk";

async function main() {
const glide = new GlideClient({
// credentials can be omitted if set in environment variable
clientId: "your-client-id",
clientSecret: "your-client-secret",
});

const simSwapUserClient = await glide.simSwap.forUser({
phoneNumber: '+555123456789'
});
}

main().catch(console.error);

SimSwapUserClient Reference

The SimSwapUserClient is used to interact with the SIM Swap service for a specific phone number.

Properties

1. requiresConsent

A boolean indicating if the user needs to provide consent before checking for a SIM swap. If this is true then you need to call getConsentUrl to get the consent URL and ask the user to provide consent before calling check or retrieveDate.

Methods

1. check

Description: check verifies if a SIM swap has occurred for the user's phone number.

Syntax:

check(checkParams: SimSwapCheckParams = {}, config: ApiConfig = {}): Promise<SimSwapCheckResponse>;

Parameters:

ParameterTypeDescription
checkParamsSimSwapCheckParamsAn object containing the check parameters.

SimSwapCheckParams Properties:

PropertyTypeDescription
phoneNumberstringOptional - The phone number to check for a SIM swap.
maxAgenumberOptional - Maximum age of the SIM swap in hours.

If phoneNumber was provied in the forUser method as the user identifier, it can be omitted here.

Returns:

  • SimSwapCheckResponse: An object containing the SIM swap status.

SimSwapCheckResponse Properties:

PropertyTypeDescription
swappedbooleanIndicates if a SIM swap has occurred up to maxAge hours ago

Example:

import { GlideClient } from "glide-sdk";

async function main() {
const glide = new GlideClient();
const simSwapUserClient = await glide.simSwap.forUser({
phoneNumber: '+555123456789'
});

const simSwapCheckResponse = await simSwapUserClient.check();
console.log(simSwapCheckResponse);
// Output: { swapped: true }
}

main().catch(console.error);

2. retrieveDate

Description: retrieveDate retrieves the date of the last SIM swap for the user's phone number.

Syntax:

retrieveDate(params: SimSwapRetrieveDateParams = {}, config: ApiConfig = {}): Promise<SimSwapRetrieveDateResponse>;

Parameters:

ParameterTypeDescription
paramsSimSwapRetrieveDateParamsAn object containing the retrieve date parameters.

SimSwapRetrieveDateParams Properties:

PropertyTypeDescription
phoneNumberstringOptional - The phone number to check for a SIM swap.

Returns:

  • SimSwapRetrieveDateResponse: An object containing the date of the last SIM swap.

SimSwapRetrieveDateResponse Properties:

PropertyTypeDescription
latestSimChangestringThe date of the last SIM swap in ISO 8601 format.

Example:

import { GlideClient } from "glide-sdk";

async function main() {
const glide = new GlideClient();
const simSwapUserClient = await glide.simSwap.forUser({
phoneNumber: '+555123456789'
});

const simSwapDateResponse = await simSwapUserClient.retrieveDate();
console.log(simSwapDateResponse);
// Output: { latestSimChange: "2022-01-01T00:00:00Z" }
}

main().catch(console.error);

3. getConsentUrl

Description: getConsentUrl retrieves the URL for the user to provide consent before checking for a SIM swap.

Syntax:

getConsentUrl(): string;

Returns:

  • string: The URL for the user to provide consent.

Example:

import { GlideClient } from "glide-sdk";

async function main() {
const glide = new GlideClient();
const simSwapUserClient = await glide.simSwap.forUser({
phoneNumber: '+555123456789'
});

if (simSwapUserClient.requiresConsent) {
const consentUrl = simSwapUserClient.getConsentUrl();
console.log(consentUrl);
}
}

main().catch(console.error);

4. pollAndWaitForSession

Description: pollAndWaitForSession polls the SIM Swap service until the user has provided consent and a session is available. This method should be called after you have retrieved the consent URL and passed it to the user.

Syntax:

pollAndWaitForSession(): Promise<void>;

Returns:

  • void

Example:

import { GlideClient } from "glide-sdk";

async function main() {
const glide = new GlideClient();
const simSwapUserClient = await glide.simSwap.forUser({
phoneNumber: '+555123456789'
});

if (simSwapUserClient.requiresConsent) {
const consentUrl = simSwapUserClient.getConsentUrl();
console.log(consentUrl);
await simSwapUserClient.pollAndWaitForSession();
}
// Now you can call check or retrieveDate
}

main().catch(console.error);

Error Handling

Each method in ExampleService can throw errors under certain conditions. Developers should handle these exceptions as part of their implementation. Common errors include:

  • InvalidInputError: Thrown when input parameters do not meet the required format or type.
  • OperationFailedError: Thrown when an operation cannot be completed successfully due to various issues, such as network problems or service unavailability.

Type Definitions

ApiConfig

This object can be sent to most service apis to override the default configuration like the access token used in the request.

Properties

PropertyTypeDescription
sessionSessionAn optional session object for authentication and authorization.

Session

This object represents a user session with an access token, expiration time, and associated scopes.

Properties

PropertyTypeDescription
accessTokenstringThe access token for the session.
expiresAtnumberThe expiration time of the session.
scopesstring[]An array of scopes associated with the session.