@jskit-ai/push-core 0.1.9 → 0.1.11

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jskit-ai/push-core",
3
- "version": "0.1.9",
3
+ "version": "0.1.11",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "test": "jskit test"
@@ -89,15 +89,15 @@
89
89
  }
90
90
  },
91
91
  "dependencies": {
92
- "@jskit-ai/resource-core": "0.1.238",
92
+ "@jskit-ai/resource-core": "0.1.239",
93
93
  "json-rest-schema": "^1.0.20",
94
94
  "web-push": "4.0.0"
95
95
  },
96
96
  "peerDependencies": {
97
- "@jskit-ai/database-runtime": "0.1.306",
98
- "@jskit-ai/http-runtime": "0.2.49",
99
- "@jskit-ai/kernel": "0.2.47",
100
- "@jskit-ai/resource-runtime": "0.2.73",
101
- "@jskit-ai/users-core": "0.2.92"
97
+ "@jskit-ai/database-runtime": "0.1.307",
98
+ "@jskit-ai/http-runtime": "0.2.50",
99
+ "@jskit-ai/kernel": "0.2.48",
100
+ "@jskit-ai/resource-runtime": "0.2.75",
101
+ "@jskit-ai/users-core": "0.2.94"
102
102
  }
103
103
  }
@@ -6,7 +6,7 @@ import {
6
6
  ACTION_REMOVE_DEVICE,
7
7
  ACTION_UPDATE_SETTINGS
8
8
  } from "./pushActions.js";
9
- import { forgetDeviceInput, registerDeviceInput, updateSettingsInput } from "./inputSchemas.js";
9
+ import { forgetDeviceInput, registerDeviceInput, removeDeviceInput, updateSettingsInput } from "./inputSchemas.js";
10
10
 
11
11
  const PUSH_PATHS = Object.freeze({
12
12
  OVERVIEW: "/api/push",
@@ -26,8 +26,9 @@ function registerPushRoutes(router) {
26
26
  auth: "required",
27
27
  actionId,
28
28
  meta: { tags: ["push"], summary: extra.summary },
29
+ ...(extra.params ? { params: extra.params } : {}),
29
30
  ...(extra.body ? { body: extra.body } : {}),
30
- responses: withStandardErrorResponses({}, { includeValidation400: Boolean(extra.body) }),
31
+ responses: withStandardErrorResponses({}, { includeValidation400: Boolean(extra.body || extra.params) }),
31
32
  ...(extra.rateLimit ? { rateLimit: extra.rateLimit } : {})
32
33
  }, async function (request, reply) {
33
34
  reply.code(200).send(await request.executeAction({ actionId, input: input(request) }));
@@ -42,7 +43,7 @@ function registerPushRoutes(router) {
42
43
  }, (request) => request.input.body);
43
44
  route("POST", PUSH_PATHS.FORGET, ACTION_FORGET_DEVICE, { summary: "Forget this device, as signing out on it does.", body: forgetDeviceInput },
44
45
  (request) => request.input.body);
45
- route("DELETE", PUSH_PATHS.DEVICE, ACTION_REMOVE_DEVICE, { summary: "Remove one of the signed-in person's devices." },
46
+ route("DELETE", PUSH_PATHS.DEVICE, ACTION_REMOVE_DEVICE, { summary: "Remove one of the signed-in person's devices.", params: removeDeviceInput },
46
47
  (request) => ({ id: request.input.params.id }));
47
48
  route("PUT", PUSH_PATHS.SETTINGS, ACTION_UPDATE_SETTINGS, { summary: "Save the signed-in person's notification settings.", body: updateSettingsInput },
48
49
  (request) => request.input.body);
@@ -0,0 +1,32 @@
1
+ import assert from "node:assert/strict";
2
+ import test from "node:test";
3
+ import Fastify from "fastify";
4
+ import { registerApiErrorHandler } from "../../kernel/server/http/errorHandling.js";
5
+ import { createRouter } from "../../kernel/server/http/lib/router.js";
6
+ import { registerRoutes } from "../../kernel/server/http/lib/routeRegistration.js";
7
+ import { as, startPush } from "./support/pushHarness.js";
8
+
9
+ // push-core's routes as an application serves them: the kernel's router and route registration on Fastify, over the
10
+ // feature's actions, with person 1 signed in.
11
+ async function servePush(t) {
12
+ const router = createRouter();
13
+ const started = await startPush(t, { router });
14
+ started.actions.registerContextContributor({ id: "test.person", contribute: () => as(1).context });
15
+ const app = Fastify();
16
+ t.after(() => app.close());
17
+ registerApiErrorHandler(app);
18
+ registerRoutes(app, { routes: router.list(), actions: started.actions });
19
+ return { app, push: started.push };
20
+ }
21
+
22
+ test("removing one of the person's devices from the settings answers 200, and the device is gone", async (t) => {
23
+ const { app, push } = await servePush(t);
24
+ const device = await push.registerDevice({ kind: "fcm", token: "ada-phone" }, as(1));
25
+
26
+ const response = await app.inject({ method: "DELETE", url: `/api/push/devices/${device.id}` });
27
+
28
+ // Before, the route read request.input.params without declaring params, so it had no input at all: a 500.
29
+ assert.equal(response.statusCode, 200, response.body);
30
+ assert.deepEqual(response.json(), { ok: true });
31
+ assert.deepEqual((await push.readOverview(as(1))).devices, []);
32
+ });
@@ -15,10 +15,11 @@ function recordingLogger() {
15
15
  /**
16
16
  * PushFeature over the package's own migrations, on SQLite in memory or the run's database (createPackageTestKnex),
17
17
  * with `users` 1 to `people` in place for the devices' foreign keys.
18
+ * With `router`, the routes go to that router (the kernel's, for a test over HTTP) instead of a list of their names.
18
19
  * @param {import("node:test").TestContext} t
19
- * @param {{ env?: Record<string, string>, people?: number }} [options]
20
+ * @param {{ env?: Record<string, string>, people?: number, router?: { register: Function } }} [options]
20
21
  */
21
- async function startPush(t, { env = { APP_ENV: "test" }, people = 3 } = {}) {
22
+ async function startPush(t, { env = { APP_ENV: "test" }, people = 3, router = null } = {}) {
22
23
  const knex = await createPackageTestKnex(t, { environment: process.env });
23
24
  await knex.schema.createTable("users", (table) => {
24
25
  table.bigIncrements("id").unsigned().primary();
@@ -30,16 +31,16 @@ async function startPush(t, { env = { APP_ENV: "test" }, people = 3 } = {}) {
30
31
  const started = await startTestFeatures({
31
32
  knex,
32
33
  features: [PushFeature],
33
- requires: { push: "push.core" },
34
+ requires: { push: "push.core", actions: "runtime.actions" },
34
35
  inputs: {
35
36
  "runtime.env": env,
36
- "runtime.http": { router: { register: (method, path) => routes.push(`${method} ${path}`) } },
37
+ "runtime.http": { router: router ?? { register: (method, path) => routes.push(`${method} ${path}`) } },
37
38
  "runtime.logger": logger
38
39
  },
39
40
  logger
40
41
  });
41
42
  t.after(() => started.stop());
42
- return { knex, push: started.capabilities.push, logger, routes };
43
+ return { knex, push: started.capabilities.push, actions: started.capabilities.actions, logger, routes };
43
44
  }
44
45
 
45
46
  /** Inserts users 1 to `count`, in chunks SQLite takes. */