klaviyo-react-native-sdk
Version:
Official Klaviyo React Native SDK
170 lines (162 loc) • 5.61 kB
JavaScript
"use strict";
import { KlaviyoReactNativeSdk } from "./KlaviyoReactNativeSdk.js";
const {
PROFILE_KEYS
} = KlaviyoReactNativeSdk.getConstants();
/**
* Interface for the Klaviyo Profile API
*/
/**
* Enum for various profile properties that can be set on a user
*/
export let ProfileProperty = function (ProfileProperty) {
/**
* Individual's first name
*/
ProfileProperty[ProfileProperty["FIRST_NAME"] = PROFILE_KEYS.FIRST_NAME ?? 'first_name'] = "FIRST_NAME";
/**
* Individual's last name
*/
ProfileProperty[ProfileProperty["LAST_NAME"] = PROFILE_KEYS.LAST_NAME ?? 'last_name'] = "LAST_NAME";
/**
* Individual's job title
*/
ProfileProperty[ProfileProperty["TITLE"] = PROFILE_KEYS.TITLE ?? 'title'] = "TITLE";
/**
* Name of the company or organization within the company for whom the individual works
*/
ProfileProperty[ProfileProperty["ORGANIZATION"] = PROFILE_KEYS.ORGANIZATION ?? 'organization'] = "ORGANIZATION";
/**
* URL pointing to the location of a profile image
*/
ProfileProperty[ProfileProperty["IMAGE"] = PROFILE_KEYS.IMAGE ?? 'image'] = "IMAGE";
/**
* First line of street address
*/
ProfileProperty[ProfileProperty["ADDRESS1"] = PROFILE_KEYS.ADDRESS1 ?? 'address1'] = "ADDRESS1";
/**
* Second line of street address
*/
ProfileProperty[ProfileProperty["ADDRESS2"] = PROFILE_KEYS.ADDRESS2 ?? 'address2'] = "ADDRESS2";
/**
* City name
*/
ProfileProperty[ProfileProperty["CITY"] = PROFILE_KEYS.CITY ?? 'city'] = "CITY";
/**
* Country name
*/
ProfileProperty[ProfileProperty["COUNTRY"] = PROFILE_KEYS.COUNTRY ?? 'country'] = "COUNTRY";
/**
* Zip code
*/
ProfileProperty[ProfileProperty["ZIP"] = PROFILE_KEYS.ZIP ?? 'zip'] = "ZIP";
/**
* Region within a country, such as state or province
*/
ProfileProperty[ProfileProperty["REGION"] = PROFILE_KEYS.REGION ?? 'region'] = "REGION";
/**
* Latitude coordinate. We recommend providing a precision of four decimal places.
*/
ProfileProperty[ProfileProperty["LATITUDE"] = PROFILE_KEYS.LATITUDE ?? 'latitude'] = "LATITUDE";
/**
* Longitude coordinate. We recommend providing a precision of four decimal places.
*/
ProfileProperty[ProfileProperty["LONGITUDE"] = PROFILE_KEYS.LONGITUDE ?? 'longitude'] = "LONGITUDE";
/**
* Time zone name. We recommend using time zones from the IANA Time Zone Database.
*/
ProfileProperty[ProfileProperty["TIMEZONE"] = PROFILE_KEYS.TIMEZONE ?? 'timezone'] = "TIMEZONE";
/**
* An object containing location information for this profile
*/
ProfileProperty[ProfileProperty["LOCATION"] = PROFILE_KEYS.LOCATION ?? 'location'] = "LOCATION";
/**
* An object containing key/value pairs for any custom properties assigned to this profile
*/
ProfileProperty[ProfileProperty["PROPERTIES"] = PROFILE_KEYS.PROPERTIES ?? 'properties'] = "PROPERTIES";
return ProfileProperty;
}({});
/**
* Interface for location information of a profile
*/
/**
* Interface for a profile
*/
/**
* Convert a Profile object to a Record<ProfileProperty, Object> object
* where the keys are the ProfileProperty enum values mapped to the native module's constants
*
* @param profile {@link Profile} - The profile object to convert
*/
export function formatProfile(profile) {
let bridgedProfile = {};
if (profile.externalId) {
const key = PROFILE_KEYS.EXTERNAL_ID ?? 'external_id';
bridgedProfile[key] = profile.externalId;
}
if (profile.email) {
const key = PROFILE_KEYS.EMAIL ?? 'email';
bridgedProfile[key] = profile.email;
}
if (profile.phoneNumber) {
const key = PROFILE_KEYS.PHONE_NUMBER ?? 'phone_number';
bridgedProfile[key] = profile.phoneNumber;
}
if (profile.firstName) {
bridgedProfile[ProfileProperty.FIRST_NAME] = profile.firstName;
}
if (profile.lastName) {
bridgedProfile[ProfileProperty.LAST_NAME] = profile.lastName;
}
if (profile.title) {
bridgedProfile[ProfileProperty.TITLE] = profile.title;
}
if (profile.organization) {
bridgedProfile[ProfileProperty.ORGANIZATION] = profile.organization;
}
if (profile.image) {
bridgedProfile[ProfileProperty.IMAGE] = profile.image;
}
if (profile.location) {
let bridgedLocation = {};
if (profile.location.address1) {
bridgedLocation[ProfileProperty.ADDRESS1] = profile.location.address1;
}
if (profile.location.address2) {
bridgedLocation[ProfileProperty.ADDRESS2] = profile.location.address2;
}
if (profile.location.city) {
bridgedLocation[ProfileProperty.CITY] = profile.location.city;
}
if (profile.location.country) {
bridgedLocation[ProfileProperty.COUNTRY] = profile.location.country;
}
if (profile.location.zip) {
bridgedLocation[ProfileProperty.ZIP] = profile.location.zip;
}
if (profile.location.region) {
bridgedLocation[ProfileProperty.REGION] = profile.location.region;
}
if (profile.location.latitude) {
bridgedLocation[ProfileProperty.LATITUDE] = profile.location.latitude;
}
if (profile.location.longitude) {
bridgedLocation[ProfileProperty.LONGITUDE] = profile.location.longitude;
}
if (profile.location.timezone) {
bridgedLocation[ProfileProperty.TIMEZONE] = profile.location.timezone;
}
bridgedProfile[ProfileProperty.LOCATION] = bridgedLocation;
}
if (profile.properties) {
bridgedProfile[ProfileProperty.PROPERTIES] = profile.properties;
}
return bridgedProfile;
}
/**
* Type for a profile property key
*/
/**
* Type for profile properties
*/
//# sourceMappingURL=Profile.js.map