@jskit-ai/push-core 0.1.2 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2 -0
- package/locales/en.json +6 -4
- package/package.json +10 -6
- package/src/server/pushService.js +9 -5
- package/src/server/pushSettings.js +1 -1
- package/test/registry.test.js +8 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
## Unreleased
|
|
4
4
|
|
|
5
|
+
- Its migrations declare `"after": ["@jskit-ai/users-core"]`: they create a key to `users` with their tables, and ran before users-core created it on a new database (path order), which MySQL and PostgreSQL refuse.
|
|
6
|
+
- Quiet hours with one end are refused with the empty end in `details.fieldErrors` (`quietFrom` or `quietTo`, codes `push.settings.quietFromRequired` and `push.settings.quietToRequired`), so the field shows it. The refusals of a browser subscription, an unknown push service and an unknown time zone now say what the person can do.
|
|
5
7
|
- The manifest's `jskit.capabilities.requires` lists `runtime.env` and `runtime.logger`, which `PushFeature` requires; without them an app's server stopped at start-up.
|
|
6
8
|
- A deleted account's devices and settings are forgotten on `account.deleting`.
|
|
7
9
|
- `push.updateLiveActivity({ token, environment, event, data, ... })` updates or ends an iOS Live Activity through APNs' `liveactivity` push type; logged outside production.
|
package/locales/en.json
CHANGED
|
@@ -2,13 +2,15 @@
|
|
|
2
2
|
"jskit": {
|
|
3
3
|
"push": {
|
|
4
4
|
"device": {
|
|
5
|
-
"endpointRefused": "This browser's
|
|
6
|
-
"keysRequired": "
|
|
7
|
-
"taken": "
|
|
5
|
+
"endpointRefused": "This browser's notification service isn't one this app sends to. Try another browser.",
|
|
6
|
+
"keysRequired": "This browser's notification subscription is incomplete. Turn notifications off and on again.",
|
|
7
|
+
"taken": "Another account gets notifications in this browser. Sign in as that account and turn them off here, then try again."
|
|
8
8
|
},
|
|
9
9
|
"settings": {
|
|
10
10
|
"quietHoursIncomplete": "Quiet hours need both a start and an end.",
|
|
11
|
-
"
|
|
11
|
+
"quietFromRequired": "Choose when quiet hours start.",
|
|
12
|
+
"quietToRequired": "Choose when quiet hours end.",
|
|
13
|
+
"timeZoneInvalid": "This device's time zone isn't one the server knows, so quiet hours can't be saved. Leave quiet hours empty, or change the device's time zone."
|
|
12
14
|
}
|
|
13
15
|
}
|
|
14
16
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jskit-ai/push-core",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "jskit test"
|
|
@@ -82,18 +82,22 @@
|
|
|
82
82
|
"migrations": {
|
|
83
83
|
"directories": [
|
|
84
84
|
"migrations"
|
|
85
|
+
],
|
|
86
|
+
"after": [
|
|
87
|
+
"@jskit-ai/users-core"
|
|
85
88
|
]
|
|
86
89
|
}
|
|
87
90
|
},
|
|
88
91
|
"dependencies": {
|
|
89
|
-
"@jskit-ai/resource-core": "0.1.
|
|
92
|
+
"@jskit-ai/resource-core": "0.1.235",
|
|
90
93
|
"json-rest-schema": "^1.0.20",
|
|
91
94
|
"web-push": "4.0.0"
|
|
92
95
|
},
|
|
93
96
|
"peerDependencies": {
|
|
94
|
-
"@jskit-ai/database-runtime": "0.1.
|
|
95
|
-
"@jskit-ai/http-runtime": "0.2.
|
|
96
|
-
"@jskit-ai/kernel": "0.2.
|
|
97
|
-
"@jskit-ai/resource-runtime": "0.2.
|
|
97
|
+
"@jskit-ai/database-runtime": "0.1.302",
|
|
98
|
+
"@jskit-ai/http-runtime": "0.2.46",
|
|
99
|
+
"@jskit-ai/kernel": "0.2.44",
|
|
100
|
+
"@jskit-ai/resource-runtime": "0.2.69",
|
|
101
|
+
"@jskit-ai/users-core": "0.2.88"
|
|
98
102
|
}
|
|
99
103
|
}
|
|
@@ -54,10 +54,10 @@ function createPush({ devices, settings, senders, vapidPublicKey, environment, l
|
|
|
54
54
|
const userId = resolveActorId(options.context);
|
|
55
55
|
if (input.kind === "webpush") {
|
|
56
56
|
if (!isPushServiceEndpoint(input.token)) {
|
|
57
|
-
throw new AppError(400, "This browser's
|
|
57
|
+
throw new AppError(400, "This browser's notification service isn't one this app sends to. Try another browser.", { code: "push.device.endpointRefused" });
|
|
58
58
|
}
|
|
59
59
|
if (!input.p256dh || !input.auth) {
|
|
60
|
-
throw new AppError(400, "
|
|
60
|
+
throw new AppError(400, "This browser's notification subscription is incomplete. Turn notifications off and on again.", { code: "push.device.keysRequired" });
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
63
|
const seenAt = new Date(now()).toISOString();
|
|
@@ -74,7 +74,7 @@ function createPush({ devices, settings, senders, vapidPublicKey, environment, l
|
|
|
74
74
|
if (existing) {
|
|
75
75
|
const anotherPerson = String(existing.userId) !== String(userId);
|
|
76
76
|
if (anotherPerson && input.kind === "webpush" && (existing.p256dh !== input.p256dh || existing.auth !== input.auth)) {
|
|
77
|
-
throw new AppError(409, "
|
|
77
|
+
throw new AppError(409, "Another account gets notifications in this browser. Sign in as that account and turn them off here, then try again.", { code: "push.device.taken" });
|
|
78
78
|
}
|
|
79
79
|
return deviceOf(await devices.update(existing.id, anotherPerson ? { ...fields, userId } : fields, systemOptions));
|
|
80
80
|
}
|
|
@@ -98,10 +98,14 @@ function createPush({ devices, settings, senders, vapidPublicKey, environment, l
|
|
|
98
98
|
/** @param {import("./types.js").PushSettingsInput} input */
|
|
99
99
|
async function updateSettings(input, options) {
|
|
100
100
|
if (Boolean(input.quietFrom) !== Boolean(input.quietTo)) {
|
|
101
|
-
|
|
101
|
+
// The refusal names the empty end, so the person sees it beside that field.
|
|
102
|
+
const details = input.quietFrom
|
|
103
|
+
? { fieldErrors: { quietTo: "Choose when quiet hours end." }, fieldErrorCodes: { quietTo: { code: "push.settings.quietToRequired", params: {} } } }
|
|
104
|
+
: { fieldErrors: { quietFrom: "Choose when quiet hours start." }, fieldErrorCodes: { quietFrom: { code: "push.settings.quietFromRequired", params: {} } } };
|
|
105
|
+
throw new AppError(400, "Quiet hours need both a start and an end.", { code: "push.settings.quietHoursIncomplete", details });
|
|
102
106
|
}
|
|
103
107
|
if (input.timeZone && !validTimeZone(input.timeZone)) {
|
|
104
|
-
throw new AppError(400, "This time zone
|
|
108
|
+
throw new AppError(400, "This device's time zone isn't one the server knows, so quiet hours can't be saved. Leave quiet hours empty, or change the device's time zone.", { code: "push.settings.timeZoneInvalid" });
|
|
105
109
|
}
|
|
106
110
|
return settings.saveMine({
|
|
107
111
|
kindsOff: [...new Set(input.kindsOff)],
|
|
@@ -80,4 +80,4 @@ function createPushSettings({ pushSettings }) {
|
|
|
80
80
|
return Object.freeze({ readMine, readForUsers, saveMine, removeForUser });
|
|
81
81
|
}
|
|
82
82
|
|
|
83
|
-
export {
|
|
83
|
+
export { createPushSettings, inQuietHours, settingsOf };
|
package/test/registry.test.js
CHANGED
|
@@ -69,7 +69,14 @@ test("settings save once per person, check quiet hours and time zone, and defaul
|
|
|
69
69
|
assert.deepEqual(saved, { kindsOff: ["mention"], showText: false, quietFrom: "22:00", quietTo: "07:00", timeZone: "Europe/Rome" });
|
|
70
70
|
await push.updateSettings({ kindsOff: [], showText: true }, as(1));
|
|
71
71
|
assert.deepEqual((await push.readOverview(as(1))).settings.quietFrom, null);
|
|
72
|
-
|
|
72
|
+
// The refusal names the empty end, so the person sees it beside that field.
|
|
73
|
+
await assert.rejects(push.updateSettings({ kindsOff: [], showText: true, quietFrom: "22:00" }, as(1)), {
|
|
74
|
+
code: "push.settings.quietHoursIncomplete",
|
|
75
|
+
details: { fieldErrors: { quietTo: "Choose when quiet hours end." }, fieldErrorCodes: { quietTo: { code: "push.settings.quietToRequired", params: {} } } }
|
|
76
|
+
});
|
|
77
|
+
await assert.rejects(push.updateSettings({ kindsOff: [], showText: true, quietTo: "07:00" }, as(1)), {
|
|
78
|
+
details: { fieldErrors: { quietFrom: "Choose when quiet hours start." }, fieldErrorCodes: { quietFrom: { code: "push.settings.quietFromRequired", params: {} } } }
|
|
79
|
+
});
|
|
73
80
|
await assert.rejects(push.updateSettings({ kindsOff: [], showText: true, timeZone: "Mars/Olympus" }, as(1)), { code: "push.settings.timeZoneInvalid" });
|
|
74
81
|
});
|
|
75
82
|
|