Skip to content

Commit c6ce1ee

Browse files
committed
Features:
- properties.json includes spec(Securelay) and implementation versions - webhook usage metadata is present even to data passed via webhook - webpush only if webhook is absent or fails
1 parent 17228a5 commit c6ce1ee

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

api/index.js

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ fastify.post('/public/:publicKey', async (request, reply) => {
7777
if (helper.parseKey(publicKey, { validate: false }).type !== 'public') throw new Error('Unauthorized');
7878

7979
const webhook = await helper.cacheGet(publicKey, 'hook'); // Also validates key
80-
let webhookUsed = false;
8180

8281
const app = request.query.app;
8382

@@ -92,9 +91,11 @@ fastify.post('/public/:publicKey', async (request, reply) => {
9291
if (ip) meta.ip = ip;
9392
const data = helper.decoratePayload(request.body, meta);
9493

95-
// Try posting the data to webhook, if any, with timeout. On fail, store/bin data for later retrieval.
94+
// Try posting the data to webhook, if any, with timeout.
95+
// On fail, store data and send web-push notifications to owner.
9696
try {
9797
if (!webhook) throw new Error('No webhook');
98+
data.webhook = true; // Data passed via webhook should also have webhook-usage metadata
9899

99100
await fetch(webhook, {
100101
method: "POST",
@@ -107,19 +108,15 @@ fastify.post('/public/:publicKey', async (request, reply) => {
107108
return response.text();
108109
})
109110

110-
webhookUsed = true;
111111
} catch (err) {
112+
data.webhook = false;
112113
await helper.publicProduce(publicKey, data);
113114
if (webhook) waitUntil(helper.cacheDel(publicKey, 'hook').catch((err) => {}));
114-
}
115-
116-
if (app) {
117-
data.webhook = webhookUsed; // Adding webhook info to metadata
118-
waitUntil(helper.OneSignalSendPush(app, publicKey, data).catch((err) => {}));
115+
if (app) waitUntil(helper.OneSignalSendPush(app, publicKey, data).catch((err) => {}));
119116
}
120117

121118
if (redirectOnOk == null) {
122-
reply.send({message: "Done", error: "Ok", statusCode: reply.statusCode, webhook: webhookUsed});
119+
reply.send({message: "Done", error: "Ok", statusCode: reply.statusCode, webhook: data.webhook});
123120
} else {
124121
reply.redirect(redirectOnOk, 303);
125122
}

build.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ echo "${id}" > "${build_dir}/id.txt"
1212

1313
cat > "${build_dir}/properties.json" <<-EOF
1414
{
15+
"versions": {
16+
"specification": "0.0",
17+
"implementation": "0.0.0"
18+
},
1519
"id": "${id}",
1620
"OneSignalAppId": {
1721
"formonit": "${ONESIGNAL_APP_ID_FORMONIT}"

0 commit comments

Comments
 (0)