@jskit-ai/http-web 0.2.32 → 0.2.33

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 CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ - A `useCommand()` DELETE sends its parsed input as the request body when the command declares an `input` schema or a `buildRawPayload`, so a DELETE that needs a reason or a confirmation reaches the server with it. Before, the client parsed the input and then dropped it for every DELETE, and a route that required a body answered 500. A DELETE that declares neither still sends no body, and `buildCommandPayload` still decides the body when given.
5
6
  - The CRUD list screen, form lookups and list-filter lookups no longer pass `search: { mode: "query" }`: a list's search runs on the server only, so they leave the mode out, as the guide says to. They search on the server as before.
6
7
  - **Breaking.** `useList`'s search runs on the server only: `search: { mode: "local" }`, which filtered the page the list had loaded in the browser and so missed every row past it, throws naming the server search, and so does `search.fields`, which only that mode read: the resource's `searchSchema.q` names the fields a search reads. Upgrading: drop the mode and give the resource `searchSchema.q`, which the list's search sends as `q`.
7
8
  - `CrudListFilterControls` applies a typed record id or number-range bound when the person pauses (400 ms), presses Enter or leaves the field, instead of on every key, so typing `1500` asks for one list rather than four; clearing a field applies at once.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jskit-ai/http-web",
3
- "version": "0.2.32",
3
+ "version": "0.2.33",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "test": "jskit test"
@@ -47,13 +47,13 @@
47
47
  "./locales/en.json": "./locales/en.json"
48
48
  },
49
49
  "dependencies": {
50
- "@jskit-ai/resource-crud-core": "0.1.213"
50
+ "@jskit-ai/resource-crud-core": "0.1.214"
51
51
  },
