@paydock/client-sdk
Version:
Paydock client sdk
163 lines • 5.34 kB
TypeScript
import { type Mode } from './fraud-prevention.constants';
import type { FraudPreventionProvider } from './fraud-prevention.events';
import { ForterDeviceAgent } from './providers/forter/forter-device-agent.service';
type FraudPreventionConfig = {
mode: Mode;
environmentAlias?: string;
environmentId: string;
};
/**
* A class to manage integration fraud prevention integrations.
*
* @example
*
* ```js
* const fps = new FraudPreventionService({
* environmentId: 'production',
* mode: 'live',
* });
* ```
*/
export declare class FraudPreventionService {
private readonly environment;
private readonly httpFetcherFactory;
private readonly mode;
private authorizationStrategy;
private forterDeviceAgent;
/**
* @constructs
*
* @param {Object} config - FraudPreventionService configuration object
* @param {string} config.mode - Environment mode, must be either 'test' or 'live'
* @param {string} config.environmentId - Environment identifier
* @param {string} [config.environmentAlias] - Optional environment alias for API requests
*/
constructor(config: FraudPreventionConfig);
/**
* Automatically detects and sets the authorization strategy the service should use
* based on the shape of the provided string.
*
* If the value is a JWT token, it will use an access token strategy, otherwise it will use
* a public key strategy.
*
* @param value - The authorization value (either JWT token or public key)
*
* @returns The FraudPreventionService instance for method chaining
*
* @example
* ```ts
* // With JWT token
* fps.withAuthorization('eyJhbGciOiJIUzI1NiIs...');
*
* // With public key
* fps.withAuthorization('pk_example_...');
* ```
*/
withAuthorization(value: string): FraudPreventionService;
/**
* Sets the authorization strategy to use access token authentication.
*
* @param accessToken - The JWT access token
* @returns The FraudPreventionService instance for method chaining
*
* @example
*
* ```ts
* fps.withAccessTokenStrategy('eyJhbGciOiJIUzI1NiIs...');
* ```
*/
withAccessTokenStrategy(accessToken: string): FraudPreventionService;
/**
* Sets the authorization strategy to use public key authentication.
*
* @param publicKey - The public key
* @returns The FraudPreventionService instance for method chaining
*
* @example
*
* ```ts
* fps.withPublicKeyStrategy('pk_example_...');
* ```
*/
withPublicKeyStrategy(publicKey: string): FraudPreventionService;
/**
* Initializes Forter integration with the provided configuration. This method injects
* Forter's JavaScript snippet into the page and starts tracking user behavior.
*
* @param {Object} config - Configuration object for Forter integration
* @param {string} [config.siteId] - Your Forter site ID or subsite merchant ID
* @param {string} [config.providerId] - Your Paydock integrated Forter Service ID.
* @param {boolean} [config.csp] - Set to true if your site uses Content-Security-Policies
*
* @throws If neither siteId nor providerId are provided in the configuration
* @throws If providerId fails to resolve to a siteId through Paydock integration services
*
* @returns Promise with existing FraudPreventionService instance
*
* @example
*
* ```js
* await fps.withForter({
* providerId: 'your-paydock-forter-service-id'
* });
* ```
*
* @example
*
* ```js
* await fps.withForter({
* siteId: 'your-forter-site-id',
* });
* ```
*/
withForter(config: {
csp?: boolean;
} & ({
siteId: string;
providerId?: never;
} | {
siteId?: never;
providerId: string;
})): Promise<this>;
/**
* Returns the initialized Forter device agent instance if available.
*
* Make sure to call withForter() before accessing this getter.
*
* @returns {ForterDeviceAgent | null} The Forter device agent instance or null if not initialized
*
* @example
*
* ```js
* const fps = new FraudPreventionService();
*
* fps.withForter({
* siteId: 'your-site-id',
* mode: 'test'
* });
*
* const token = fps.forter?.token;
* ```
*/
get forter(): ForterDeviceAgent | null;
/**
* Gets the credentials for a specific fraud prevention provider.
*
* Returns different credential types based on the selected provider.
*
* @param provider - The fraud prevention provider
* @param providerId - The ID of the provider instance
*
* @returns a tuple with shape [providerSpecificCredentials, error]
*/
getProviderCredentials<P extends FraudPreventionProvider>(provider: P, providerId: string): Promise<import("../shared/shared.constants").Result<P extends "forter" ? {
provider: "forter";
siteId: string;
subsiteId: string;
} : never, unknown>>;
private validateEnvironmentId;
private validateEnvironmentAlias;
private validateMode;
}
export {};
//# sourceMappingURL=fraud-prevention.service.d.ts.map