Compare commits
38 Commits
spike-noti
...
master
| Author | SHA1 | Date |
|---|---|---|
|
|
f78d448a0b | |
|
|
683c685b7d | |
|
|
d5f474768c | |
|
|
3a56b9f853 | |
|
|
37f32cce3a | |
|
|
e9c7d7a8ef | |
|
|
75087f2121 | |
|
|
a719706dff | |
|
|
be55d46391 | |
|
|
277ee9f2b5 | |
|
|
d1f20c4a2b | |
|
|
b992443a99 | |
|
|
8feb9bd37a | |
|
|
d66c72ce96 | |
|
|
e88b953c58 | |
|
|
fdbf8c5ca5 | |
|
|
2031e8a3e7 | |
|
|
06e82c4f3f | |
|
|
5c230f8e5c | |
|
|
8aad5028ab | |
|
|
6f6a1bc2dc | |
|
|
6334b63631 | |
|
|
26344fbdb2 | |
|
|
d2860dc454 | |
|
|
cfd6a40859 | |
|
|
206ce42655 | |
|
|
20e7099317 | |
|
|
cbdaea7f75 | |
|
|
384a65f2dc | |
|
|
28bfe4c755 | |
|
|
dfb20a1cbe | |
|
|
16530e0505 | |
|
|
71d5706320 | |
|
|
d7ef727558 | |
|
|
45ec236839 | |
|
|
a475f7f4bf | |
|
|
c0821776c1 | |
|
|
34372bdb89 |
|
|
@ -1 +1,2 @@
|
||||||
data/
|
data/
|
||||||
|
data-test/
|
||||||
|
|
@ -0,0 +1,6 @@
|
||||||
|
DATABASE="postgres"
|
||||||
|
POSTGRES_PASSWORD="testpassword"
|
||||||
|
POSTGRES_HOST="database"
|
||||||
|
POSTGRES_PORT=5432
|
||||||
|
VAPID_PRIVATE_KEY="privatekey"
|
||||||
|
BASE_URL="http://localhost:5173"
|
||||||
|
|
@ -1,4 +1,6 @@
|
||||||
DATABASE="postgres"
|
DATABASE="postgres"
|
||||||
POSTGRES_PASSWORD="testpassword"
|
POSTGRES_PASSWORD="testpassword"
|
||||||
|
POSTGRES_HOST="localhost"
|
||||||
|
POSTGRES_PORT=5434
|
||||||
VAPID_PRIVATE_KEY="privatekey"
|
VAPID_PRIVATE_KEY="privatekey"
|
||||||
BASE_URL="http://localhost:5173"
|
BASE_URL="http://localhost:5173"
|
||||||
|
|
@ -5,6 +5,27 @@ on: [push]
|
||||||
jobs:
|
jobs:
|
||||||
test:
|
test:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
container: mcr.microsoft.com/playwright:v1.48.1-jammy
|
||||||
|
services:
|
||||||
|
database:
|
||||||
|
image: postgres:16
|
||||||
|
env:
|
||||||
|
POSTGRES_PASSWORD: testpassword
|
||||||
|
POSTGRES_USER: postgres
|
||||||
|
POSTGRES_DB: test
|
||||||
|
options: >-
|
||||||
|
--health-cmd pg_isready
|
||||||
|
--health-interval 10s
|
||||||
|
--health-timeout 5s
|
||||||
|
--health-retries 5
|
||||||
|
ports:
|
||||||
|
- 5434:5432
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- run: npm install && npm run test && npx playwright install && npx playwright test
|
- name: Run Tests
|
||||||
|
env: NODE_OPTIONS=--max-old-space-size=8192
|
||||||
|
run: |
|
||||||
|
npm install
|
||||||
|
npm run ci
|
||||||
|
npm ci
|
||||||
|
npx playwright test
|
||||||
|
|
|
||||||
|
|
@ -8,3 +8,4 @@ build/
|
||||||
/playwright-report/
|
/playwright-report/
|
||||||
/blob-report/
|
/blob-report/
|
||||||
/playwright/.cache/
|
/playwright/.cache/
|
||||||
|
send-it.js
|
||||||
|
|
@ -8,7 +8,7 @@ app.use(express.json())
|
||||||
|
|
||||||
app.get("/api", (req, res) => res.send("HI"))
|
app.get("/api", (req, res) => res.send("HI"))
|
||||||
|
|
||||||
app.post("/api/subscription/", postSubscription)
|
app.post("/api/subscription", postSubscription)
|
||||||
app.put("/api/subscription/:id/", putSubscription)
|
app.put("/api/subscription/:id/", putSubscription)
|
||||||
|
|
||||||
export default app
|
export default app
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,13 @@ const dialect = new PostgresDialect({
|
||||||
}),
|
}),
|
||||||
})
|
})
|
||||||
|
|
||||||
export const db = new Kysely<Database>({
|
export let db = new Kysely<Database>({
|
||||||
dialect,
|
dialect,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
export async function resetDbInstance() {
|
||||||
|
await db.destroy()
|
||||||
|
db = new Kysely<Database>({
|
||||||
|
dialect,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
export default {
|
export default {
|
||||||
database: process.env.DATABASE ?? "postgres",
|
database: process.env.DATABASE ?? "postgres",
|
||||||
host: "database",
|
host: process.env.POSTGRES_HOST ?? "database",
|
||||||
user: "postgres",
|
user: "postgres",
|
||||||
password: process.env.POSTGRES_PASSWORD,
|
password: process.env.POSTGRES_PASSWORD,
|
||||||
port: 5432,
|
port: process.env.POSTGRES_PORT ?? 5432,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { db } from "./database"
|
import { db, resetDbInstance } from "./database"
|
||||||
import migrateToLatest, { resetAll } from "./migrate"
|
import migrateToLatest, { resetAll } from "./migrate"
|
||||||
import {
|
import {
|
||||||
createSubscription,
|
createSubscription,
|
||||||
|
|
@ -26,17 +26,29 @@ const pushSubscription2 = {
|
||||||
}
|
}
|
||||||
|
|
||||||
jest.mock("./settings", () => ({
|
jest.mock("./settings", () => ({
|
||||||
port: 5434,
|
port: process.env.POSTGRES_PORT,
|
||||||
user: "postgres",
|
user: "postgres",
|
||||||
password: process.env.POSTGRES_PASSWORD,
|
password: process.env.POSTGRES_PASSWORD,
|
||||||
database: "test",
|
database: "test",
|
||||||
host: "localhost",
|
host: process.env.POSTGRES_HOST,
|
||||||
}))
|
}))
|
||||||
|
|
||||||
describe("subscriptions", () => {
|
describe("subscriptions", () => {
|
||||||
beforeEach(migrateToLatest)
|
beforeAll(async () => {
|
||||||
|
await resetDbInstance()
|
||||||
|
})
|
||||||
|
|
||||||
afterEach(resetAll)
|
beforeEach(async () => {
|
||||||
|
await migrateToLatest()
|
||||||
|
})
|
||||||
|
|
||||||
|
afterEach(async () => {
|
||||||
|
await resetAll()
|
||||||
|
})
|
||||||
|
|
||||||
|
afterAll(async () => {
|
||||||
|
await db.destroy()
|
||||||
|
})
|
||||||
|
|
||||||
test("createSubscription", async () => {
|
test("createSubscription", async () => {
|
||||||
const { id } = await createSubscription(pushSubscription1)
|
const { id } = await createSubscription(pushSubscription1)
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,10 @@ describe("/api/subscription", () => {
|
||||||
mockedCreateSubscription.mockImplementation((subscription) =>
|
mockedCreateSubscription.mockImplementation((subscription) =>
|
||||||
Promise.resolve({ id: 40, subscription })
|
Promise.resolve({ id: 40, subscription })
|
||||||
)
|
)
|
||||||
|
|
||||||
|
mockedUpdateSubscription.mockImplementation((subscription, id) =>
|
||||||
|
Promise.resolve({ id, subscription })
|
||||||
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
test("POST", async () => {
|
test("POST", async () => {
|
||||||
|
|
|
||||||
|
|
@ -5,8 +5,6 @@ import { createSubscription } from "../data/subscription"
|
||||||
export async function postSubscription(req: Request, res: Response) {
|
export async function postSubscription(req: Request, res: Response) {
|
||||||
const subscriptionBody = req.body
|
const subscriptionBody = req.body
|
||||||
|
|
||||||
console.log("Posted subscription", subscriptionBody)
|
|
||||||
|
|
||||||
const { id: subscriptionId } = await createSubscription(subscriptionBody)
|
const { id: subscriptionId } = await createSubscription(subscriptionBody)
|
||||||
|
|
||||||
res.status(200).send({ subscriptionId })
|
res.status(200).send({ subscriptionId })
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,8 @@
|
||||||
import React, { useState } from "react"
|
import React from "react"
|
||||||
import { useEffect } from "react"
|
import { useEffect } from "react"
|
||||||
import { usePush } from "../usePush"
|
import { usePush } from "../usePush"
|
||||||
import { request } from "http"
|
|
||||||
import urlB64ToUint8Array from "../../b64ToUInt8"
|
|
||||||
import pushPublicKey from "../../pushPublicKey"
|
import pushPublicKey from "../../pushPublicKey"
|
||||||
|
import urlB64ToUint8Array from "../../b64ToUInt8"
|
||||||
|
|
||||||
export default function EnableNotifications({
|
export default function EnableNotifications({
|
||||||
onSubscribe,
|
onSubscribe,
|
||||||
|
|
@ -25,9 +24,6 @@ export default function EnableNotifications({
|
||||||
function EnableButton({ onSubscribe }: { onSubscribe: () => void }) {
|
function EnableButton({ onSubscribe }: { onSubscribe: () => void }) {
|
||||||
const { subscribeToPush, requestPermission, canSendPush } = usePush()
|
const { subscribeToPush, requestPermission, canSendPush } = usePush()
|
||||||
|
|
||||||
const [error, setError] = useState<Error>()
|
|
||||||
const [log, setLog] = useState<string[]>([])
|
|
||||||
|
|
||||||
function subscribe() {
|
function subscribe() {
|
||||||
requestPermission()
|
requestPermission()
|
||||||
}
|
}
|
||||||
|
|
@ -35,45 +31,19 @@ function EnableButton({ onSubscribe }: { onSubscribe: () => void }) {
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!canSendPush) return
|
if (!canSendPush) return
|
||||||
|
|
||||||
setLog((prev) => [...prev, "Subscribing to push notifications"])
|
|
||||||
|
|
||||||
subscribeToPush(
|
subscribeToPush(
|
||||||
urlB64ToUint8Array(pushPublicKey) as any,
|
urlB64ToUint8Array(pushPublicKey) as any,
|
||||||
(subscription) => {
|
async (subscription) => {
|
||||||
setLog((prev) => [
|
await navigator.serviceWorker.ready.then((registration) => {
|
||||||
...prev,
|
|
||||||
`controller is undefined? ${navigator.serviceWorker.controller === undefined}`,
|
|
||||||
])
|
|
||||||
setLog((prev) => [
|
|
||||||
...prev,
|
|
||||||
`subscriptions: ${JSON.stringify(subscription.toJSON())}`,
|
|
||||||
])
|
|
||||||
try {
|
|
||||||
navigator.serviceWorker.ready.then((registration) => {
|
|
||||||
registration.active?.postMessage({
|
registration.active?.postMessage({
|
||||||
type: "subscribed",
|
type: "subscribed",
|
||||||
subscription: subscription.toJSON(),
|
subscription: subscription.toJSON(),
|
||||||
})
|
})
|
||||||
setLog((prev) => [...prev, "After post message"])
|
|
||||||
})
|
})
|
||||||
// onSubscribe()
|
onSubscribe()
|
||||||
} catch (error) {
|
|
||||||
setError(error as Error)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
(error) => {
|
|
||||||
setError(error)
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}, [canSendPush])
|
}, [canSendPush])
|
||||||
|
|
||||||
return (
|
return <button onClick={subscribe}>Enable Notifications</button>
|
||||||
<>
|
|
||||||
<button onClick={subscribe}>Enable Notifications</button>
|
|
||||||
<div>{error?.toString()}</div>
|
|
||||||
{log.map((log, index) => (
|
|
||||||
<div key={index}>{log}</div>
|
|
||||||
))}
|
|
||||||
</>
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -93,21 +93,10 @@ function TackUpNow({
|
||||||
|
|
||||||
const [isInstalled, setIsInstalled] = useState(installed)
|
const [isInstalled, setIsInstalled] = useState(installed)
|
||||||
|
|
||||||
const [messages, setMessages] = useState<any[]>([])
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
navigator.serviceWorker.onmessage = (event) =>
|
|
||||||
setMessages((prev) => [...prev, JSON.stringify(event.data)])
|
|
||||||
}, [])
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ClientOnly fallback={<div>Loading</div>}>
|
<ClientOnly fallback={<div>Loading</div>}>
|
||||||
{() => (
|
{() =>
|
||||||
<>
|
isInstalled ? (
|
||||||
{messages.map((message, index) => (
|
|
||||||
<div key={index}>{JSON.stringify(message)}</div>
|
|
||||||
))}
|
|
||||||
{isInstalled ? (
|
|
||||||
<div>Your Notifications</div>
|
<div>Your Notifications</div>
|
||||||
) : (
|
) : (
|
||||||
<InstallPrompts
|
<InstallPrompts
|
||||||
|
|
@ -117,9 +106,8 @@ function TackUpNow({
|
||||||
notificationsEnabled={false}
|
notificationsEnabled={false}
|
||||||
onInstallComplete={() => setIsInstalled(true)}
|
onInstallComplete={() => setIsInstalled(true)}
|
||||||
/>
|
/>
|
||||||
)}
|
)
|
||||||
</>
|
}
|
||||||
)}
|
|
||||||
</ClientOnly>
|
</ClientOnly>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,64 +3,167 @@ import "core-js/stable/structured-clone"
|
||||||
import initWorker from "./worker"
|
import initWorker from "./worker"
|
||||||
import Dexie, { EntityTable } from "dexie"
|
import Dexie, { EntityTable } from "dexie"
|
||||||
|
|
||||||
|
function createSubscription(testToken = "HI") {
|
||||||
|
return {
|
||||||
|
toJSON: () => ({
|
||||||
|
subscription: testToken,
|
||||||
|
}),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const createSelf = () =>
|
const createSelf = () =>
|
||||||
({
|
({
|
||||||
addEventListener: jest.fn(),
|
addEventListener: jest.fn(),
|
||||||
skipWaiting: jest.fn(() => Promise.resolve()),
|
skipWaiting: jest.fn(() => Promise.resolve()),
|
||||||
registration: {
|
registration: {
|
||||||
pushManager: {
|
pushManager: {
|
||||||
subscribe: jest.fn(() => Promise.resolve({ subscription: "HI" })),
|
subscribe: jest.fn(() => Promise.resolve(createSubscription())),
|
||||||
getSubscription: jest.fn(() => Promise.resolve({ subscription: "HI" })),
|
getSubscription: jest.fn(() => Promise.resolve(createSubscription())),
|
||||||
},
|
},
|
||||||
|
showNotification: jest.fn(),
|
||||||
},
|
},
|
||||||
clients: {
|
clients: {
|
||||||
claim: jest.fn(() => Promise.resolve()),
|
claim: jest.fn(() => Promise.resolve()),
|
||||||
|
openWindow: jest.fn(() => Promise.resolve()),
|
||||||
|
matchAll: jest.fn(() => Promise.resolve([])),
|
||||||
},
|
},
|
||||||
}) as unknown as ServiceWorkerGlobalScope
|
}) as unknown as ServiceWorkerGlobalScope
|
||||||
|
|
||||||
|
let originalWindow: Window & typeof globalThis
|
||||||
|
|
||||||
describe("service worker", () => {
|
describe("service worker", () => {
|
||||||
let self: ServiceWorkerGlobalScope
|
let self: ServiceWorkerGlobalScope
|
||||||
|
let controlledClients: Client[]
|
||||||
|
let uncontrolledClients: Client[]
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
|
originalWindow = global.window
|
||||||
|
global.window = undefined as any
|
||||||
indexedDB = new IDBFactory()
|
indexedDB = new IDBFactory()
|
||||||
self = createSelf()
|
self = createSelf()
|
||||||
|
controlledClients = []
|
||||||
// fetchMock.mockIf(/http:\/\/localhost\/api\/subscribe\/?/, (req) => {
|
uncontrolledClients = []
|
||||||
// return Promise.resolve(
|
|
||||||
// req.method === "POST"
|
|
||||||
// ? {
|
|
||||||
// body: JSON.stringify({ subscriptionId: 123 }),
|
|
||||||
// }
|
|
||||||
// : req.method === "PUT"
|
|
||||||
// ? { init: { status: 200 } }
|
|
||||||
// : { init: { status: 405 } }
|
|
||||||
// )
|
|
||||||
// })
|
|
||||||
|
|
||||||
fetchMock.mockResponse((req) => {
|
fetchMock.mockResponse((req) => {
|
||||||
return Promise.resolve(
|
if (
|
||||||
|
req.url.replace(/https?:\/\/[a-zA-Z0-9\.]*/, "") ===
|
||||||
|
"/api/subscription/" &&
|
||||||
req.method === "POST"
|
req.method === "POST"
|
||||||
? {
|
) {
|
||||||
|
return Promise.resolve({
|
||||||
body: JSON.stringify({ subscriptionId: 123 }),
|
body: JSON.stringify({ subscriptionId: 123 }),
|
||||||
|
})
|
||||||
|
} else if (
|
||||||
|
req.url
|
||||||
|
.replace(/https?:\/\/[a-zA-Z0-9\.]*/, "")
|
||||||
|
.startsWith("/api/subscription/") &&
|
||||||
|
req.method === "PUT"
|
||||||
|
) {
|
||||||
|
return Promise.resolve({ init: { status: 200 } })
|
||||||
}
|
}
|
||||||
: req.method === "PUT"
|
|
||||||
? { init: { status: 200 } }
|
return Promise.resolve({ init: { status: 500 } })
|
||||||
: { init: { status: 405 } }
|
|
||||||
)
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
jest.clearAllMocks()
|
jest.clearAllMocks()
|
||||||
|
global.window = originalWindow
|
||||||
})
|
})
|
||||||
|
|
||||||
xtest("displays push notifications", () => {
|
test("displays push notifications", async () => {
|
||||||
initWorker(self)
|
initWorker(self)
|
||||||
|
|
||||||
const pushHandler = getHandler("push")
|
const pushHandler = getHandler("push")
|
||||||
|
|
||||||
const pushEvent = createEvent({ data: "HI" })
|
const pushEvent = createPushEvent(
|
||||||
|
JSON.stringify({
|
||||||
|
title: "Test title",
|
||||||
|
body: "Test text",
|
||||||
|
icon: "Test icon",
|
||||||
|
badge: "Test badge",
|
||||||
|
destination: "tackupnow.com/hi",
|
||||||
|
})
|
||||||
|
)
|
||||||
pushHandler(pushEvent)
|
pushHandler(pushEvent)
|
||||||
|
await waitUntilCalls(pushEvent)
|
||||||
|
|
||||||
|
expect(self.registration.showNotification).toHaveBeenCalledWith(
|
||||||
|
"Test title",
|
||||||
|
{
|
||||||
|
body: "Test text",
|
||||||
|
icon: "Test icon",
|
||||||
|
badge: "Test badge",
|
||||||
|
data: { destination: "tackupnow.com/hi" },
|
||||||
|
}
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
describe("on notification click", () => {
|
||||||
|
test("the notification is closed", async () => {
|
||||||
|
initWorker(self)
|
||||||
|
|
||||||
|
const notificationHandler = getHandler("notificationclick")
|
||||||
|
|
||||||
|
const event = createNotificationEvent("tackupnow.com")
|
||||||
|
notificationHandler(event)
|
||||||
|
await waitUntilCalls(event)
|
||||||
|
|
||||||
|
expect(event.notification.close).toHaveBeenCalled()
|
||||||
|
})
|
||||||
|
|
||||||
|
test("opens tack up now if no clients match the destination", async () => {
|
||||||
|
initWorker(self)
|
||||||
|
|
||||||
|
const notificationHandler = getHandler("notificationclick")
|
||||||
|
|
||||||
|
const event = createNotificationEvent("tackupnow.com")
|
||||||
|
notificationHandler(event)
|
||||||
|
await waitUntilCalls(event)
|
||||||
|
|
||||||
|
expect(self.clients.openWindow).toHaveBeenCalledWith("tackupnow.com")
|
||||||
|
})
|
||||||
|
|
||||||
|
test("focuses first matching client", async () => {
|
||||||
|
addClient("https://tackupnow.com/place", "window", true)
|
||||||
|
const matchingClient = addClient(
|
||||||
|
"https://tackupnow.com/otherplace",
|
||||||
|
"window",
|
||||||
|
true
|
||||||
|
)
|
||||||
|
addClient("https://tackupnow.com/yetanotherotherplace", "window", true)
|
||||||
|
|
||||||
|
initWorker(self)
|
||||||
|
|
||||||
|
const notificationHandler = getHandler("notificationclick")
|
||||||
|
|
||||||
|
const event = createNotificationEvent("https://tackupnow.com/otherplace")
|
||||||
|
notificationHandler(event)
|
||||||
|
await waitUntilCalls(event)
|
||||||
|
|
||||||
|
expect(matchingClient.focus).toHaveBeenCalled()
|
||||||
|
})
|
||||||
|
|
||||||
|
test("focuses uncontrolled matching clients", async () => {
|
||||||
|
addClient("https://derpatious.world", "window", false)
|
||||||
|
addClient("https://tackupnow.com/1", "window", false)
|
||||||
|
const matchingClient = addClient(
|
||||||
|
"https://tackupnow.com/2",
|
||||||
|
"window",
|
||||||
|
false
|
||||||
|
)
|
||||||
|
addClient("https://tackupnow.com/controlled", "window", true)
|
||||||
|
|
||||||
|
initWorker(self)
|
||||||
|
|
||||||
|
const notificationHandler = getHandler("notificationclick")
|
||||||
|
|
||||||
|
const event = createNotificationEvent("https://tackupnow.com/2")
|
||||||
|
notificationHandler(event)
|
||||||
|
await waitUntilCalls(event)
|
||||||
|
|
||||||
|
expect(matchingClient.focus).toHaveBeenCalled()
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
test("claims on activate", async () => {
|
test("claims on activate", async () => {
|
||||||
|
|
@ -87,6 +190,82 @@ describe("service worker", () => {
|
||||||
expect(self.skipWaiting).toHaveBeenCalled()
|
expect(self.skipWaiting).toHaveBeenCalled()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe("on subscription message", () => {
|
||||||
|
test("puts push subscription if the subscription id is set", async () => {
|
||||||
|
initWorker(self)
|
||||||
|
await setSavedSubscription(5000)
|
||||||
|
|
||||||
|
const messageHandler = getHandler("message")
|
||||||
|
|
||||||
|
const messageEvent = createEvent({
|
||||||
|
data: {
|
||||||
|
subscription: { subscription: "YO" },
|
||||||
|
type: "subscribed",
|
||||||
|
},
|
||||||
|
})
|
||||||
|
messageHandler(messageEvent)
|
||||||
|
await waitUntilCalls(messageEvent)
|
||||||
|
|
||||||
|
expect(fetch).toHaveBeenCalledWith(
|
||||||
|
`${process.env.BASE_URL}/api/subscription/5000`,
|
||||||
|
{
|
||||||
|
method: "PUT",
|
||||||
|
body: JSON.stringify({ subscription: "YO" }),
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
test("posts to subscriptions when there is no user set", async () => {
|
||||||
|
initWorker(self)
|
||||||
|
|
||||||
|
const messageHandler = getHandler("message")
|
||||||
|
|
||||||
|
const messageEvent = createEvent({
|
||||||
|
data: {
|
||||||
|
subscription: { subscription: "YO" },
|
||||||
|
type: "subscribed",
|
||||||
|
},
|
||||||
|
})
|
||||||
|
messageHandler(messageEvent)
|
||||||
|
await waitUntilCalls(messageEvent)
|
||||||
|
|
||||||
|
expect(fetch).toHaveBeenCalledWith(
|
||||||
|
`${process.env.BASE_URL}/api/subscription/`,
|
||||||
|
{
|
||||||
|
method: "POST",
|
||||||
|
body: JSON.stringify({ subscription: "YO" }),
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
test("subscription id is saved on first subscription change", async () => {
|
||||||
|
initWorker(self)
|
||||||
|
|
||||||
|
const messageHandler = getHandler("message")
|
||||||
|
|
||||||
|
const messageEvent = createEvent({
|
||||||
|
data: {
|
||||||
|
subscription: { subscription: "YO" },
|
||||||
|
type: "subscribed",
|
||||||
|
},
|
||||||
|
})
|
||||||
|
messageHandler(messageEvent)
|
||||||
|
await waitUntilCalls(messageEvent)
|
||||||
|
|
||||||
|
expect(await getSavedSubscription()).toEqual({
|
||||||
|
id: 1,
|
||||||
|
subscriptionId: 123,
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe("on subscription change", () => {
|
||||||
test("puts push subscription if the subscription id is set", async () => {
|
test("puts push subscription if the subscription id is set", async () => {
|
||||||
initWorker(self)
|
initWorker(self)
|
||||||
await setSavedSubscription(5000)
|
await setSavedSubscription(5000)
|
||||||
|
|
@ -107,6 +286,9 @@ describe("service worker", () => {
|
||||||
{
|
{
|
||||||
method: "PUT",
|
method: "PUT",
|
||||||
body: JSON.stringify({ subscription: "HI" }),
|
body: JSON.stringify({ subscription: "HI" }),
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
@ -130,6 +312,9 @@ describe("service worker", () => {
|
||||||
{
|
{
|
||||||
method: "POST",
|
method: "POST",
|
||||||
body: JSON.stringify({ subscription: "HI" }),
|
body: JSON.stringify({ subscription: "HI" }),
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
@ -143,8 +328,37 @@ describe("service worker", () => {
|
||||||
changeHandler(changeEvent)
|
changeHandler(changeEvent)
|
||||||
await waitUntilCalls(changeEvent)
|
await waitUntilCalls(changeEvent)
|
||||||
|
|
||||||
expect(await getSavedSubscription()).toEqual({ id: 1, subscriptionId: 123 })
|
expect(await getSavedSubscription()).toEqual({
|
||||||
|
id: 1,
|
||||||
|
subscriptionId: 123,
|
||||||
})
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
function addClient(url: string, type: ClientTypes, controlled: boolean) {
|
||||||
|
const matchAllMock = self.clients.matchAll as jest.Mock
|
||||||
|
|
||||||
|
matchAllMock.mockImplementation(
|
||||||
|
(args: { type: string; includeUncontrolled?: boolean }) => {
|
||||||
|
const clientList = args.includeUncontrolled
|
||||||
|
? [...uncontrolledClients, ...controlledClients]
|
||||||
|
: controlledClients
|
||||||
|
return clientList.filter((client) => client.type === args.type)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
const clientList = controlled ? controlledClients : uncontrolledClients
|
||||||
|
|
||||||
|
const client: WindowClient = {
|
||||||
|
url,
|
||||||
|
type,
|
||||||
|
focus: jest.fn(() => Promise.resolve(client)) as WindowClient["focus"],
|
||||||
|
} as WindowClient
|
||||||
|
|
||||||
|
clientList.push(client)
|
||||||
|
|
||||||
|
return client
|
||||||
|
}
|
||||||
|
|
||||||
function getHandler(eventName: string) {
|
function getHandler(eventName: string) {
|
||||||
expect(self.addEventListener).toHaveBeenCalledWith(
|
expect(self.addEventListener).toHaveBeenCalledWith(
|
||||||
|
|
@ -193,8 +407,19 @@ function createPushEvent(data: string) {
|
||||||
return createEvent(pushFields)
|
return createEvent(pushFields)
|
||||||
}
|
}
|
||||||
|
|
||||||
function createMessageEvent(message: any) {
|
function createNotificationEvent(destination: string): NotificationEvent & {
|
||||||
return createEvent({ data: message })
|
waitUntil: jest.Mock<void, Parameters<ExtendableEvent["waitUntil"]>>
|
||||||
|
} {
|
||||||
|
return createEvent({
|
||||||
|
notification: {
|
||||||
|
close: jest.fn(),
|
||||||
|
data: {
|
||||||
|
destination,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}) as any as NotificationEvent & {
|
||||||
|
waitUntil: jest.Mock<void, Parameters<ExtendableEvent["waitUntil"]>>
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function createEvent(properties?: object) {
|
function createEvent(properties?: object) {
|
||||||
|
|
|
||||||
199
app/worker.ts
199
app/worker.ts
|
|
@ -16,72 +16,49 @@ export default function start(self: ServiceWorkerGlobalScope) {
|
||||||
event.waitUntil(self.clients.claim())
|
event.waitUntil(self.clients.claim())
|
||||||
})
|
})
|
||||||
|
|
||||||
// self.addEventListener("push", function (event: PushEvent) {
|
self.addEventListener("push", function (event: PushEvent) {
|
||||||
// console.log("[Service Worker] Push Received.")
|
const { title, body, badge, icon, destination } = event.data?.json()
|
||||||
// console.log(`[Service Worker] Push had this data: "${event.data?.text()}"`)
|
|
||||||
|
|
||||||
// const title = "Push Codelab"
|
event.waitUntil(
|
||||||
// const options = {
|
self.registration.showNotification(title, {
|
||||||
// body: "Yay it works.",
|
body,
|
||||||
// icon: "images/icon.png",
|
badge,
|
||||||
// badge: "images/badge.png",
|
icon,
|
||||||
// }
|
data: { destination },
|
||||||
|
})
|
||||||
// event.waitUntil(self.registration.showNotification(title, options))
|
|
||||||
// })
|
|
||||||
|
|
||||||
// self.addEventListener("notificationclick", function (event) {
|
|
||||||
// console.log("[Service Worker] Notification click Received.")
|
|
||||||
|
|
||||||
// event.notification.close()
|
|
||||||
|
|
||||||
// event.waitUntil(
|
|
||||||
// self.clients.openWindow("https://developers.google.com/web/")
|
|
||||||
// )
|
|
||||||
// })
|
|
||||||
|
|
||||||
async function sendMessage(message: any) {
|
|
||||||
const clients = await self.clients.matchAll()
|
|
||||||
|
|
||||||
await Promise.all(
|
|
||||||
clients.map(async (client) => client.postMessage(message))
|
|
||||||
)
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
self.addEventListener("notificationclick", function (event) {
|
||||||
|
event.notification.close()
|
||||||
|
const destination = event.notification.data.destination
|
||||||
|
|
||||||
|
event.waitUntil(
|
||||||
|
(async () => {
|
||||||
|
const clients = await self.clients.matchAll({
|
||||||
|
type: "window",
|
||||||
|
includeUncontrolled: true,
|
||||||
|
})
|
||||||
|
|
||||||
|
const existingClient = clients.find(
|
||||||
|
(client) => client.url === event.notification.data.destination
|
||||||
|
)
|
||||||
|
|
||||||
|
if (existingClient === undefined) {
|
||||||
|
await self.clients.openWindow(destination)
|
||||||
|
} else {
|
||||||
|
await existingClient.focus()
|
||||||
}
|
}
|
||||||
|
})()
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
self.addEventListener("message", function (event) {
|
self.addEventListener("message", function (event) {
|
||||||
const waitEvent = event as ExtendableEvent
|
const waitEvent = event as ExtendableEvent
|
||||||
waitEvent.waitUntil(
|
|
||||||
(async () => {
|
|
||||||
await sendMessage({
|
|
||||||
message: "Got message",
|
|
||||||
data: event.data,
|
|
||||||
})
|
|
||||||
|
|
||||||
if (
|
if ("type" in event.data && event.data.type === "subscribed") {
|
||||||
"type" in event.data &&
|
waitEvent.waitUntil(submitSubscription(event.data.subscription))
|
||||||
event.data.type === "subscribed" &&
|
|
||||||
"subscription" in event.data
|
|
||||||
) {
|
|
||||||
try {
|
|
||||||
await event.waitUntil(
|
|
||||||
submitSubscription(
|
|
||||||
self.registration,
|
|
||||||
event.data.subscription as PushSubscription
|
|
||||||
)
|
|
||||||
)
|
|
||||||
} catch (e) {
|
|
||||||
await sendMessage({
|
|
||||||
message: "Got error processing subscription",
|
|
||||||
error: (e as Error).toString(),
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
await sendMessage({
|
|
||||||
message: "Processed subscription",
|
|
||||||
})
|
|
||||||
})()
|
|
||||||
)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
self.addEventListener("pushsubscriptionchange", function (event) {
|
self.addEventListener("pushsubscriptionchange", function (event) {
|
||||||
|
|
@ -89,117 +66,44 @@ export default function start(self: ServiceWorkerGlobalScope) {
|
||||||
|
|
||||||
waitEvent.waitUntil(
|
waitEvent.waitUntil(
|
||||||
(async () => {
|
(async () => {
|
||||||
const existingSubscription =
|
const applicationServerKey = urlB64ToUint8Array(pushPublicKey)
|
||||||
await self.registration.pushManager.getSubscription()
|
const newSubscription = await self.registration.pushManager.subscribe({
|
||||||
const newSubscription = await submitSubscription(
|
|
||||||
self.registration,
|
|
||||||
existingSubscription
|
|
||||||
)
|
|
||||||
|
|
||||||
await sendMessage({ type: "sent subscription", newSubscription })
|
|
||||||
})()
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
async function submitSubscription(
|
|
||||||
registration: ServiceWorkerRegistration,
|
|
||||||
subscription: PushSubscription | null
|
|
||||||
) {
|
|
||||||
const db = database()
|
|
||||||
|
|
||||||
await sendMessage({
|
|
||||||
message: `Is subscription null? ${subscription === null}`,
|
|
||||||
})
|
|
||||||
|
|
||||||
if (subscription === null) return
|
|
||||||
|
|
||||||
const existingSubscriptionId = await db.subscriptions.get(1)
|
|
||||||
|
|
||||||
await sendMessage({
|
|
||||||
message: `Existing subscription ID ${existingSubscriptionId}`,
|
|
||||||
})
|
|
||||||
|
|
||||||
await sendMessage({
|
|
||||||
message: `pushPublicKey ${pushPublicKey}`,
|
|
||||||
})
|
|
||||||
|
|
||||||
let applicationServerKey
|
|
||||||
try {
|
|
||||||
applicationServerKey = urlB64ToUint8Array(pushPublicKey)
|
|
||||||
} catch (error) {
|
|
||||||
await sendMessage({
|
|
||||||
message: `B64 error ${(error as Error).toString()}`,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
await sendMessage({
|
|
||||||
message: `Converted public key`,
|
|
||||||
})
|
|
||||||
const newSubscription = await registration.pushManager.subscribe({
|
|
||||||
userVisibleOnly: true,
|
userVisibleOnly: true,
|
||||||
applicationServerKey: applicationServerKey,
|
applicationServerKey: applicationServerKey,
|
||||||
})
|
})
|
||||||
|
|
||||||
await sendMessage({
|
await submitSubscription(newSubscription.toJSON())
|
||||||
message: `subscribed via pushManager`,
|
})()
|
||||||
})
|
|
||||||
|
|
||||||
const stupid =
|
|
||||||
existingSubscriptionId === undefined
|
|
||||||
? postSubscription(newSubscription.toJSON(), db)
|
|
||||||
: putSubscription(
|
|
||||||
newSubscription.toJSON(),
|
|
||||||
existingSubscriptionId.subscriptionId
|
|
||||||
)
|
)
|
||||||
await stupid
|
})
|
||||||
|
}
|
||||||
|
|
||||||
return newSubscription
|
async function submitSubscription(subscription: PushSubscriptionJSON) {
|
||||||
|
const db = database()
|
||||||
|
|
||||||
|
const existingSubscriptionId = await db.subscriptions.get(1)
|
||||||
|
|
||||||
|
await (existingSubscriptionId === undefined
|
||||||
|
? postSubscription(subscription, db)
|
||||||
|
: putSubscription(subscription, existingSubscriptionId.subscriptionId))
|
||||||
}
|
}
|
||||||
|
|
||||||
async function postSubscription(
|
async function postSubscription(
|
||||||
subscription: PushSubscriptionJSON,
|
subscription: PushSubscriptionJSON,
|
||||||
db: ReturnType<typeof database>
|
db: ReturnType<typeof database>
|
||||||
) {
|
) {
|
||||||
await sendMessage({
|
const response = await fetch(`${process.env.BASE_URL}/api/subscription/`, {
|
||||||
message: "Log something you piece of garbage",
|
|
||||||
})
|
|
||||||
|
|
||||||
try {
|
|
||||||
await sendMessage({
|
|
||||||
message: `URL ${process.env.BASE_URL}/api/subscription/`,
|
|
||||||
})
|
|
||||||
|
|
||||||
await sendMessage({
|
|
||||||
message: `Submitting subscription ${subscription}`,
|
|
||||||
})
|
|
||||||
|
|
||||||
await sendMessage({
|
|
||||||
message: `JSON formatted: ${JSON.stringify(subscription)}`,
|
|
||||||
})
|
|
||||||
|
|
||||||
const response = await fetch(
|
|
||||||
`${process.env.BASE_URL}/api/subscription/`,
|
|
||||||
{
|
|
||||||
method: "POST",
|
method: "POST",
|
||||||
body: JSON.stringify(subscription),
|
body: JSON.stringify(subscription),
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
},
|
},
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
await sendMessage({
|
|
||||||
message: `Response status ${response.status}`,
|
|
||||||
})
|
})
|
||||||
|
|
||||||
db.subscriptions.put({
|
db.subscriptions.put({
|
||||||
id: 1,
|
id: 1,
|
||||||
subscriptionId: (await response.json()).subscriptionId,
|
subscriptionId: (await response.json()).subscriptionId,
|
||||||
})
|
})
|
||||||
} catch (error) {
|
|
||||||
await sendMessage({
|
|
||||||
message: `ERRRROR ${(error as Error).toString()}}`,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function putSubscription(subscription: PushSubscriptionJSON, id: number) {
|
function putSubscription(subscription: PushSubscriptionJSON, id: number) {
|
||||||
|
|
@ -211,7 +115,6 @@ export default function start(self: ServiceWorkerGlobalScope) {
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
function database() {
|
function database() {
|
||||||
const db = new Dexie("tack-up-now", { indexedDB }) as Dexie & {
|
const db = new Dexie("tack-up-now", { indexedDB }) as Dexie & {
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
services:
|
services:
|
||||||
database:
|
database:
|
||||||
image: postgres
|
image: postgres:16
|
||||||
ports:
|
ports:
|
||||||
- "5434:5432"
|
- "5434:5432"
|
||||||
environment:
|
environment:
|
||||||
|
|
|
||||||
|
|
@ -3,10 +3,9 @@ services:
|
||||||
build: .
|
build: .
|
||||||
ports:
|
ports:
|
||||||
- "9000:3000"
|
- "9000:3000"
|
||||||
|
env_file: ".env"
|
||||||
database:
|
database:
|
||||||
image: postgres
|
image: postgres:16
|
||||||
ports:
|
|
||||||
- "5432:5432"
|
|
||||||
environment:
|
environment:
|
||||||
POSTGRES_USER: postgres
|
POSTGRES_USER: postgres
|
||||||
POSTGRES_DB: postgres
|
POSTGRES_DB: postgres
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
import { test, expect, Page } from "@playwright/test"
|
import { test, expect, Page } from "@playwright/test"
|
||||||
import matchPath from "./urlMatcher"
|
import matchPath from "./urlMatcher"
|
||||||
|
import { messageSW } from "@remix-pwa/sw"
|
||||||
|
|
||||||
const { describe, beforeEach, skip, use } = test
|
const { describe, beforeEach, skip, use } = test
|
||||||
|
|
||||||
|
|
@ -89,6 +90,23 @@ describe("when user is on iOS", () => {
|
||||||
|
|
||||||
await expect(yourNotificationsHeading).toBeVisible()
|
await expect(yourNotificationsHeading).toBeVisible()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test("the subscription is submitted", async ({ page }) => {
|
||||||
|
await page.goto("/")
|
||||||
|
|
||||||
|
await page.getByText(/Enable Notifications/).click()
|
||||||
|
|
||||||
|
const postedMessages = await page.evaluate(() => {
|
||||||
|
return (window as any).postedMessages
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(postedMessages).toContainEqual({
|
||||||
|
type: "subscribed",
|
||||||
|
subscription: {
|
||||||
|
subscription: "HI",
|
||||||
|
},
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
@ -212,20 +230,37 @@ function stubNotifications(
|
||||||
|
|
||||||
function stubServiceWorker(page: Page) {
|
function stubServiceWorker(page: Page) {
|
||||||
return page.addInitScript(() => {
|
return page.addInitScript(() => {
|
||||||
const serviceWorker = {}
|
function createSubscription(testToken = "HI") {
|
||||||
|
return {
|
||||||
|
toJSON: () => ({
|
||||||
|
subscription: testToken,
|
||||||
|
}),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let postedMessages: any[] = []
|
||||||
|
|
||||||
|
const serviceWorker = {
|
||||||
|
postMessage: (message: any) => postedMessages.push(message),
|
||||||
|
}
|
||||||
|
|
||||||
const registration = {
|
const registration = {
|
||||||
pushManager: {
|
pushManager: {
|
||||||
getSubscription() {
|
getSubscription() {
|
||||||
return Promise.resolve({ hi: "subscription" })
|
return Promise.resolve(createSubscription())
|
||||||
},
|
},
|
||||||
subscribe(args: Parameters<PushManager["subscribe"]>[0]) {
|
subscribe(args: Parameters<PushManager["subscribe"]>[0]) {
|
||||||
return Promise.resolve({ hi: "subscription" })
|
return Promise.resolve(createSubscription())
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
active: serviceWorker,
|
active: serviceWorker,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Object.defineProperty(window, "postedMessages", {
|
||||||
|
value: postedMessages,
|
||||||
|
writable: true,
|
||||||
|
})
|
||||||
|
|
||||||
Object.defineProperty(navigator, "serviceWorker", {
|
Object.defineProperty(navigator, "serviceWorker", {
|
||||||
value: {
|
value: {
|
||||||
ready: Promise.resolve(registration),
|
ready: Promise.resolve(registration),
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@
|
||||||
"@babel/preset-env": "^7.24.5",
|
"@babel/preset-env": "^7.24.5",
|
||||||
"@babel/preset-react": "^7.24.1",
|
"@babel/preset-react": "^7.24.1",
|
||||||
"@babel/preset-typescript": "^7.24.1",
|
"@babel/preset-typescript": "^7.24.1",
|
||||||
"@playwright/test": "^1.44.1",
|
"@playwright/test": "^1.48.1",
|
||||||
"@remix-pwa/dev": "^3.1.0",
|
"@remix-pwa/dev": "^3.1.0",
|
||||||
"@remix-run/dev": "^2.9.0",
|
"@remix-run/dev": "^2.9.0",
|
||||||
"@remix-run/testing": "^2.9.1",
|
"@remix-run/testing": "^2.9.1",
|
||||||
|
|
@ -3324,18 +3324,18 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@playwright/test": {
|
"node_modules/@playwright/test": {
|
||||||
"version": "1.44.1",
|
"version": "1.48.1",
|
||||||
"resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.44.1.tgz",
|
"resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.48.1.tgz",
|
||||||
"integrity": "sha512-1hZ4TNvD5z9VuhNJ/walIjvMVvYkZKf71axoF/uiAqpntQJXpG64dlXhoDXE3OczPuTuvjf/M5KWFg5VAVUS3Q==",
|
"integrity": "sha512-s9RtWoxkOLmRJdw3oFvhFbs9OJS0BzrLUc8Hf6l2UdCNd1rqeEyD4BhCJkvzeEoD1FsK4mirsWwGerhVmYKtZg==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"playwright": "1.44.1"
|
"playwright": "1.48.1"
|
||||||
},
|
},
|
||||||
"bin": {
|
"bin": {
|
||||||
"playwright": "cli.js"
|
"playwright": "cli.js"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=16"
|
"node": ">=18"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@remix-pwa/dev": {
|
"node_modules/@remix-pwa/dev": {
|
||||||
|
|
@ -13843,33 +13843,33 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/playwright": {
|
"node_modules/playwright": {
|
||||||
"version": "1.44.1",
|
"version": "1.48.1",
|
||||||
"resolved": "https://registry.npmjs.org/playwright/-/playwright-1.44.1.tgz",
|
"resolved": "https://registry.npmjs.org/playwright/-/playwright-1.48.1.tgz",
|
||||||
"integrity": "sha512-qr/0UJ5CFAtloI3avF95Y0L1xQo6r3LQArLIg/z/PoGJ6xa+EwzrwO5lpNr/09STxdHuUoP2mvuELJS+hLdtgg==",
|
"integrity": "sha512-j8CiHW/V6HxmbntOfyB4+T/uk08tBy6ph0MpBXwuoofkSnLmlfdYNNkFTYD6ofzzlSqLA1fwH4vwvVFvJgLN0w==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"playwright-core": "1.44.1"
|
"playwright-core": "1.48.1"
|
||||||
},
|
},
|
||||||
"bin": {
|
"bin": {
|
||||||
"playwright": "cli.js"
|
"playwright": "cli.js"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=16"
|
"node": ">=18"
|
||||||
},
|
},
|
||||||
"optionalDependencies": {
|
"optionalDependencies": {
|
||||||
"fsevents": "2.3.2"
|
"fsevents": "2.3.2"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/playwright-core": {
|
"node_modules/playwright-core": {
|
||||||
"version": "1.44.1",
|
"version": "1.48.1",
|
||||||
"resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.44.1.tgz",
|
"resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.48.1.tgz",
|
||||||
"integrity": "sha512-wh0JWtYTrhv1+OSsLPgFzGzt67Y7BE/ZS3jEqgGBlp2ppp1ZDj8c+9IARNW4dwf1poq5MgHreEM2KV/GuR4cFA==",
|
"integrity": "sha512-Yw/t4VAFX/bBr1OzwCuOMZkY1Cnb4z/doAFSwf4huqAGWmf9eMNjmK7NiOljCdLmxeRYcGPPmcDgU0zOlzP0YA==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"bin": {
|
"bin": {
|
||||||
"playwright-core": "cli.js"
|
"playwright-core": "cli.js"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=16"
|
"node": ">=18"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/playwright/node_modules/fsevents": {
|
"node_modules/playwright/node_modules/fsevents": {
|
||||||
|
|
|
||||||
|
|
@ -9,8 +9,9 @@
|
||||||
"lint": "eslint --ignore-path .gitignore --cache --cache-location ./node_modules/.cache/eslint .",
|
"lint": "eslint --ignore-path .gitignore --cache --cache-location ./node_modules/.cache/eslint .",
|
||||||
"start": "remix-serve ./build/server/index.js",
|
"start": "remix-serve ./build/server/index.js",
|
||||||
"typecheck": "tsc",
|
"typecheck": "tsc",
|
||||||
"watch": "export $(cat .env.test | xargs) && docker compose -f docker-compose-test.yaml up database -d && jest --watch --config=jest.config.ts",
|
"watch": "export $(cat .env.test | xargs) && docker compose -f docker-compose-test.yaml up database -d --remove-orphans && jest --watch --config=jest.config.ts",
|
||||||
"test": "export $(cat .env.test | xargs) && docker compose -f docker-compose-test.yaml up database -d && jest --config=jest.config.ts"
|
"test": "export $(cat .env.test | xargs) && docker compose -f docker-compose-test.yaml up database -d --remove-orphans && sleep 5 && jest --config=jest.config.ts",
|
||||||
|
"ci": "export $(cat .env.ci | xargs) && jest --config=jest.config.ts"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@remix-pwa/sw": "^3.0.9",
|
"@remix-pwa/sw": "^3.0.9",
|
||||||
|
|
@ -38,7 +39,7 @@
|
||||||
"@babel/preset-env": "^7.24.5",
|
"@babel/preset-env": "^7.24.5",
|
||||||
"@babel/preset-react": "^7.24.1",
|
"@babel/preset-react": "^7.24.1",
|
||||||
"@babel/preset-typescript": "^7.24.1",
|
"@babel/preset-typescript": "^7.24.1",
|
||||||
"@playwright/test": "^1.44.1",
|
"@playwright/test": "^1.48.1",
|
||||||
"@remix-pwa/dev": "^3.1.0",
|
"@remix-pwa/dev": "^3.1.0",
|
||||||
"@remix-run/dev": "^2.9.0",
|
"@remix-run/dev": "^2.9.0",
|
||||||
"@remix-run/testing": "^2.9.1",
|
"@remix-run/testing": "^2.9.1",
|
||||||
|
|
|
||||||
|
|
@ -1 +1 @@
|
||||||
export default "BKc02U2-z7PkTbYgYLlxELWqzTVE631fs4IPuMLbxY_rxdo9VaduthqwkPOiblwjETl99uXes2Nc9EtPbS5x4uA"
|
export default "BNwr5jYXxBwSRGooQWx6nzsrG5XejgAskVqowkc_O0rutL9PgRIkQAnDh4nz1yoPQEw40juMuqL2NEHSaD3XcxA"
|
||||||
|
|
|
||||||
22
send-it.js
22
send-it.js
|
|
@ -1,22 +0,0 @@
|
||||||
import webPush from "web-push"
|
|
||||||
|
|
||||||
const subscription = {
|
|
||||||
endpoint:
|
|
||||||
"https://updates.push.services.mozilla.com/wpush/v2/gAAAAABm9FlbY5vMro60hF2iJF3UUBzweuFcg5NRSHXPSpHfUpjo5jKGVRnUxR4ekg0-FsvdQCP89cu__IFd06Tu2TJZ649YyqivRUBnAav0DgOLHGx5-t943QLS-wLvBqyJRCuuLlM1bLz6S9ph9AWJ8CG7rQuTabsHvw--s_w2KDQo3GcQXIM",
|
|
||||||
expirationTime: null,
|
|
||||||
keys: {
|
|
||||||
auth: "dDUqtFo26ekGEAmNzvmJAw",
|
|
||||||
p256dh:
|
|
||||||
"BHIT3J6xSRiHfz0m-QRHagDThiOZGVIANtPzOasrOBYG0s_yUnshTVharX5dZcq8GA5OkyMm3mqmA7_o_lFR4WE",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
webPush.setVapidDetails(
|
|
||||||
"https://tackupnow.com",
|
|
||||||
"BKc02U2-z7PkTbYgYLlxELWqzTVE631fs4IPuMLbxY_rxdo9VaduthqwkPOiblwjETl99uXes2Nc9EtPbS5x4uA",
|
|
||||||
"Xmv5Pc4mqr138V3sCxXq7UmsbL5UgSOY43UuJ50nxPw"
|
|
||||||
)
|
|
||||||
|
|
||||||
webPush
|
|
||||||
.sendNotification(subscription, "Hi what's up?", {})
|
|
||||||
.then((x) => console.log("It sent", x))
|
|
||||||
.catch((error) => console.log("It did not send", error))
|
|
||||||
3
start.sh
3
start.sh
|
|
@ -1,7 +1,4 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
set -a
|
|
||||||
source ./.env
|
|
||||||
set +a
|
|
||||||
npx tsx api/data/upgrade.ts
|
npx tsx api/data/upgrade.ts
|
||||||
npx tsx server.ts
|
npx tsx server.ts
|
||||||
|
|
@ -12,7 +12,7 @@ export default defineConfig({
|
||||||
tsconfigPaths(),
|
tsconfigPaths(),
|
||||||
remixPWA({
|
remixPWA({
|
||||||
buildVariables: {
|
buildVariables: {
|
||||||
"process.env.BASE_URL": process.env.BASE_URL!,
|
"process.env.BASE_URL": process.env.BASE_URL ?? "http://localhost:5173",
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue