dropsh 0.4.1 → 0.5.1
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/README.md
CHANGED
|
@@ -55,14 +55,18 @@ Optional modules unlock stricter schemas or builder-specific support:
|
|
|
55
55
|
| Feature | Drupal modules |
|
|
56
56
|
| --- | --- |
|
|
57
57
|
| OAuth2 login | `simple_oauth` |
|
|
58
|
-
| Authoritative schemas | `
|
|
58
|
+
| Authoritative schemas (Drupal 10.1+/11) | `jsonapi_schema` |
|
|
59
|
+
| Authoritative schemas (legacy; 500s on D11/PHP 8.4) | `schemata`, `schemata_json_schema` |
|
|
59
60
|
| Canvas schemas | `canvas`, `jsonapi_sdc` |
|
|
60
61
|
| Display Builder schemas | `display_builder`, `display_builder_entity_view`, `jsonapi_sdc` |
|
|
61
62
|
|
|
62
|
-
dropsh works without
|
|
63
|
-
back to a shallow schema inferred from JSON:API sample records.
|
|
64
|
-
|
|
65
|
-
|
|
63
|
+
dropsh works without an authoritative-schema module. In that case, `dropsh
|
|
64
|
+
schema` falls back to a shallow schema inferred from JSON:API sample records.
|
|
65
|
+
Installing `jsonapi_schema` lets `@dropsh/plugin-jsonapi-schema` return a more
|
|
66
|
+
precise schema with Drupal's required fields, formats, and constraints — so
|
|
67
|
+
`create`/`update` reject malformed payloads client-side. On **Drupal 11 / PHP
|
|
68
|
+
8.4** prefer `jsonapi_schema`: the older `schemata_json_schema` endpoint returns
|
|
69
|
+
HTTP 500 there.
|
|
66
70
|
|
|
67
71
|
### Installing the Drupal modules
|
|
68
72
|
|
|
@@ -77,16 +81,21 @@ drush en jsonapi
|
|
|
77
81
|
composer require drupal/simple_oauth
|
|
78
82
|
drush en simple_oauth
|
|
79
83
|
|
|
80
|
-
# Optional: authoritative schemas (
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
84
|
+
# Optional: authoritative schemas (Drupal 10.1+/11, PHP 8.4) — recommended
|
|
85
|
+
composer require drupal/jsonapi_schema
|
|
86
|
+
drush en jsonapi_schema
|
|
87
|
+
|
|
88
|
+
# Legacy alternative — the schemata endpoint returns HTTP 500 on
|
|
89
|
+
# Drupal 11 / PHP 8.4; prefer jsonapi_schema there.
|
|
90
|
+
# composer require drupal/schemata
|
|
91
|
+
# drush en schemata schemata_json_schema
|
|
92
|
+
# drush role:perm:add "content_editor" "access schemata data models"
|
|
85
93
|
```
|
|
86
94
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
endpoint
|
|
95
|
+
`jsonapi_schema` serves its routes under the JSON:API prefix (`/jsonapi/*`), so
|
|
96
|
+
the role/consumer used by dropsh needs no extra permission beyond JSON:API
|
|
97
|
+
access. (The legacy `schemata` endpoint instead needs `access schemata data
|
|
98
|
+
models` on that role.)
|
|
90
99
|
|
|
91
100
|
By default JSON:API only accepts read operations. To create, update, or delete
|
|
92
101
|
entities through dropsh, set **Accept all JSON:API create, read, update, and
|
|
@@ -103,7 +112,7 @@ store.
|
|
|
103
112
|
```js
|
|
104
113
|
import { basicAuthPlugin } from "dropsh";
|
|
105
114
|
import { oauth2Plugin } from "@dropsh/plugin-oauth2";
|
|
106
|
-
import {
|
|
115
|
+
import { jsonapiSchemaPlugin } from "@dropsh/plugin-jsonapi-schema";
|
|
107
116
|
|
|
108
117
|
export default {
|
|
109
118
|
site: {
|
|
@@ -121,7 +130,7 @@ export default {
|
|
|
121
130
|
client_id: "my-client",
|
|
122
131
|
token_url: "https://my-drupal.example.com/oauth/token",
|
|
123
132
|
}),
|
|
124
|
-
|
|
133
|
+
jsonapiSchemaPlugin(),
|
|
125
134
|
],
|
|
126
135
|
};
|
|
127
136
|
```
|
|
@@ -4,7 +4,13 @@ export async function fetchJsonSchema(deps) {
|
|
|
4
4
|
const { entity, bundle } = deps;
|
|
5
5
|
const target = { entity_type: entity, bundle };
|
|
6
6
|
const plugins = deps.plugins ?? [];
|
|
7
|
-
const ctx = {
|
|
7
|
+
const ctx = {
|
|
8
|
+
http: deps.http,
|
|
9
|
+
auth: deps.auth,
|
|
10
|
+
baseUrl: deps.baseUrl,
|
|
11
|
+
jsonapiPrefix: deps.jsonapiPrefix,
|
|
12
|
+
warn: deps.warn,
|
|
13
|
+
};
|
|
8
14
|
// Build heuristic base schema
|
|
9
15
|
let heuristicResult;
|
|
10
16
|
try {
|
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
import Ajv from "ajv";
|
|
2
2
|
import draft6MetaSchema from "ajv/dist/refs/json-schema-draft-06.json" with { type: "json" };
|
|
3
3
|
import draft7MetaSchema from "ajv/dist/refs/json-schema-draft-07.json" with { type: "json" };
|
|
4
|
+
import addFormats from "ajv-formats";
|
|
4
5
|
import { ValidationError } from "../../errors.js";
|
|
5
6
|
export function validatePayload(schema, payload, target) {
|
|
6
7
|
const ajv = new Ajv({ allErrors: true, strict: false, validateSchema: false, logger: false });
|
|
8
|
+
// Enforce standard `format` keywords (uri, date-time, uuid, email, …) so a
|
|
9
|
+
// constraint-bearing schema (e.g. from the jsonapi-schema plugin) rejects a
|
|
10
|
+
// malformed value — such as an SCP-style git remote where a URI is required —
|
|
11
|
+
// client-side, before the request is sent. Schemas without `format` are
|
|
12
|
+
// unaffected.
|
|
13
|
+
addFormats(ajv);
|
|
7
14
|
// Schemata (Drupal module) may emit Draft-04 schemas that use `id` instead of `$id`.
|
|
8
15
|
// AJV v8 hard-throws on `id`; removing the keyword makes AJV silently ignore it.
|
|
9
16
|
ajv.removeKeyword("id");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dropsh",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.1",
|
|
4
4
|
"description": "Entity-agnostic helper CLI for Drupal 11 JSON:API, used by the dropsh Claude skill for editorial publishing workflows.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -34,6 +34,7 @@
|
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"ajv": "^8.18.0",
|
|
37
|
+
"ajv-formats": "^3.0.1",
|
|
37
38
|
"commander": "^12.1.0",
|
|
38
39
|
"drupal-jsonapi-params": "^3.0.1",
|
|
39
40
|
"open": "^11.0.0"
|