-
Notifications
You must be signed in to change notification settings - Fork 568
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
create shopper session class; add identify
- Loading branch information
Showing
5 changed files
with
76 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* @flow */ | ||
/* eslint-disable eslint-comments/disable-enable-pair */ | ||
/* eslint-disable no-restricted-globals, promise/no-native */ | ||
import { load as loadFingerprintJS } from "@fingerprintjs/fingerprintjs-pro"; | ||
|
||
const __FINGERPRINT_JS_API_KEY__ = "Eh4QKkI51U0rVUUPeQT8"; | ||
|
||
type FingerprintResults = {| | ||
requestId: string, | ||
|}; | ||
|
||
type Fingerprinter = {| | ||
get: () => Promise<FingerprintResults>, | ||
|}; | ||
|
||
export class Fingerprint { | ||
fingerprinter: ?Fingerprinter; | ||
results: ?FingerprintResults; | ||
|
||
async load(): Promise<void> { | ||
if (!this.fingerprinter) { | ||
this.fingerprinter = await loadFingerprintJS({ | ||
apiKey: __FINGERPRINT_JS_API_KEY__, | ||
}); | ||
} | ||
} | ||
|
||
async collect(): Promise<FingerprintResults> { | ||
if (this.results && this.results.requestId) { | ||
return this.results; | ||
} | ||
|
||
if (!this.fingerprinter) { | ||
await this.load(); | ||
} | ||
|
||
if (!this.fingerprinter) { | ||
throw new Error("fingerprint library failed to load"); | ||
} | ||
|
||
this.results = await this.fingerprinter.get(); | ||
|
||
return this.results; | ||
} | ||
|
||
get(): Promise<FingerprintResults> { | ||
return this.collect(); | ||
} | ||
} | ||
|
||
// $FlowIssue flow is bad with classes | ||
export const fingerprint = new Fingerprint(); |
This file contains 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
This file contains 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
This file contains 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