import { BatchUserAttribute } from './BatchUserAttribute'; const RNBatch = require('./NativeRNBatchModule').default; /** * Batch's user module */ export const BatchUser = { /** * Get the unique installation ID, generated by Batch. Batch must be started to read it. * You will get the result in a promise. */ getInstallationID: (): Promise => RNBatch.user_getInstallationId(), /** * Get the custom user identifier. * @returns The custom user identifier set with BatchUser.editor().setIdentifier(); */ getIdentifier: (): Promise => RNBatch.user_getIdentifier(), /** * Get the region. * @returns The region set with BatchUser.editor().setRegion(); */ getRegion: (): Promise => RNBatch.user_getRegion(), /** * Get the language. * @returns The language set with BatchUser.editor().setLanguage(); */ getLanguage: (): Promise => RNBatch.user_getLanguage(), /** * Read the saved attributes. * Reading is asynchronous so as not to interfere with saving operations. * @returns The attributes set with Batch.editor().setAttribute() */ getAttributes: (): Promise<{ [key: string]: BatchUserAttribute }> => { return RNBatch.user_getAttributes().then(attributes => { Object.keys(attributes).map(key => { attributes[key] = new BatchUserAttribute(attributes[key].type, attributes[key].value); }); return attributes; }); }, /** * Get the tag collections. * @returns The tags added with BatchUser.editor().addTag() */ getTagCollections: (): Promise<{ [key: string]: string[] }> => RNBatch.user_getTags(), /** * Clear all tags and attributes set on an installation and their local cache returned by fetchAttributes and fetchTagCollections. * This doesn’t affect data set on profiles using BatchProfile. */ clearInstallationData: (): void => RNBatch.user_clearInstallationData(), };