Skip to content

Commit df5ae0d

Browse files
committed
Add bindings for push notifications using service worker
1 parent d0872d0 commit df5ae0d

35 files changed

+448
-45
lines changed

src/DOMAPI.res

+1-4
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,14 @@ open MediaCaptureAndStreamsAPI
1010
open MediaSessionAPI
1111
open PermissionsAPI
1212
open ScreenWakeLockAPI
13+
open WebWorkersAPI
1314
open ServiceWorkerAPI
1415
open EncryptedMediaExtensionsAPI
15-
open GamepadAPI
1616
open FileAPI
17-
open WebMIDIAPI
1817
open HistoryAPI
1918
open VisualViewportAPI
2019
open WebSpeechAPI
21-
open ViewTransitionsAPI
2220
open FileAndDirectoryEntriesAPI
23-
open WebVTTAPI
2421
open RemotePlaybackAPI
2522
open CanvasAPI
2623
open StorageAPI

src/EventAPI.res

+11
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ type eventType =
5151
| @as("mouseout") Mouseout
5252
| @as("mouseover") Mouseover
5353
| @as("mouseup") Mouseup
54+
| @as("notificationclick") NotificationClick
5455
| @as("paste") Paste
5556
| @as("pause") Pause
5657
| @as("play") Play
@@ -94,6 +95,7 @@ type eventType =
9495
| @as("pointercancel") Pointercancel
9596
| @as("pointerout") Pointerout
9697
| @as("pointerleave") Pointerleave
98+
| @as("push") Push
9799
| @as("gotpointercapture") Gotpointercapture
98100
| @as("lostpointercapture") Lostpointercapture
99101
| @as("selectstart") Selectstart
@@ -217,3 +219,12 @@ type eventInit = {
217219
mutable cancelable?: bool,
218220
mutable composed?: bool,
219221
}
222+
223+
/**
224+
The ExtendableEvent interface extends the lifetime of the install and activate events dispatched on the global scope as part of the service worker lifecycle.
225+
[See ExtendableEvent on MDN](https://developer.mozilla.org/docs/Web/API/ExtendableEvent)
226+
*/
227+
@editor.completeFrom(ExtendableEvent)
228+
type extendableEvent = {
229+
...event
230+
}

src/EventAPI/ExtendableEvent.js

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

