UNPKG

@paritydeals/node-sdk

Version:

Node.js SDK for interacting with the ParityDeals API.

96 lines 4.95 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.CustomersOperations = void 0; const constants_1 = require("./constants"); const exceptions_1 = require("./exceptions"); // For potential client-side validation class CustomersOperations { constructor(client) { this.client = client; this.client.logger.debug("CustomersOperations initialized."); } /** * Retrieves a paginated list of customers. * @param params - Optional parameters for pagination. * - page?: number - Page number to retrieve. * - pageSize?: number - Number of items per page. * @returns A Promise resolving to PaginatedCustomerResponse. */ async list(params) { this.client.logger.info(`Initiating list customers. Params: ${JSON.stringify(params) || 'None'}`); const endpointModulePath = `${constants_1.CUSTOMERS_MODULE_PREFIX}/`; const queryParams = params || {}; this.client.logger.debug(`listCustomers query params (camelCase, before client processing): ${JSON.stringify(queryParams)}`); return this.client._request("GET", endpointModulePath, undefined, queryParams); } /** * Creates a new customer record. * @param params - Parameters for creating a customer. * - customerId: string - Client-defined unique identifier for the customer. * - email: string - Email address of the customer. * - name?: string | null - Optional name of the customer. * - metadata?: Record<string, any> | null - Optional metadata for the customer. * @returns A Promise resolving to CustomerResponse. */ async create(params) { this.client.logger.info(`Initiating create customer for customerId: ${params.customerId}`); const payload = { customerId: params.customerId, email: params.email, name: params.name, metadata: params.metadata, }; const endpointModulePath = `${constants_1.CUSTOMERS_MODULE_PREFIX}/`; this.client.logger.debug(`Create customer payload (camelCase, before client processing): ${JSON.stringify(payload)}`); return this.client._request("POST", endpointModulePath, payload); } /** * Retrieves a specific customer by their client-defined customerId. * @param params - Parameters for retrieving a customer. * - customerId: string - The unique identifier of the customer. * @returns A Promise resolving to CustomerResponse. */ async retrieve(params) { this.client.logger.info(`Initiating retrieve customer for customerId: ${params.customerId}`); const endpointModulePath = `${constants_1.CUSTOMERS_MODULE_PREFIX}/${params.customerId}/`; return this.client._request("GET", endpointModulePath); } /** * Updates an existing customer record (partial update). * @param params - Parameters for updating a customer. * - customerId: string - The unique identifier of the customer to update. * - name?: string | null - Optional new name for the customer. * - email?: string | null - Optional new email for the customer. * - metadata?: Record<string, any> | null - Optional new metadata for the customer. * @returns A Promise resolving to CustomerResponse. */ async update(params) { this.client.logger.info(`Initiating update customer for customerId: ${params.customerId}`); const payload = { name: params.name, email: params.email, metadata: params.metadata, }; const effectivelyEmpty = Object.values(payload).every(value => value === undefined || value === null); if (effectivelyEmpty) { const errMsg = "Update payload cannot be empty for PATCH request. At least one field (name, email, or metadata) to update must be provided."; this.client.logger.warn(errMsg); throw new exceptions_1.InvalidRequestError(errMsg); } const endpointModulePath = `${constants_1.CUSTOMERS_MODULE_PREFIX}/${params.customerId}/`; this.client.logger.debug(`Update customer payload (camelCase, before client processing): ${JSON.stringify(payload)}`); return this.client._request("PATCH", endpointModulePath, payload); } /** * Archives (soft deletes) a customer. * @param params - Parameters for archiving a customer. * - customerId: string - The unique identifier of the customer to archive. * @returns A Promise resolving to ArchiveSuccessResponse. */ async archive(params) { this.client.logger.info(`Initiating archive customer for customerId: ${params.customerId}`); const endpointModulePath = `${constants_1.CUSTOMERS_MODULE_PREFIX}/${params.customerId}/`; return this.client._request("DELETE", endpointModulePath); } } exports.CustomersOperations = CustomersOperations; //# sourceMappingURL=customers.js.map