52
52
  "peerDependencies": {
53
- "@jskit-ai/http-runtime": "0.2.20",
54
- "@jskit-ai/kernel": "0.2.20",
55
- "@jskit-ai/realtime": "0.2.30",
56
- "@jskit-ai/shell-web": "0.2.27",
53
+ "@jskit-ai/http-runtime": "0.2.21",
54
+ "@jskit-ai/kernel": "0.2.21",
55
+ "@jskit-ai/realtime": "0.2.31",
56
+ "@jskit-ai/shell-web": "0.2.28",
57
57
  "@tanstack/vue-query": "^5.90.5",
58
58
  "vue": "^3.5.13",
59
59
  "vue-router": "^5.0.4",
@@ -15,7 +15,7 @@ function useCommandCore({
15
15
  fieldBag,
16
16
  feedback,
17
17
  input,
18
- buildRawPayload = emptyRecord,
18
+ buildRawPayload,
19
19
  buildCommandPayload,
20
20
  buildCommandOptions = emptyRecord,
21
21
  onRunSuccess,
@@ -25,6 +25,10 @@ function useCommandCore({
25
25
  }) {
26
26
  const queryClient = useQueryClient();
27
27
  const normalizedWriteMethod = String(writeMethod || "POST").trim().toUpperCase();
28
+ // A DELETE sends its parsed input as its body only when the command declares one, by an input schema or a raw
29
+ // payload builder; every other method always sends it.
30
+ const sendsParsedInput = normalizedWriteMethod !== "DELETE" || Boolean(input) || buildRawPayload !== undefined;
31
+ const readRawPayload = buildRawPayload ?? emptyRecord;
28
32
 
29
33
  const running = resource.isSaving;
30
34
  const fieldErrors = fieldBag.errors;
@@ -39,7 +43,7 @@ function useCommandCore({
39
43
  feedback.clear();
40
44
  fieldBag.clear();
41
45
 
42
- const rawPayload = buildRawPayload(model, {
46
+ const rawPayload = readRawPayload(model, {
43
47
  queryClient,
44
48
  resource,
45
49
  context
@@ -57,7 +61,7 @@ function useCommandCore({
57
61
  }
58
62
 
59
63
  const { parsedInput } = validationResult;
60
- // readable-check: allow method-probe - optional operation: without buildCommandPayload a command sends its parsed input, and nothing for DELETE
64
+ // readable-check: allow method-probe - optional operation: without buildCommandPayload a command sends its parsed input
61
65
  const payload = typeof buildCommandPayload === "function"
62
66
  ? buildCommandPayload(parsedInput, {
63
67
  rawPayload,
@@ -65,7 +69,7 @@ function useCommandCore({
65
69
  resource,
66
70
  context
67
71
  })
68
- : (normalizedWriteMethod === "DELETE" ? undefined : parsedInput);
72
+ : (sendsParsedInput ? parsedInput : undefined);
69
73
 
70
74
  const options = buildCommandOptions(parsedInput, {
71
75
  rawPayload,
@@ -206,7 +206,7 @@
206
206
  * @property {UiFeedback} feedback
207
207
  * @property {unknown} [input]
208
208
  * @property {(model: any, context: Record<string, any>) => Record<string, any>} [buildRawPayload]
209
- * @property {(parsedInput: any, context: Record<string, any>) => unknown} [buildCommandPayload] Without it a command sends its parsed input, and nothing for DELETE.
209
+ * @property {(parsedInput: any, context: Record<string, any>) => unknown} [buildCommandPayload] Without it a command sends its parsed input; a DELETE sends it only when the command declares `input` or `buildRawPayload`, and otherwise no body.
210
210
  * @property {(parsedInput: any, context: Record<string, any>) => Record<string, any>} [buildCommandOptions]
211
211
  * @property {(response: any, context: Record<string, any>) => unknown} [onRunSuccess]
212
212
  * @property {(error: unknown, context: Record<string, any>) => unknown} [onRunError]
@@ -4,6 +4,7 @@ import { QueryClient, QueryObserver, VueQueryPlugin } from "@tanstack/vue-query"
4
4
  import { createSSRApp, h } from "vue";
5
5
  import { renderToString } from "vue/server-renderer";
6
6
  import { routeLocationKey } from "vue-router";
7
+ import { createSchema } from "json-rest-schema";
7
8
 
8
9
  import {
9
10
  buildEndpointReadRequestOptions,
@@ -596,8 +597,65 @@ test("commands use public CRUD resource access without a CSRF session preflight"
596
597
  assert.equal(calls.length, 1);
597
598
  assert.equal(calls[0][0], "/api/books/1");
598
599
  assert.equal(calls[0][1].method, "DELETE");
600
+ assert.equal(calls[0][1].body, undefined);
599
601
  assert.equal(Object.hasOwn(calls[0][1], "csrf"), false);
600
602
  } finally {
601
603
  configureHttpWebClient();
602
604
  }
603
605
  });
606
+
607
+ // Runs one DELETE command with the given options and answers the request it sent.
608
+ async function sendDeleteCommand(options) {
609
+ const calls = [];
610
+ let command = null;
611
+ configureHttpWebClient({
612
+ fetchImpl: async (url, request) => {
613
+ calls.push([url, request]);
614
+ return { ok: true, status: 204, headers: { get: () => "" }, json: async () => ({}) };
615
+ }
616
+ });
617
+ try {
618
+ const app = createSSRApp({
619
+ setup() {
620
+ command = useCommand({
621
+ access: "always",
622
+ apiSuffix: "/saved-views/7",
623
+ writeMethod: "DELETE",
624
+ resource: { apiAccess: "public" },
625
+ ...options
626
+ });
627
+ return () => h("div");
628
+ }
629
+ });
630
+ app.provide(routeLocationKey, { path: "/" });
631
+ app.use(VueQueryPlugin, { queryClient: new QueryClient() });
632
+ await renderToString(app);
633
+ await command.run();
634
+ } finally {
635
+ configureHttpWebClient();
636
+ }
637
+ assert.equal(calls.length, 1);
638
+ assert.equal(calls[0][1].method, "DELETE");
639
+ return calls[0][1];
640
+ }
641
+
642
+ test("a DELETE command sends its parsed input as the body when it declares input or buildRawPayload", async () => {
643
+ const input = {
644
+ schema: createSchema({ reason: { type: "string", required: true }, copies: { type: "number" } }),
645
+ mode: "create"
646
+ };
647
+
648
+ const validated = await sendDeleteCommand({ input, buildRawPayload: () => ({ reason: "duplicate", copies: "2" }) });
649
+ assert.equal(validated.headers["Content-Type"], "application/json");
650
+ assert.deepEqual(JSON.parse(validated.body), { reason: "duplicate", copies: 2 });
651
+
652
+ const raw = await sendDeleteCommand({ buildRawPayload: () => ({ force: true }) });
653
+ assert.deepEqual(JSON.parse(raw.body), { force: true });
654
+
655
+ const schemaOnly = await sendDeleteCommand({ input: { schema: createSchema({ note: { type: "string" } }) } });
656
+ assert.deepEqual(JSON.parse(schemaOnly.body), {});
657
+
658
+ // A buildCommandPayload still decides the body itself.
659
+ const built = await sendDeleteCommand({ input, buildRawPayload: () => ({ reason: "x" }), buildCommandPayload: () => undefined });
660
+ assert.equal(built.body, undefined);
661
+ });