src/EventAPI/ExtendableEvent.res

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
open EventAPI
2+
3+
module Impl = (
4+
T: {
5+
type t
6+
},
7+
) => {
8+
external asExtendableEvent: T.t => extendableEvent = "%identity"
9+
10+
include Event.Impl({
11+
type t = T.t
12+
})
13+
14+
@send
15+
external waitUntil: (T.t, promise<'a>) => unit = "waitUntil"
16+
}
17+
18+
include Impl({
19+
type t = extendableEvent
20+
})

src/Global.res

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ open WebSpeechAPI
55
open IndexedDBAPI
66
open WebCryptoAPI
77
open PerformanceAPI
8-
open ServiceWorkerAPI
8+
open WebWorkersAPI
99
open WebStorageAPI
1010
open CanvasAPI
1111
open FileAPI

src/NotificationAPI.res

+24-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,17 @@ type notification = {
6363
/**
6464
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/Notification/data)
6565
*/
66-
data: JSON.t,
66+
data?: JSON.t,
67+
}
68+
69+
/**
70+
An array of actions to display in the notification, for which the default is an empty array.
71+
[Read more on MDN](https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerRegistration/showNotification#actions)
72+
*/
73+
type notificationAction = {
74+
action: string,
75+
title: string,
76+
icon?: string
6777
}
6878

6979
type notificationOptions = {
@@ -76,8 +86,21 @@ type notificationOptions = {
7686
mutable silent?: Null.t<bool>,
7787
mutable requireInteraction?: bool,
7888
mutable data?: JSON.t,
89+
mutable actions?: array<notificationAction>
7990
}
8091

8192
type getNotificationOptions = {mutable tag?: string}
8293

8394
type notificationPermissionCallback = notificationPermission => unit
95+
96+
type notificationEvent = {
97+
...extendableEvent,
98+
/**
99+
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/NotificationEvent/action)
100+
*/
101+
action: string,
102+
/**
103+
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/NotificationEvent/notification)
104+
*/
105+
notification: notification,
106+
}
File renamed without changes.

src/PushManagerAPI.res renamed to src/PushAPI.res

+17-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
@@warning("-30")
22

33
open Prelude
4+
open EventAPI
45

56
type permissionState =
67
| @as("denied") Denied
@@ -23,6 +24,8 @@ type pushManager = {
2324
supportedContentEncodings: array<string>,
2425
}
2526

27+
type applicationServerKey
28+
2629
/**
2730
[See PushSubscriptionOptions on MDN](https://developer.mozilla.org/docs/Web/API/PushSubscriptionOptions)
2831
*/
@@ -34,7 +37,7 @@ type pushSubscriptionOptions = {
3437
/**
3538
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/PushSubscriptionOptions/applicationServerKey)
3639
*/
37-
applicationServerKey: Null.t<ArrayBuffer.t>,
40+
applicationServerKey: applicationServerKey,
3841
}
3942

4043
/**
@@ -59,11 +62,23 @@ type pushSubscription = {
5962

6063
type pushSubscriptionOptionsInit = {
6164
mutable userVisibleOnly?: bool,
62-
mutable applicationServerKey?: Null.t<unknown>,
65+
mutable applicationServerKey?: applicationServerKey,
6366
}
6467

6568
type pushSubscriptionJSON = {
6669
mutable endpoint?: string,
6770
mutable expirationTime?: Null.t<int>,
6871
mutable keys?: any,
6972
}
73+
74+
@editor.completeFrom(PushMessageData)
75+
type pushMessageData
76+
77+
@editor.completeFrom(PushEvent)
78+
type pushEvent = {
79+
...extendableEvent,
80+
/**
81+
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/PushEvent/data)
82+
*/
83+
data?: pushMessageData,
84+
}

src/PushAPI/ApplicationServerKey.res

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
open PushAPI
2+
3+
external fromString: string => applicationServerKey = "%identity"
4+
external fromUint8Array: Uint8Array.t => applicationServerKey = "%identity"

src/PushAPI/PushEvent.js

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

src/PushAPI/PushEvent.res

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
open PushAPI
2+
3+
include ExtendableEvent.Impl({
4+
type t = pushEvent;
5+
});
File renamed without changes.

src/PushManagerAPI/PushManager.res renamed to src/PushAPI/PushManager.res

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
open PushManagerAPI
1+
open PushAPI
22

33
/**
44
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/PushManager/subscribe)
File renamed without changes.

src/PushAPI/PushMessageData.res

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
open PushAPI
2+
3+
/**
4+
The json() method of the PushMessageData interface extracts push message data by parsing it as a JSON string and returning the result.
5+
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/PushMessageData/json)
6+
*/
7+
@send
8+
external json: pushMessageData => JSON.t = "json"
9+
10+
/**
11+
The text() method of the PushMessageData interface extracts push message data as a plain text string.
12+
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/PushMessageData/text)
13+
*/
14+
@send
15+
external text: pushMessageData => string = "text"

src/PushAPI/PushSubscription.js

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

src/PushManagerAPI/PushSubscription.res renamed to src/PushAPI/PushSubscription.res

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
open PushManagerAPI
1+
open PushAPI
22

33
/**
44
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/PushSubscription/getKey)

src/ServiceWorkerAPI.res

+44-26
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@
22

33
open Prelude
44
open EventAPI
5-
open PushManagerAPI
6-
open NotificationAPI
7-
open FetchAPI
8-
open ChannelMessagingAPI
5+
open PushAPI
6+
open WebWorkersAPI
97

108
type serviceWorkerState =
119
| @as("activated") Activated
@@ -101,20 +99,6 @@ type serviceWorkerContainer = {
10199
ready: promise<serviceWorkerRegistration>,
102100
}
103101

104-
/**
105-
The storage for Cache objects.
106-
[See CacheStorage on MDN](https://developer.mozilla.org/docs/Web/API/CacheStorage)
107-
*/
108-
@editor.completeFrom(CacheStorage)
109-
type cacheStorage = {}
110-
111-
/**
112-
Provides a storage mechanism for Request / Response object pairs that are cached, for example as part of the ServiceWorker life cycle. Note that the Cache interface is exposed to windowed scopes as well as workers. You don't have to use it in conjunction with service workers, even though it is defined in the service worker spec.
113-
[See Cache on MDN](https://developer.mozilla.org/docs/Web/API/Cache)
114-
*/
115-
@editor.completeFrom(Cache)
116-
type cache = {}
117-
118102
type navigationPreloadState = {
119103
mutable enabled?: bool,
120104
mutable headerValue?: string,
@@ -126,15 +110,49 @@ type registrationOptions = {
126110
mutable updateViaCache?: serviceWorkerUpdateViaCache,
127111
}
128112

129-
type cacheQueryOptions = {
130-
mutable ignoreSearch?: bool,
131-
mutable ignoreMethod?: bool,
132-
mutable ignoreVary?: bool,
113+
type requestInfo = any
114+
115+
/**
116+
The Clients interface provides access to Client objects. Access it via self.clients within a service worker.
117+
[See Clients on MDN](https://developer.mozilla.org/en-US/docs/Web/API/Clients)
118+
*/
119+
@editor.completeFrom(Clients)
120+
type clients
121+
122+
/**
123+
The ServiceWorkerGlobalScope interface of the Service Worker API represents the global execution context of a service worker.
124+
[See ServiceWorkerGlobalScope on MDN](https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerGlobalScope)
125+
*/
126+
@editor.completeFrom(ServiceWorkerGlobalScope)
127+
type serviceWorkerGlobalScope = {
128+
...workerGlobalScope,
129+
/**
130+
[Read more on MDN](https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerGlobalScope/clients)
131+
*/
132+
clients: clients,
133+
/**
134+
[Read more on MDN](https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerGlobalScope/registration)
135+
*/
136+
registration: serviceWorkerRegistration,
133137
}
134138

135-
type multiCacheQueryOptions = {
136-
...cacheQueryOptions,
137-
mutable cacheName?: string,
139+
/**
140+
The Client interface represents an executable context such as a Worker, or a SharedWorker. Window clients are represented by the more-specific WindowClient.
141+
[See Client on MDN](https://developer.mozilla.org/en-US/docs/Web/API/Client)
142+
*/
143+
type client = {
144+
/**
145+
[Read more on MDN](https://developer.mozilla.org/en-US/docs/Web/API/Client/id)
146+
*/
147+
id: string,
148+
/** [Read more on MDN](https://developer.mozilla.org/en-US/docs/Web/API/Client/url) */
149+
url: string,
138150
}
139151

140-
type requestInfo = any
152+
/**
153+
The WindowClient interface of the ServiceWorker API represents the scope of a service worker client that is a document in a browsing context, controlled by an active worker.
154+
[See WindowClient on MDN](https://developer.mozilla.org/en-US/docs/Web/API/WindowClient)
155+
*/
156+
type windowClient = {
157+
...client,
158+
}

src/ServiceWorkerAPI/Cache.res

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
open FetchAPI
2-
open ServiceWorkerAPI
2+
open WebWorkersAPI
33

44
/**
55
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/Cache/match)

src/ServiceWorkerAPI/Clients.js

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

src/ServiceWorkerAPI/Clients.res

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
open ServiceWorkerAPI
2+
3+
@send
4+
external openWindow: (clients, string) => promise<windowClient> = "open"

src/ServiceWorkerAPI/ServiceWorkerGlobalScope.js

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
open ServiceWorkerAPI
2+
3+
include WorkerGlobalScope.Impl({
4+
type t = serviceWorkerGlobalScope
5+
})

src/WebWorkersAPI.js

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

0 commit comments

Comments
 (0)