@sirenapp/js-sdk
Version:
JavaScript middleware designed to streamline interaction for managing and displaying in-app notifications seamlessly
45 lines (44 loc) • 2.23 kB
TypeScript
import type { SirenErrorType, ActionCallbackType } from './types';
import type { ApiOperationType } from './constants/generic';
import { SirenErrorTypes } from './constants/generic';
/**
* Validates and sanitizes session data, calling an error handler if any issues found.
* @param {string} token - The session token to validate.
* @param {string} recipientId - The recipient ID associated with the session.
* @param {(response: SirenErrorType) => void} onError - A callback function to handle validation errors.
*
* @returns {object} An object containing either sanitized data or error information.
* - data:
* token: (string) The validated session token.
* recipientId: (string) The validated recipient ID.
* onError: (Function) The original `onError` function passed in.
* - error: (string | null) An error message if validation fails, otherwise null.
* - code: (string | null) An error code if validation fails, otherwise null.
*/
export declare function sanitizeSession(token: string, recipientId: string, onError: (response: SirenErrorType) => void, actionCallbacks?: ActionCallbackType): {
data: {
token: string;
recipientId: string;
onError: (response: SirenErrorType) => void;
} | null;
error: string | null;
code: string | null;
};
/**
* Creates a SirenError object and calls an error handling callback.
*
* @param {keyof typeof SirenErrorTypes} type - The type of SirenError to create. Value can be 'ERROR' | 'CONFIG_ERROR' |'NETWORK_ERROR' .
* @param {string} message - The error message to include in the SirenError object.
* @param {number} code - The error code to include in the SirenError object.
*/
export declare const emitSirenError: (type: keyof typeof SirenErrorTypes, message: string, code: string) => SirenErrorType;
/**
* Parses a date string and returns a new date after adding 1 millisecond
* @param {string} date - The date string to parse.
* @returns {string} An ISO date string representing the time one millisecond after the passed date.
*/
export declare const getStartDate: (date: string) => string;
export declare const generateApiError: (operation?: ApiOperationType) => {
code: string;
message: string;
};