-
-
Save pragmat1c/8e0c60dec3a797af2723d685ade879a3 to your computer and use it in GitHub Desktop.
Fullstory API typescript definitions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface Fullstory { | |
identify(uid: string, userVars?: object): void; | |
setUserVars(userVars: object): void; | |
getCurrentSessionURL(now?: boolean): string; | |
log(msg: string): void; | |
log(level: string, msg: string): void; | |
shutdown(): void; | |
restart(): void; | |
consent(consent: boolean): void; | |
event(eventName: string, eventProperties: object): void; | |
anonymize(); | |
} | |
declare var FS: Fullstory; |
Per the property name requirements we can refine the type for FS.event
a bit more:
event(
eventName: string,
eventProperties:
| { [key: `${string}_str`]: string }
| { [key: `${string}${'_int' | '_real'}`]: number }
| { [key: `${string}_date`]: Date }
| { [key: `${string}_bool`]: boolean }
| { [key: `${string}_strs`]: string[] }
| { [key: `${string}${'_ints' | '_reals'}`]: number[] }
| { [key: `${string}_dates`]: Date[] }
| { [key: `${string}_bools`]: boolean[] }
): void;
These restrictions seem to apply similarly for FS.setUserVars
and FS.identify
with a few exceptions for "reserved properties", you could add those too and it would look something like this:
setUserVars(
properties:
| { [key: `${string}_str`]: string }
| { [key: `${string}${'_int' | '_real'}`]: number }
| { [key: `${string}_date`]: Date }
| { [key: `${string}_bool`]: boolean }
| { [key: `${string}_strs`]: string[] }
| { [key: `${string}${'_ints' | '_reals'}`]: number[] }
| { [key: `${string}_dates`]: Date[] }
| { [key: `${string}_bools`]: boolean[] }
| 'uid'
| 'displayName'
| 'email'
| 'acctId'
| 'website'
): void;
Of course, we can take advantage of some aliases to clean this all up a bit. The final result would be more like so:
type TypedFSPropertyNames =
| { [key: `${string}_str`]: string }
| { [key: `${string}${'_int' | '_real'}`]: number }
| { [key: `${string}_date`]: Date }
| { [key: `${string}_bool`]: boolean }
| { [key: `${string}_strs`]: string[] }
| { [key: `${string}${'_ints' | '_reals'}`]: number[] }
| { [key: `${string}_dates`]: Date[] }
| { [key: `${string}_bools`]: boolean[] };
type ReservedFSPropertyNames =
| 'uid'
| 'displayName'
| 'email'
| 'acctId'
| 'website';
type Fullstory = {
identify(
uid: string,
userVars?: TypedFSPropertyNames & ReservedFSPropertyNames
);
setUserVars(properties: TypedFSPropertyNames & ReservedFSPropertyNames): void;
getCurrentSessionURL(now?: boolean): string;
log(msg: string): void;
log(level: string, msg: string): void;
shutdown(): void;
restart(): void;
consent(consent: boolean): void;
event(eventName: string, eventProperties: TypedFSPropertyNames): void;
};
declare var FS: Fullstory;
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Based on the API as documented here:
https://developer.fullstory.com/introduction