@paritydeals/node-sdk
Version:
Node.js SDK for interacting with the ParityDeals API.
84 lines • 4.41 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ReportingOperations = void 0;
const constants_1 = require("./constants");
// import { InvalidRequestError } from './exceptions'; // Only if doing runtime Zod validation here
// import { ReportUsagePayloadSchema, ReportEventPayloadSchema } from './models'; // If using Zod
/**
* Handles 'reporting' related API operations.
* This class is instantiated by the ParityDeals client and accessed
* via `client.reporting`. All methods are asynchronous.
*/
class ReportingOperations {
constructor(client) {
this.client = client;
this.client.logger.debug("ReportingOperations initialized.");
}
/**
* Reports usage information to the API.
* @param params - Parameters for reporting usage.
* - customerId: string - Customer's unique identifier.
* - featureId: string - Feature's unique identifier.
* - value: number - The usage value.
* - behaviour: Behaviour - How the usage should be interpreted ('SET' or 'DELTA').
* - resourceId?: string | null - Optional resource identifier.
* @returns A Promise resolving to ReportUsageResponse.
*/
async reportUsage(params) {
this.client.logger.info(`Initiating reportUsage for customerId: ${params.customerId}, featureId: ${params.featureId}`);
// Construct the payload object internally from individual parameters
const payload = {
value: params.value,
customerId: params.customerId,
featureId: params.featureId,
behaviour: params.behaviour,
resourceId: params.resourceId,
};
// Optional: If you were to add runtime validation with Zod:
// try {
// ReportUsagePayloadSchema.parse(payload); // Assuming ReportUsagePayloadSchema is your Zod schema
// } catch (error: any) {
// this.client.logger.warn(`Runtime validation failed for reportUsage: ${JSON.stringify(error.errors)}`);
// throw new InvalidRequestError("Validation failed", undefined, error.errors);
// }
const endpointModulePath = `${constants_1.REPORT_MODULE_PREFIX}/usage/`;
this.client.logger.debug(`ReportUsage payload (camelCase, before client processing): ${JSON.stringify(payload)}`);
return this.client._request("POST", endpointModulePath, payload // Pass the camelCase payload; client._request will handle case conversion
);
}
/**
* Reports an event to the API.
* @param params - Parameters for reporting an event.
* - customerId: string - Customer's unique identifier.
* - eventName: string - Name of the event.
* - idempotencyKey: string - Unique key for the event.
* - timestamp: string - UTC timestamp string ("YYYY-MM-DD HH:MM:SS.ffffff").
* - resourceId?: string | null - Optional resource identifier.
* - properties?: Record<string, any> | null - Optional additional properties for the event.
* @returns A Promise resolving to ReportEventResponse.
*/
async reportEvent(params) {
this.client.logger.info(`Initiating reportEvent for customerId: ${params.customerId}, eventName: ${params.eventName}`);
const payload = {
customerId: params.customerId,
eventName: params.eventName,
idempotencyKey: params.idempotencyKey,
timestamp: params.timestamp,
resourceId: params.resourceId,
properties: params.properties,
};
// Optional: Add runtime validation using Zod here if desired
// try {
// ReportEventPayloadSchema.parse(payload); // Assuming ReportEventPayloadSchema is your Zod schema
// } catch (error: any) {
// this.client.logger.warn(`Runtime validation failed for reportEvent: ${JSON.stringify(error.errors)}`);
// throw new InvalidRequestError("Invalid parameters for reportEvent", undefined, error.errors);
// }
const endpointModulePath = `${constants_1.REPORT_MODULE_PREFIX}/event/`;
this.client.logger.debug(`ReportEvent payload (camelCase, before client processing): ${JSON.stringify(payload)}`);
return this.client._request("POST", endpointModulePath, payload // Pass the camelCase payload
);
}
}
exports.ReportingOperations = ReportingOperations;
//# sourceMappingURL=reporting.js.map