@hoxhaolsi/cloud-sdk
Version:
LiquidCommerce Cloud SDK
126 lines (125 loc) • 6.86 kB
TypeScript
import type { AuthenticatedService } from '../core';
import type { BaseUser, IPurgeResponse, IUser, IUserAddress, IUserAddressParams, IUserPayment, IUserPaymentAddParams, IUserPaymentParams, IUserPaymentUpdateParams, IUserSessionParams } from '../interfaces';
import type { IApiResponseWithData } from '../types';
/**
* A class representing a user service.
*/
export declare class UserService {
private client;
private readonly servicePath;
constructor(client: AuthenticatedService);
/**
* Creates or updates a user session.
*
* @param {IUserSessionParams} params - The parameters for creating or updating a user session.
* @returns {Promise<IApiResponseWithData<IUser>>} A promise that resolves to the user data.
* @throws {Error} If the session creation/update request fails or if neither id nor email is provided.
*/
createOrUpdateSession(params: IUserSessionParams): Promise<IApiResponseWithData<IUser>>;
/**
* Fetches user data from the API using the provided identifier.
*
* @param {string} identifier - The unique identifier for the user.
* @return {Promise<IApiResponseWithData<BaseUser>>} The API response containing
* user data omitting the session field.
*/
fetchUser(identifier: string): Promise<IApiResponseWithData<BaseUser>>;
/**
* Purges a user's data from the system.
*
* @param {string} identifier - The user's ID or email.
* @returns {Promise<IApiResponseWithData<IPurgeResponse>>} A promise that resolves to the purge response.
* @throws {Error} If the purge request fails or if the identifier is not provided.
*/
purge(identifier: string): Promise<IApiResponseWithData<IPurgeResponse>>;
/**
* Adds a new address for a user.
*
* @param {IUserAddressParams} params - The parameters containing the user's address details.
* @return {Promise<IApiResponseWithData<IUserAddress>>} - A promise that resolves with the API response containing the added user address.
* @throws {Error} If the addAddress request fails or if the required parameters are not provided.
*/
addAddress(params: IUserAddressParams): Promise<IApiResponseWithData<IUserAddress>>;
/**
* Updates or creates a new address for a user.
*
* @param {IUserAddressParams} params - The parameters for updating or creating an address.
* @returns {Promise<IApiResponseWithData<IUserAddress>>} A promise that resolves to the updated or created address.
* @throws {Error} If the address update request fails or if required parameters are missing.
*/
updateAddress(params: IUserAddressParams): Promise<IApiResponseWithData<IUserAddress>>;
/**
* Validates the parameters required for updating a user address.
*
* @param {IUserAddressParams} params - The parameters to be validated for the address update. This should include
* at least the user ID and one of the following: address object, latitude and longitude, or a Google places ID.
* @return {IUserAddressParams} Throws an error if the required parameters are not provided.
*/
private validateAddressParams;
/**
* Checks if the given user address parameters contain valid customer ID and user ID.
*
* @param {IUserAddressParams} params - The user address parameters object containing customerId and userId.
* @return {boolean} - Returns true if the customerId or userId is missing or not a string, otherwise returns false.
*/
private hasUser;
/**
* Checks if the given user address object has a valid address.
*
* @param {IUserAddressParams} params - The user address parameters object containing address details.
*
* @return {boolean} Returns true if the user address object is valid; otherwise, returns false.
*/
private hasUserAddressObj;
/**
* Checks if the user address coordinates (latitude and longitude) are not present or not of type 'number'.
*
* @param {IUserAddressParams} params - The user address parameters containing latitude and longitude.
* @return {boolean} Returns true if latitude or longitude are not provided or are not numbers, otherwise returns false.
*/
private hasUserAddressCoords;
/**
* Checks whether the user address parameters contain a valid placesId.
*
* @param {IUserAddressParams} params - The user address parameters containing placesId.
* @return {boolean} Returns true if placesId is missing or not a string, false otherwise.
*/
private hasUserAddressPlacesId;
/**
* Purges an address for a user.
*
* @param {string} addressId - The ID of the address to purge.
* @returns {Promise<IApiResponseWithData<IPurgeResponse>>} A promise that resolves to the purge response.
* @throws {Error} If the address purge request fails or if the address ID is not provided.
*/
purgeAddress(addressId: string): Promise<IApiResponseWithData<IPurgeResponse>>;
/**
* Adds a new payment method for a user.
*
* @param {IUserPaymentParams} params - The parameters required to add a payment method.
* @param {string} params.customerId - The ID of the customer.
* @param {string} params.paymentMethodId - The ID of the payment method.
* @param {boolean} params.isDefault - Indicates whether the new payment method should be marked as default.
* @return {Promise<IApiResponseWithData<IUserPayment>>} - A promise that resolves to the response containing user payment information.
* @throws {Error} - Throws an error if required parameters are missing or if the request fails.
*/
addPayment(params: IUserPaymentAddParams): Promise<IApiResponseWithData<IUserPayment>>;
/**
* Updates whether default payment method for a user.
*
* @param {IUserPaymentParams} params - The payment parameters required to update payment. Must include `customerId`,
* `paymentMethodId`.
* @returns {Promise<IApiResponseWithData<boolean>>} - A promise that resolves to the API response containing
* the updated payment information.
* @throws {Error} - Throws an error if required parameters are missing or the request fails.
*/
updatePayment(params: IUserPaymentParams | IUserPaymentUpdateParams): Promise<IApiResponseWithData<boolean>>;
/**
* Purges a payment record for a specified customer.
*
* @param {string} customerId - The ID of the customer whose payment record is to be purged.
* @param {string} paymentId - The ID of the payment record to be purged.
* @return {Promise<IApiResponseWithData<IPurgeResponse>>} A promise that resolves to the response of the purge request.
*/
purgePayment(customerId: string, paymentId: string): Promise<IApiResponseWithData<IPurgeResponse>>;
}