Skip to content

Specify pushSubscriptionJSONKeys #58

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/EventAPI.res
Original file line number Diff line number Diff line change
Expand Up @@ -226,5 +226,5 @@ The ExtendableEvent interface extends the lifetime of the install and activate e
*/
@editor.completeFrom(ExtendableEvent)
type extendableEvent = {
...event
}
...event,
}
4 changes: 2 additions & 2 deletions src/NotificationAPI.res
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ type notification = {
type notificationAction = {
action: string,
title: string,
icon?: string
icon?: string,
}

type notificationOptions = {
Expand All @@ -86,7 +86,7 @@ type notificationOptions = {
mutable silent?: Null.t<bool>,
mutable requireInteraction?: bool,
mutable data?: JSON.t,
mutable actions?: array<notificationAction>
mutable actions?: array<notificationAction>,
}

type getNotificationOptions = {mutable tag?: string}
Expand Down
11 changes: 9 additions & 2 deletions src/PushAPI.res
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,17 @@ type pushSubscriptionOptionsInit = {
mutable applicationServerKey?: applicationServerKey,
}

type pushSubscriptionJSONKeys = {
/** Base64URL-encoded ArrayBuffer value */
p256dh: string,
/** Base64URL-encoded ArrayBuffer value */
auth: string,
}

type pushSubscriptionJSON = {
mutable endpoint?: string,
mutable expirationTime?: Null.t<int>,
mutable keys?: any,
mutable keys?: pushSubscriptionJSONKeys,
}

@editor.completeFrom(PushMessageData)
Expand All @@ -81,4 +88,4 @@ type pushEvent = {
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/PushEvent/data)
*/
data?: pushMessageData,
}
}
4 changes: 2 additions & 2 deletions src/PushAPI/PushEvent.res
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
open PushAPI

include ExtendableEvent.Impl({
type t = pushEvent;
});
type t = pushEvent
})
2 changes: 1 addition & 1 deletion src/PushAPI/PushMessageData.res
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ The text() method of the PushMessageData interface extracts push message data as
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/PushMessageData/text)
*/
@send
external text: pushMessageData => string = "text"
external text: pushMessageData => string = "text"
2 changes: 1 addition & 1 deletion src/ServiceWorkerAPI.res
Original file line number Diff line number Diff line change
Expand Up @@ -155,4 +155,4 @@ The WindowClient interface of the ServiceWorker API represents the scope of a se
*/
type windowClient = {
...client,
}
}
2 changes: 1 addition & 1 deletion src/ServiceWorkerAPI/ServiceWorkerGlobalScope.res
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ open ServiceWorkerAPI

include WorkerGlobalScope.Impl({
type t = serviceWorkerGlobalScope
})
})
2 changes: 1 addition & 1 deletion src/WebWorkersAPI/WorkerGlobalScope.res
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ let response = await self->WorkerGlobalScope.fetch("https://rescript-lang.org")

[Read more on MDN](https://developer.mozilla.org/en-US/docs/Web/API/WorkerGlobalScope/fetch)
*/
@send
@send
external fetch: (T.t, string, ~init: requestInit=?) => promise<response> = "fetch"

/**
Expand Down
21 changes: 21 additions & 0 deletions tests/Global__test.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions tests/Global__test.res
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,10 @@ let subscription = await registrationResult.pushManager->PushManager.subscribe(
applicationServerKey: ApplicationServerKey.fromString("MyPublicKey"),
},
)

let pushSubscriptionJSON = subscription->PushSubscription.toJSON
let (auth, p256dh) = switch pushSubscriptionJSON.keys {
| None => ("?", "?")
| Some(keys) => (keys.auth, keys.p256dh)
}
Console.log(`For subscription ${subscription.endpoint}, auth is ${auth} and p256dh is ${p256dh}`)
Loading