Skip to content

Commit 3f4e07b

Browse files
authored
Merge pull request #58 from rescript-lang/notifications
Specify pushSubscriptionJSONKeys
2 parents 5bcdadd + 5505393 commit 3f4e07b

10 files changed

+47
-12
lines changed

src/EventAPI.res

+2-2
Original file line numberDiff line numberDiff line change
@@ -226,5 +226,5 @@ The ExtendableEvent interface extends the lifetime of the install and activate e
226226
*/
227227
@editor.completeFrom(ExtendableEvent)
228228
type extendableEvent = {
229-
...event
230-
}
229+
...event,
230+
}

src/NotificationAPI.res

+2-2
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ type notification = {
7373
type notificationAction = {
7474
action: string,
7575
title: string,
76-
icon?: string
76+
icon?: string,
7777
}
7878

7979
type notificationOptions = {
@@ -86,7 +86,7 @@ type notificationOptions = {
8686
mutable silent?: Null.t<bool>,
8787
mutable requireInteraction?: bool,
8888
mutable data?: JSON.t,
89-
mutable actions?: array<notificationAction>
89+
mutable actions?: array<notificationAction>,
9090
}
9191

9292
type getNotificationOptions = {mutable tag?: string}

src/PushAPI.res

+9-2
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,17 @@ type pushSubscriptionOptionsInit = {
6565
mutable applicationServerKey?: applicationServerKey,
6666
}
6767

68+
type pushSubscriptionJSONKeys = {
69+
/** Base64URL-encoded ArrayBuffer value */
70+
p256dh: string,
71+
/** Base64URL-encoded ArrayBuffer value */
72+
auth: string,
73+
}
74+
6875
type pushSubscriptionJSON = {
6976
mutable endpoint?: string,
7077
mutable expirationTime?: Null.t<int>,
71-
mutable keys?: any,
78+
mutable keys?: pushSubscriptionJSONKeys,
7279
}
7380

7481
@editor.completeFrom(PushMessageData)
@@ -81,4 +88,4 @@ type pushEvent = {
8188
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/PushEvent/data)
8289
*/
8390
data?: pushMessageData,
84-
}
91+
}

src/PushAPI/PushEvent.res

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
open PushAPI
22

33
include ExtendableEvent.Impl({
4-
type t = pushEvent;
5-
});
4+
type t = pushEvent
5+
})

src/PushAPI/PushMessageData.res

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ The text() method of the PushMessageData interface extracts push message data as
1212
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/PushMessageData/text)
1313
*/
1414
@send
15-
external text: pushMessageData => string = "text"
15+
external text: pushMessageData => string = "text"

src/ServiceWorkerAPI.res

+1-1
Original file line numberDiff line numberDiff line change
@@ -155,4 +155,4 @@ The WindowClient interface of the ServiceWorker API represents the scope of a se
155155
*/
156156
type windowClient = {
157157
...client,
158-
}
158+
}

src/ServiceWorkerAPI/ServiceWorkerGlobalScope.res

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ open ServiceWorkerAPI
22

33
include WorkerGlobalScope.Impl({
44
type t = serviceWorkerGlobalScope
5-
})
5+
})

src/WebWorkersAPI/WorkerGlobalScope.res

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ let response = await self->WorkerGlobalScope.fetch("https://rescript-lang.org")
2222
2323
[Read more on MDN](https://developer.mozilla.org/en-US/docs/Web/API/WorkerGlobalScope/fetch)
2424
*/
25-
@send
25+
@send
2626
external fetch: (T.t, string, ~init: requestInit=?) => promise<response> = "fetch"
2727

2828
/**

tests/Global__test.js

+21
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/Global__test.res

+7
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,10 @@ let subscription = await registrationResult.pushManager->PushManager.subscribe(
3737
applicationServerKey: ApplicationServerKey.fromString("MyPublicKey"),
3838
},
3939
)
40+
41+
let pushSubscriptionJSON = subscription->PushSubscription.toJSON
42+
let (auth, p256dh) = switch pushSubscriptionJSON.keys {
43+
| None => ("?", "?")
44+
| Some(keys) => (keys.auth, keys.p256dh)
45+
}
46+
Console.log(`For subscription ${subscription.endpoint}, auth is ${auth} and p256dh is ${p256dh}`)

0 commit comments

Comments
 (0)