From 96de9a263a5a8d75779a7c1420dfde6a35489d17 Mon Sep 17 00:00:00 2001 From: Thomas Auty Date: Fri, 5 Oct 2018 12:14:29 -0400 Subject: [PATCH 1/2] Add typings for core and experiment features of SDK --- index.d.ts | 121 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 121 insertions(+) create mode 100644 index.d.ts diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 00000000..be20bf90 --- /dev/null +++ b/index.d.ts @@ -0,0 +1,121 @@ +declare module 'taplytics-react-native' { + namespace Taplytics { + export interface TaplyticsUserAttributes extends object { + email?: string; + name?: string; + age?: number; + gender?: string; + user_id: string; + } + + /** + * User Attributes set before startTaplytics is called will be used for experiment + * segmentation on the first session of your app. Any attributes that are set after + * startTaplytics is called will not be used for experiment segmentation until the + * next session of your app. + */ + export function setUserAttributes(attributes: TaplyticsUserAttributes): void; + + /** + * Once a user logs out of your app, their User Attributes are no longer valid. + * You can reset their data by calling resetAppUser, make sure you do not set + * any new user attributes until you receive the callback. + */ + export function resetAppUser(): void; + + export interface TaplyticsSessionInfo { + appUser_id: string; + session_id: string; + } + + export function getSessionInfo(): Promise; + export function logEvent(eventName: string, value: number, customAttributes: object): void; + export function logRevenue(eventName: string, value: number, customAttributes: object): void; + + /** + * Synchronous variables are guaranteed to have the same value for the + * entire session and will have that value immediately after construction. + * Synchronous variables take two parameters in its constructor: + * - Variable name + * - Default Value + * - Promise + * The type of the variable will be inferred from the type of value passed + * in as the default. This method returns a promise which resolves with the + * value of the synchronous variable: + */ + export function newSyncVariable(variableName: string, defaultValue: T): Promise; + + /** + * IMPORTANT: The value of these variables will be determined immediately, + * ie. the SDK will not wait for properties to be loaded from the server. + * Thus, if you want to ensure that the variables have their correct variables + * based on your experiment segmentation, you must initialize them after the + * properties have been loaded from the server. This module provides a callback to + * achieve this: + */ + export function propertiesLoadedCallback(): Promise; + + /** + * Asynchronous variables take care of insuring that the experiments have been loaded + * before returning a value. This removes any danger of tainting the results of your + * experiment with bad data. What comes with the insurance of using the correct value + * is the possibility that the value will not be set immediately. If the variable is + * constructed before the experiments are loaded, you won't have the correct value until + * the experiments have finished loading. If the experiments fail to load, then you will + * be given the default value, as specified in the variables constructor. + */ + export function newAsyncVariable(name: string, defaultValue: T, variableChangedCallback: (v: T) => void): void; + + /** + * Synchronous feature flags are guaranteed to have the same value for the entire session + * and will have that value immediately after construction. + */ + export function featureFlagEnabled(featureFlagKey: string): Promise; + + /** + * IMPORTANT: The value of featureFlagEnabled will be determined immediately, ie. the SDK + * will not wait for properties to be loaded from the server. Thus, if you want to ensure + * that the variables have their correct variables based on your experiment segmentation, + * you must initialize them after the properties have been loaded from the server. + * This module provides a callback to achieve this: propertiesLoadedCallback + */ + + /** + * If you would like to see which feature flags are running on a given device, + * there exists a getRunningFeatureFlags() function which provides a callback with the + * current feature flags' names and their associated key. An example: + */ + export function getRunningFeatureFlags(): Promise; + + /** + * To make it easier to keep track of your variables, this module also provides a + * method to retrieve an object map of their names and values: + */ + export interface TaplyticsVariableMap {[key: string]: string | number | boolean | object} + export function getVariables(): Promise; + + /** + * You can also register a function to be called whenever this object changes: + */ + export function registerVariablesChangedListener(callback: (v: TaplyticsVariableMap) => void): void; + + /** + * If you would like to see which variations and experiments are running on a given device, + * there exists a getRunningExperimentsAndVariations function which provides a callback with + * a map of the current experiments and their running variation. An example: + */ + export function getRunningExperimentsAndVariations(): Promise; + + /** + * To manually force a new user session (ex: A user has logged in / out), there exists + */ + export function startNewSession(): Promise; + + /** + * You can also register a callback to be run when Taplytics creates a new session: + */ + export function setTaplyticsNewSessionListener(callback: () => void): void; + + } + export = Taplytics; +} From 3f19e3a21e1f28ff5347c0b58935bdbbad978302 Mon Sep 17 00:00:00 2001 From: Thomas Auty Date: Mon, 8 Oct 2018 10:42:53 -0400 Subject: [PATCH 2/2] Tabs -> Spaces --- index.d.ts | 238 ++++++++++++++++++++++++++--------------------------- 1 file changed, 119 insertions(+), 119 deletions(-) diff --git a/index.d.ts b/index.d.ts index be20bf90..a0ba2765 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,121 +1,121 @@ declare module 'taplytics-react-native' { - namespace Taplytics { - export interface TaplyticsUserAttributes extends object { - email?: string; - name?: string; - age?: number; - gender?: string; - user_id: string; - } - - /** - * User Attributes set before startTaplytics is called will be used for experiment - * segmentation on the first session of your app. Any attributes that are set after - * startTaplytics is called will not be used for experiment segmentation until the - * next session of your app. - */ - export function setUserAttributes(attributes: TaplyticsUserAttributes): void; - - /** - * Once a user logs out of your app, their User Attributes are no longer valid. - * You can reset their data by calling resetAppUser, make sure you do not set - * any new user attributes until you receive the callback. - */ - export function resetAppUser(): void; - - export interface TaplyticsSessionInfo { - appUser_id: string; - session_id: string; - } - - export function getSessionInfo(): Promise; - export function logEvent(eventName: string, value: number, customAttributes: object): void; - export function logRevenue(eventName: string, value: number, customAttributes: object): void; - - /** - * Synchronous variables are guaranteed to have the same value for the - * entire session and will have that value immediately after construction. - * Synchronous variables take two parameters in its constructor: - * - Variable name - * - Default Value - * - Promise - * The type of the variable will be inferred from the type of value passed - * in as the default. This method returns a promise which resolves with the - * value of the synchronous variable: - */ - export function newSyncVariable(variableName: string, defaultValue: T): Promise; - - /** - * IMPORTANT: The value of these variables will be determined immediately, - * ie. the SDK will not wait for properties to be loaded from the server. - * Thus, if you want to ensure that the variables have their correct variables - * based on your experiment segmentation, you must initialize them after the - * properties have been loaded from the server. This module provides a callback to - * achieve this: - */ - export function propertiesLoadedCallback(): Promise; - - /** - * Asynchronous variables take care of insuring that the experiments have been loaded - * before returning a value. This removes any danger of tainting the results of your - * experiment with bad data. What comes with the insurance of using the correct value - * is the possibility that the value will not be set immediately. If the variable is - * constructed before the experiments are loaded, you won't have the correct value until - * the experiments have finished loading. If the experiments fail to load, then you will - * be given the default value, as specified in the variables constructor. - */ - export function newAsyncVariable(name: string, defaultValue: T, variableChangedCallback: (v: T) => void): void; - - /** - * Synchronous feature flags are guaranteed to have the same value for the entire session - * and will have that value immediately after construction. - */ - export function featureFlagEnabled(featureFlagKey: string): Promise; - - /** - * IMPORTANT: The value of featureFlagEnabled will be determined immediately, ie. the SDK - * will not wait for properties to be loaded from the server. Thus, if you want to ensure - * that the variables have their correct variables based on your experiment segmentation, - * you must initialize them after the properties have been loaded from the server. - * This module provides a callback to achieve this: propertiesLoadedCallback - */ - - /** - * If you would like to see which feature flags are running on a given device, - * there exists a getRunningFeatureFlags() function which provides a callback with the - * current feature flags' names and their associated key. An example: - */ - export function getRunningFeatureFlags(): Promise; - - /** - * To make it easier to keep track of your variables, this module also provides a - * method to retrieve an object map of their names and values: - */ - export interface TaplyticsVariableMap {[key: string]: string | number | boolean | object} - export function getVariables(): Promise; - - /** - * You can also register a function to be called whenever this object changes: - */ - export function registerVariablesChangedListener(callback: (v: TaplyticsVariableMap) => void): void; - - /** - * If you would like to see which variations and experiments are running on a given device, - * there exists a getRunningExperimentsAndVariations function which provides a callback with - * a map of the current experiments and their running variation. An example: - */ - export function getRunningExperimentsAndVariations(): Promise; - - /** - * To manually force a new user session (ex: A user has logged in / out), there exists - */ - export function startNewSession(): Promise; - - /** - * You can also register a callback to be run when Taplytics creates a new session: - */ - export function setTaplyticsNewSessionListener(callback: () => void): void; - - } - export = Taplytics; + namespace Taplytics { + export interface TaplyticsUserAttributes extends object { + email?: string; + name?: string; + age?: number; + gender?: string; + user_id: string; + } + + /** + * User Attributes set before startTaplytics is called will be used for experiment + * segmentation on the first session of your app. Any attributes that are set after + * startTaplytics is called will not be used for experiment segmentation until the + * next session of your app. + */ + export function setUserAttributes(attributes: TaplyticsUserAttributes): void; + + /** + * Once a user logs out of your app, their User Attributes are no longer valid. + * You can reset their data by calling resetAppUser, make sure you do not set + * any new user attributes until you receive the callback. + */ + export function resetAppUser(): void; + + export interface TaplyticsSessionInfo { + appUser_id: string; + session_id: string; + } + + export function getSessionInfo(): Promise; + export function logEvent(eventName: string, value: number, customAttributes: object): void; + export function logRevenue(eventName: string, value: number, customAttributes: object): void; + + /** + * Synchronous variables are guaranteed to have the same value for the + * entire session and will have that value immediately after construction. + * Synchronous variables take two parameters in its constructor: + * - Variable name + * - Default Value + * - Promise + * The type of the variable will be inferred from the type of value passed + * in as the default. This method returns a promise which resolves with the + * value of the synchronous variable: + */ + export function newSyncVariable(variableName: string, defaultValue: T): Promise; + + /** + * IMPORTANT: The value of these variables will be determined immediately, + * ie. the SDK will not wait for properties to be loaded from the server. + * Thus, if you want to ensure that the variables have their correct variables + * based on your experiment segmentation, you must initialize them after the + * properties have been loaded from the server. This module provides a callback to + * achieve this: + */ + export function propertiesLoadedCallback(): Promise; + + /** + * Asynchronous variables take care of insuring that the experiments have been loaded + * before returning a value. This removes any danger of tainting the results of your + * experiment with bad data. What comes with the insurance of using the correct value + * is the possibility that the value will not be set immediately. If the variable is + * constructed before the experiments are loaded, you won't have the correct value until + * the experiments have finished loading. If the experiments fail to load, then you will + * be given the default value, as specified in the variables constructor. + */ + export function newAsyncVariable(name: string, defaultValue: T, variableChangedCallback: (v: T) => void): void; + + /** + * Synchronous feature flags are guaranteed to have the same value for the entire session + * and will have that value immediately after construction. + */ + export function featureFlagEnabled(featureFlagKey: string): Promise; + + /** + * IMPORTANT: The value of featureFlagEnabled will be determined immediately, ie. the SDK + * will not wait for properties to be loaded from the server. Thus, if you want to ensure + * that the variables have their correct variables based on your experiment segmentation, + * you must initialize them after the properties have been loaded from the server. + * This module provides a callback to achieve this: propertiesLoadedCallback + */ + + /** + * If you would like to see which feature flags are running on a given device, + * there exists a getRunningFeatureFlags() function which provides a callback with the + * current feature flags' names and their associated key. An example: + */ + export function getRunningFeatureFlags(): Promise; + + /** + * To make it easier to keep track of your variables, this module also provides a + * method to retrieve an object map of their names and values: + */ + export interface TaplyticsVariableMap {[key: string]: string | number | boolean | object} + export function getVariables(): Promise; + + /** + * You can also register a function to be called whenever this object changes: + */ + export function registerVariablesChangedListener(callback: (v: TaplyticsVariableMap) => void): void; + + /** + * If you would like to see which variations and experiments are running on a given device, + * there exists a getRunningExperimentsAndVariations function which provides a callback with + * a map of the current experiments and their running variation. An example: + */ + export function getRunningExperimentsAndVariations(): Promise; + + /** + * To manually force a new user session (ex: A user has logged in / out), there exists + */ + export function startNewSession(): Promise; + + /** + * You can also register a callback to be run when Taplytics creates a new session: + */ + export function setTaplyticsNewSessionListener(callback: () => void): void; + + } + export = Taplytics; }