Skip to content

Commit 328e54e

Browse files
committed
feat: added support for profile id in hyper
1 parent 062aa8e commit 328e54e

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

src/Index.res

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
open Types
22

3-
let loadHyper = (str, option: option<JSON.t>) => {
3+
let loadHyper = (hyperObject: JSON.t, option: option<JSON.t>) => {
4+
let str = switch hyperObject->JSON.Classify.classify {
5+
| String(val) => val
6+
| Object(json) =>
7+
json
8+
->Dict.get("publishableKey")
9+
->Option.flatMap(JSON.Decode.string)
10+
->Option.getOr("")
11+
| _ => ""
12+
}
413
Promise.make((resolve, reject) => {
514
let sessionID = generateSessionID()
615
let timeStamp = Date.now()
@@ -24,7 +33,7 @@ let loadHyper = (str, option: option<JSON.t>) => {
2433
script->Window.src(scriptURL)
2534
script->Window.onload(() => {
2635
switch HyperJs.hyperInstance->Nullable.toOption {
27-
| Some(instance) => resolve(instance(str, option, analyticsObj))
36+
| Some(instance) => resolve(instance(hyperObject, option, analyticsObj))
2837
| None => ()
2938
}
3039
})
@@ -37,7 +46,7 @@ let loadHyper = (str, option: option<JSON.t>) => {
3746
`INTEGRATION WARNING: There is already an existing script tag for ${scriptURL}. Multiple additions of HyperLoader.js is not permitted, please add it on the top level only once.`,
3847
)
3948
switch HyperJs.hyperInstance->Nullable.toOption {
40-
| Some(instance) => resolve(instance(str, option, analyticsObj))
49+
| Some(instance) => resolve(instance(hyperObject, option, analyticsObj))
4150
| None => ()
4251
}
4352
}

src/Types.res

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ type hyperInstance = {
5050
widgets: JSON.t => element,
5151
paymentRequest: JSON.t => JSON.t,
5252
}
53-
type hyperInstanceMake = (string, option<JSON.t>, JSON.t) => hyperInstance
53+
type hyperInstanceMake = (JSON.t, option<JSON.t>, JSON.t) => hyperInstance
5454

5555
let confirmPaymentFn = (_elements: JSON.t) => {
5656
Promise.resolve(Dict.make()->JSON.Encode.object)

0 commit comments

Comments
 (0)