@strapi/core 5.36.1 → 5.37.0
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/dist/core-api/controller/index.d.ts.map +1 -1
- package/dist/core-api/controller/index.js +17 -16
- package/dist/core-api/controller/index.js.map +1 -1
- package/dist/core-api/controller/index.mjs +17 -16
- package/dist/core-api/controller/index.mjs.map +1 -1
- package/dist/core-api/routes/index.js +15 -2
- package/dist/core-api/routes/index.js.map +1 -1
- package/dist/core-api/routes/index.mjs +15 -2
- package/dist/core-api/routes/index.mjs.map +1 -1
- package/dist/core-api/routes/validation/content-type.d.ts +5 -1
- package/dist/core-api/routes/validation/content-type.d.ts.map +1 -1
- package/dist/core-api/routes/validation/content-type.js +10 -0
- package/dist/core-api/routes/validation/content-type.js.map +1 -1
- package/dist/core-api/routes/validation/content-type.mjs +10 -0
- package/dist/core-api/routes/validation/content-type.mjs.map +1 -1
- package/dist/package.json.js +14 -14
- package/dist/package.json.mjs +14 -14
- package/dist/services/content-api/index.d.ts +6 -3
- package/dist/services/content-api/index.d.ts.map +1 -1
- package/dist/services/content-api/index.js +165 -3
- package/dist/services/content-api/index.js.map +1 -1
- package/dist/services/content-api/index.mjs +147 -4
- package/dist/services/content-api/index.mjs.map +1 -1
- package/dist/services/document-service/draft-and-publish.d.ts +16 -2
- package/dist/services/document-service/draft-and-publish.d.ts.map +1 -1
- package/dist/services/document-service/draft-and-publish.js +53 -0
- package/dist/services/document-service/draft-and-publish.js.map +1 -1
- package/dist/services/document-service/draft-and-publish.mjs +53 -2
- package/dist/services/document-service/draft-and-publish.mjs.map +1 -1
- package/dist/services/document-service/params.d.ts +24 -0
- package/dist/services/document-service/params.d.ts.map +1 -1
- package/dist/services/document-service/params.js +33 -0
- package/dist/services/document-service/params.js.map +1 -1
- package/dist/services/document-service/params.mjs +31 -1
- package/dist/services/document-service/params.mjs.map +1 -1
- package/dist/services/document-service/repository.d.ts.map +1 -1
- package/dist/services/document-service/repository.js +165 -4
- package/dist/services/document-service/repository.js.map +1 -1
- package/dist/services/document-service/repository.mjs +167 -6
- package/dist/services/document-service/repository.mjs.map +1 -1
- package/dist/services/document-service/transform/query.d.ts.map +1 -1
- package/dist/services/document-service/transform/query.js +39 -3
- package/dist/services/document-service/transform/query.js.map +1 -1
- package/dist/services/document-service/transform/query.mjs +37 -1
- package/dist/services/document-service/transform/query.mjs.map +1 -1
- package/dist/services/server/register-routes.js +3 -0
- package/dist/services/server/register-routes.js.map +1 -1
- package/dist/services/server/register-routes.mjs +3 -0
- package/dist/services/server/register-routes.mjs.map +1 -1
- package/package.json +14 -14
package/dist/package.json.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var name = "@strapi/core";
|
|
6
|
-
var version = "5.
|
|
6
|
+
var version = "5.37.0";
|
|
7
7
|
var description = "Core of Strapi";
|
|
8
8
|
var homepage = "https://strapi.io";
|
|
9
9
|
var bugs = {
|
|
@@ -61,20 +61,20 @@ var dependencies = {
|
|
|
61
61
|
"@koa/cors": "5.0.0",
|
|
62
62
|
"@koa/router": "12.0.2",
|
|
63
63
|
"@paralleldrive/cuid2": "2.2.2",
|
|
64
|
-
"@strapi/admin": "5.
|
|
65
|
-
"@strapi/database": "5.
|
|
66
|
-
"@strapi/generators": "5.
|
|
67
|
-
"@strapi/logger": "5.
|
|
68
|
-
"@strapi/permissions": "5.
|
|
69
|
-
"@strapi/types": "5.
|
|
70
|
-
"@strapi/typescript-utils": "5.
|
|
71
|
-
"@strapi/utils": "5.
|
|
64
|
+
"@strapi/admin": "5.37.0",
|
|
65
|
+
"@strapi/database": "5.37.0",
|
|
66
|
+
"@strapi/generators": "5.37.0",
|
|
67
|
+
"@strapi/logger": "5.37.0",
|
|
68
|
+
"@strapi/permissions": "5.37.0",
|
|
69
|
+
"@strapi/types": "5.37.0",
|
|
70
|
+
"@strapi/typescript-utils": "5.37.0",
|
|
71
|
+
"@strapi/utils": "5.37.0",
|
|
72
72
|
"@vercel/stega": "0.1.2",
|
|
73
73
|
bcryptjs: "2.4.3",
|
|
74
74
|
boxen: "5.1.2",
|
|
75
75
|
chalk: "4.1.2",
|
|
76
76
|
"ci-info": "4.0.0",
|
|
77
|
-
"cli-table3": "0.6.
|
|
77
|
+
"cli-table3": "0.6.5",
|
|
78
78
|
commander: "8.3.0",
|
|
79
79
|
configstore: "5.0.1",
|
|
80
80
|
copyfiles: "2.4.1",
|
|
@@ -99,7 +99,7 @@ var dependencies = {
|
|
|
99
99
|
"koa-ip": "^2.1.3",
|
|
100
100
|
"koa-session": "6.4.0",
|
|
101
101
|
"koa-static": "5.0.0",
|
|
102
|
-
lodash: "4.17.
|
|
102
|
+
lodash: "4.17.23",
|
|
103
103
|
"mime-types": "2.1.35",
|
|
104
104
|
"node-schedule": "2.1.1",
|
|
105
105
|
open: "8.4.0",
|
|
@@ -136,11 +136,11 @@ var devDependencies = {
|
|
|
136
136
|
"@types/node": "24.10.0",
|
|
137
137
|
"@types/node-schedule": "2.1.7",
|
|
138
138
|
"@types/statuses": "2.0.1",
|
|
139
|
-
"eslint-config-custom": "5.
|
|
139
|
+
"eslint-config-custom": "5.37.0",
|
|
140
140
|
supertest: "6.3.3",
|
|
141
|
-
tsconfig: "5.
|
|
141
|
+
tsconfig: "5.37.0",
|
|
142
142
|
vitest: "4.0.18",
|
|
143
|
-
"vitest-config": "5.
|
|
143
|
+
"vitest-config": "5.37.0"
|
|
144
144
|
};
|
|
145
145
|
var engines = {
|
|
146
146
|
node: ">=20.0.0 <=24.x.x",
|
package/dist/package.json.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
var name = "@strapi/core";
|
|
2
|
-
var version = "5.
|
|
2
|
+
var version = "5.37.0";
|
|
3
3
|
var description = "Core of Strapi";
|
|
4
4
|
var homepage = "https://strapi.io";
|
|
5
5
|
var bugs = {
|
|
@@ -57,20 +57,20 @@ var dependencies = {
|
|
|
57
57
|
"@koa/cors": "5.0.0",
|
|
58
58
|
"@koa/router": "12.0.2",
|
|
59
59
|
"@paralleldrive/cuid2": "2.2.2",
|
|
60
|
-
"@strapi/admin": "5.
|
|
61
|
-
"@strapi/database": "5.
|
|
62
|
-
"@strapi/generators": "5.
|
|
63
|
-
"@strapi/logger": "5.
|
|
64
|
-
"@strapi/permissions": "5.
|
|
65
|
-
"@strapi/types": "5.
|
|
66
|
-
"@strapi/typescript-utils": "5.
|
|
67
|
-
"@strapi/utils": "5.
|
|
60
|
+
"@strapi/admin": "5.37.0",
|
|
61
|
+
"@strapi/database": "5.37.0",
|
|
62
|
+
"@strapi/generators": "5.37.0",
|
|
63
|
+
"@strapi/logger": "5.37.0",
|
|
64
|
+
"@strapi/permissions": "5.37.0",
|
|
65
|
+
"@strapi/types": "5.37.0",
|
|
66
|
+
"@strapi/typescript-utils": "5.37.0",
|
|
67
|
+
"@strapi/utils": "5.37.0",
|
|
68
68
|
"@vercel/stega": "0.1.2",
|
|
69
69
|
bcryptjs: "2.4.3",
|
|
70
70
|
boxen: "5.1.2",
|
|
71
71
|
chalk: "4.1.2",
|
|
72
72
|
"ci-info": "4.0.0",
|
|
73
|
-
"cli-table3": "0.6.
|
|
73
|
+
"cli-table3": "0.6.5",
|
|
74
74
|
commander: "8.3.0",
|
|
75
75
|
configstore: "5.0.1",
|
|
76
76
|
copyfiles: "2.4.1",
|
|
@@ -95,7 +95,7 @@ var dependencies = {
|
|
|
95
95
|
"koa-ip": "^2.1.3",
|
|
96
96
|
"koa-session": "6.4.0",
|
|
97
97
|
"koa-static": "5.0.0",
|
|
98
|
-
lodash: "4.17.
|
|
98
|
+
lodash: "4.17.23",
|
|
99
99
|
"mime-types": "2.1.35",
|
|
100
100
|
"node-schedule": "2.1.1",
|
|
101
101
|
open: "8.4.0",
|
|
@@ -132,11 +132,11 @@ var devDependencies = {
|
|
|
132
132
|
"@types/node": "24.10.0",
|
|
133
133
|
"@types/node-schedule": "2.1.7",
|
|
134
134
|
"@types/statuses": "2.0.1",
|
|
135
|
-
"eslint-config-custom": "5.
|
|
135
|
+
"eslint-config-custom": "5.37.0",
|
|
136
136
|
supertest: "6.3.3",
|
|
137
|
-
tsconfig: "5.
|
|
137
|
+
tsconfig: "5.37.0",
|
|
138
138
|
vitest: "4.0.18",
|
|
139
|
-
"vitest-config": "5.
|
|
139
|
+
"vitest-config": "5.37.0"
|
|
140
140
|
};
|
|
141
141
|
var engines = {
|
|
142
142
|
node: ">=20.0.0 <=24.x.x",
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { sanitize, validate } from '@strapi/utils';
|
|
2
|
-
import type { Core } from '@strapi/types';
|
|
2
|
+
import type { Core, Modules } from '@strapi/types';
|
|
3
3
|
/**
|
|
4
4
|
* Create a content API container that holds logic, tools and utils. (eg: permissions, ...)
|
|
5
5
|
*/
|
|
@@ -51,7 +51,7 @@ declare const createContentAPI: (strapi: Core.Strapi) => {
|
|
|
51
51
|
sanitize: {
|
|
52
52
|
input: sanitize.SanitizeFunc;
|
|
53
53
|
output: sanitize.SanitizeFunc;
|
|
54
|
-
query: (query: Record<string, unknown>, schema: import("@strapi/utils/dist/types").Model, { auth }?: sanitize.Options | undefined) => Promise<Record<string, unknown>>;
|
|
54
|
+
query: (query: Record<string, unknown>, schema: import("@strapi/utils/dist/types").Model, { auth, strictParams, route }?: sanitize.Options | undefined) => Promise<Record<string, unknown>>;
|
|
55
55
|
filters: sanitize.SanitizeFunc;
|
|
56
56
|
sort: sanitize.SanitizeFunc;
|
|
57
57
|
fields: sanitize.SanitizeFunc;
|
|
@@ -59,12 +59,15 @@ declare const createContentAPI: (strapi: Core.Strapi) => {
|
|
|
59
59
|
};
|
|
60
60
|
validate: {
|
|
61
61
|
input: validate.ValidateFunc;
|
|
62
|
-
query: (query: Record<string, unknown>, schema: import("@strapi/utils/dist/types").Model, { auth }?: validate.Options | undefined) => Promise<void>;
|
|
62
|
+
query: (query: Record<string, unknown>, schema: import("@strapi/utils/dist/types").Model, { auth, strictParams, route }?: validate.Options | undefined) => Promise<void>;
|
|
63
63
|
filters: validate.ValidateFunc;
|
|
64
64
|
sort: validate.ValidateFunc;
|
|
65
65
|
fields: validate.ValidateFunc;
|
|
66
66
|
populate: validate.ValidateFunc;
|
|
67
67
|
};
|
|
68
|
+
addQueryParams: (options: Modules.ContentAPI.AddQueryParamsOptions) => void;
|
|
69
|
+
addInputParams: (options: Modules.ContentAPI.AddInputParamsOptions) => void;
|
|
70
|
+
applyExtraParamsToRoutes: (routes: Core.Route[]) => void;
|
|
68
71
|
};
|
|
69
72
|
export default createContentAPI;
|
|
70
73
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/services/content-api/index.ts"],"names":[],"mappings":"AACA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/services/content-api/index.ts"],"names":[],"mappings":"AACA,OAAO,EACL,QAAQ,EACR,QAAQ,EAIT,MAAM,eAAe,CAAC;AAGvB,OAAO,KAAK,EAAE,IAAI,EAAE,OAAO,EAAO,MAAM,eAAe,CAAC;AAiHxD;;GAEG;AACH,QAAA,MAAM,gBAAgB,WAAY,KAAK,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;8BA0CV,QAAQ,UAAU,CAAC,qBAAqB;8BAQxC,QAAQ,UAAU,CAAC,qBAAqB;uCAK/B,KAAK,KAAK,EAAE,KAAG,IAAI;CA2F9D,CAAC;AAEF,eAAe,gBAAgB,CAAC"}
|
|
@@ -2,8 +2,28 @@
|
|
|
2
2
|
|
|
3
3
|
var _ = require('lodash');
|
|
4
4
|
var strapiUtils = require('@strapi/utils');
|
|
5
|
+
var z = require('zod/v4');
|
|
5
6
|
var index = require('./permissions/index.js');
|
|
6
7
|
|
|
8
|
+
function _interopNamespaceDefault(e) {
|
|
9
|
+
var n = Object.create(null);
|
|
10
|
+
if (e) {
|
|
11
|
+
Object.keys(e).forEach(function (k) {
|
|
12
|
+
if (k !== 'default') {
|
|
13
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
14
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
get: function () { return e[k]; }
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
n.default = e;
|
|
22
|
+
return Object.freeze(n);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
var z__namespace = /*#__PURE__*/_interopNamespaceDefault(z);
|
|
26
|
+
|
|
7
27
|
const transformRoutePrefixFor = (pluginName)=>(route)=>{
|
|
8
28
|
const prefix = route.config && route.config.prefix;
|
|
9
29
|
const path = prefix !== undefined ? `${prefix}${route.path}` : `/${pluginName}${route.path}`;
|
|
@@ -13,9 +33,150 @@ const transformRoutePrefixFor = (pluginName)=>(route)=>{
|
|
|
13
33
|
};
|
|
14
34
|
};
|
|
15
35
|
const filterContentAPI = (route)=>route.info.type === 'content-api';
|
|
36
|
+
/**
|
|
37
|
+
* Runtime check for addQueryParams: we only allow scalar or array-of-scalar schemas (no nested objects).
|
|
38
|
+
* We keep this in addition to the ZodQueryParamSchema type because: (1) TypeScript can be bypassed (JS,
|
|
39
|
+
* any, or schema from another Zod instance); (2) it gives a clear, immediate error at registration
|
|
40
|
+
* time instead of a later failure in validate/sanitize. This list is intentionally tied to Zod v4
|
|
41
|
+
* constructor names; if Zod changes internals, this may need updating.
|
|
42
|
+
* Compatibility: Zod 3 and Zod 4 Classic (zod/v4) both use these constructor names and
|
|
43
|
+
* expose ._def with .innerType / .element for Optional/Default/Array. Zod 4 Core/Mini use
|
|
44
|
+
* ._zod.def instead; we only accept schemas from the same zod/v4 instance used here.
|
|
45
|
+
*/ const ALLOWED_QUERY_SCHEMA_NAMES = new Set([
|
|
46
|
+
'ZodString',
|
|
47
|
+
'ZodNumber',
|
|
48
|
+
'ZodBoolean',
|
|
49
|
+
'ZodEnum',
|
|
50
|
+
'ZodOptional',
|
|
51
|
+
'ZodDefault',
|
|
52
|
+
'ZodArray'
|
|
53
|
+
]);
|
|
54
|
+
function assertQueryParamSchema(schema, param) {
|
|
55
|
+
const name = schema?.constructor?.name ?? '';
|
|
56
|
+
if (!ALLOWED_QUERY_SCHEMA_NAMES.has(name)) {
|
|
57
|
+
throw new Error(`contentAPI.addQueryParams: param "${param}" schema must be a scalar (string, number, boolean, enum) or array of scalars; got ${name}. Use addInputParams for nested objects.`);
|
|
58
|
+
}
|
|
59
|
+
if (name === 'ZodOptional' || name === 'ZodDefault') {
|
|
60
|
+
const inner = schema?._def?.innerType;
|
|
61
|
+
if (inner) assertQueryParamSchema(inner, param);
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
if (name === 'ZodArray') {
|
|
65
|
+
const element = schema?._def?.element;
|
|
66
|
+
if (element) assertQueryParamSchema(element, param);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
function resolveSchema(schemaOrFactory) {
|
|
70
|
+
if (typeof schemaOrFactory === 'function') {
|
|
71
|
+
return schemaOrFactory(z__namespace);
|
|
72
|
+
}
|
|
73
|
+
return schemaOrFactory;
|
|
74
|
+
}
|
|
75
|
+
const mergeOneQueryParamIntoRoute = (route, param, schema, matchRoute)=>{
|
|
76
|
+
if (matchRoute && !matchRoute(route)) return;
|
|
77
|
+
const query = {
|
|
78
|
+
...route.request?.query ?? {}
|
|
79
|
+
};
|
|
80
|
+
if (param in query) {
|
|
81
|
+
throw new Error(`contentAPI.addQueryParams: param "${param}" already exists on route ${route.method} ${route.path}`);
|
|
82
|
+
}
|
|
83
|
+
route.request = {
|
|
84
|
+
...route.request,
|
|
85
|
+
query: {
|
|
86
|
+
...query,
|
|
87
|
+
[param]: schema
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
};
|
|
91
|
+
const mergeOneInputParamIntoRoute = (route, param, schema, matchRoute)=>{
|
|
92
|
+
if (matchRoute && !matchRoute(route)) return;
|
|
93
|
+
const jsonKey = 'application/json';
|
|
94
|
+
const body = route.request?.body ? {
|
|
95
|
+
...route.request.body
|
|
96
|
+
} : {};
|
|
97
|
+
const existing = body[jsonKey];
|
|
98
|
+
const base = existing && typeof existing === 'object' && 'shape' in existing ? existing.shape : {};
|
|
99
|
+
if (param in base) {
|
|
100
|
+
throw new Error(`contentAPI.addInputParams: param "${param}" already exists on route ${route.method} ${route.path}`);
|
|
101
|
+
}
|
|
102
|
+
body[jsonKey] = z__namespace.object({
|
|
103
|
+
...base,
|
|
104
|
+
[param]: schema
|
|
105
|
+
});
|
|
106
|
+
route.request = {
|
|
107
|
+
...route.request,
|
|
108
|
+
body
|
|
109
|
+
};
|
|
110
|
+
};
|
|
16
111
|
/**
|
|
17
112
|
* Create a content API container that holds logic, tools and utils. (eg: permissions, ...)
|
|
18
113
|
*/ const createContentAPI = (strapi)=>{
|
|
114
|
+
const extraQueryParams = [];
|
|
115
|
+
const extraInputParams = [];
|
|
116
|
+
const addQueryParam = (options)=>{
|
|
117
|
+
const { param, schema: schemaOrFactory, matchRoute } = options;
|
|
118
|
+
const schema = resolveSchema(schemaOrFactory);
|
|
119
|
+
assertQueryParamSchema(schema, param);
|
|
120
|
+
if (strapiUtils.ALLOWED_QUERY_PARAM_KEYS.includes(param)) {
|
|
121
|
+
throw new Error(`contentAPI.addQueryParams: param "${param}" is reserved by Strapi; use a different name`);
|
|
122
|
+
}
|
|
123
|
+
if (extraQueryParams.some((o)=>o.param === param)) {
|
|
124
|
+
throw new Error(`contentAPI.addQueryParams: param "${param}" has already been added`);
|
|
125
|
+
}
|
|
126
|
+
extraQueryParams.push({
|
|
127
|
+
param,
|
|
128
|
+
schema,
|
|
129
|
+
matchRoute
|
|
130
|
+
});
|
|
131
|
+
// Params are merged into routes when initRouting() runs (applyExtraParamsToRoutes).
|
|
132
|
+
// We do not merge here: at register() time routes may not exist yet (lazy creation), and
|
|
133
|
+
// merging here would cause double-merge when initRouting runs and 400 "invalid param" or
|
|
134
|
+
// "param already exists" errors.
|
|
135
|
+
};
|
|
136
|
+
const addInputParam = (options)=>{
|
|
137
|
+
const { param, schema: schemaOrFactory, matchRoute } = options;
|
|
138
|
+
const schema = resolveSchema(schemaOrFactory);
|
|
139
|
+
if (strapiUtils.RESERVED_INPUT_PARAM_KEYS.includes(param)) {
|
|
140
|
+
throw new Error(`contentAPI.addInputParams: param "${param}" is reserved by Strapi; use a different name`);
|
|
141
|
+
}
|
|
142
|
+
if (extraInputParams.some((o)=>o.param === param)) {
|
|
143
|
+
throw new Error(`contentAPI.addInputParams: param "${param}" has already been added`);
|
|
144
|
+
}
|
|
145
|
+
extraInputParams.push({
|
|
146
|
+
param,
|
|
147
|
+
schema,
|
|
148
|
+
matchRoute
|
|
149
|
+
});
|
|
150
|
+
// Params are merged into routes when initRouting() runs (applyExtraParamsToRoutes).
|
|
151
|
+
};
|
|
152
|
+
/**
|
|
153
|
+
* Register extra query params. Keys = param names; values = { schema, matchRoute? }.
|
|
154
|
+
* Schemas must be Zod scalar or array-of-scalars (enforced at runtime via assertQueryParamSchema).
|
|
155
|
+
*/ const addQueryParams = (options)=>{
|
|
156
|
+
Object.entries(options).forEach(([param, rest])=>addQueryParam({
|
|
157
|
+
param,
|
|
158
|
+
...rest
|
|
159
|
+
}));
|
|
160
|
+
};
|
|
161
|
+
/**
|
|
162
|
+
* Register extra input params (root-level body.data). Keys = param names; values = { schema, matchRoute? }.
|
|
163
|
+
* Any Zod type allowed; enforced at registration time.
|
|
164
|
+
*/ const addInputParams = (options)=>{
|
|
165
|
+
Object.entries(options).forEach(([param, rest])=>addInputParam({
|
|
166
|
+
param,
|
|
167
|
+
...rest
|
|
168
|
+
}));
|
|
169
|
+
};
|
|
170
|
+
/** Merge all registered extra params into the given routes (mutates in place). Called at route registration. Throws if a param key already exists. */ const applyExtraParamsToRoutes = (routes)=>{
|
|
171
|
+
routes.forEach((route)=>{
|
|
172
|
+
for (const { param, schema, matchRoute } of extraQueryParams){
|
|
173
|
+
mergeOneQueryParamIntoRoute(route, param, schema, matchRoute);
|
|
174
|
+
}
|
|
175
|
+
for (const { param, schema, matchRoute } of extraInputParams){
|
|
176
|
+
mergeOneInputParamIntoRoute(route, param, schema, matchRoute);
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
};
|
|
19
180
|
const getRoutesMap = async ()=>{
|
|
20
181
|
const routesMap = {};
|
|
21
182
|
_.forEach(strapi.apis, (api, apiName)=>{
|
|
@@ -55,7 +216,6 @@ const filterContentAPI = (route)=>route.info.type === 'content-api';
|
|
|
55
216
|
getModel (uid) {
|
|
56
217
|
return strapi.getModel(uid);
|
|
57
218
|
},
|
|
58
|
-
// NOTE: use lazy access to allow registration of sanitizers after the creation of the container
|
|
59
219
|
get sanitizers () {
|
|
60
220
|
return {
|
|
61
221
|
input: strapi.sanitizers.get('content-api.input'),
|
|
@@ -67,7 +227,6 @@ const filterContentAPI = (route)=>route.info.type === 'content-api';
|
|
|
67
227
|
getModel (uid) {
|
|
68
228
|
return strapi.getModel(uid);
|
|
69
229
|
},
|
|
70
|
-
// NOTE: use lazy access to allow registration of validators after the creation of the container
|
|
71
230
|
get validators () {
|
|
72
231
|
return {
|
|
73
232
|
input: strapi.validators.get('content-api.input')
|
|
@@ -78,7 +237,10 @@ const filterContentAPI = (route)=>route.info.type === 'content-api';
|
|
|
78
237
|
permissions: index(strapi),
|
|
79
238
|
getRoutesMap,
|
|
80
239
|
sanitize: sanitizer,
|
|
81
|
-
validate: validator
|
|
240
|
+
validate: validator,
|
|
241
|
+
addQueryParams,
|
|
242
|
+
addInputParams,
|
|
243
|
+
applyExtraParamsToRoutes
|
|
82
244
|
};
|
|
83
245
|
};
|
|
84
246
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../src/services/content-api/index.ts"],"sourcesContent":["import _ from 'lodash';\nimport { sanitize, validate, sanitizeRoutesMapForSerialization } from '@strapi/utils';\n\nimport type { Core, UID } from '@strapi/types';\n\nimport instantiatePermissionsUtilities from './permissions';\n\nconst transformRoutePrefixFor = (pluginName: string) => (route: Core.Route) => {\n const prefix = route.config && route.config.prefix;\n const path = prefix !== undefined ? `${prefix}${route.path}` : `/${pluginName}${route.path}`;\n\n return {\n ...route,\n path,\n };\n};\n\nconst filterContentAPI = (route: Core.Route) => route.info.type === 'content-api';\n\n/**\n * Create a content API container that holds logic, tools and utils. (eg: permissions, ...)\n */\nconst createContentAPI = (strapi: Core.Strapi) => {\n const getRoutesMap = async () => {\n const routesMap: Record<string, Core.Route[]> = {};\n\n _.forEach(strapi.apis, (api, apiName) => {\n const routes = _.flatMap(api.routes, (route) => {\n if ('routes' in route) {\n return route.routes;\n }\n\n return route;\n }).filter(filterContentAPI);\n\n if (routes.length === 0) {\n return;\n }\n\n const apiPrefix = strapi.config.get('api.rest.prefix');\n routesMap[`api::${apiName}`] = routes.map((route) => ({\n ...route,\n path: `${apiPrefix}${route.path}`,\n }));\n });\n\n _.forEach(strapi.plugins, (plugin, pluginName) => {\n const transformPrefix = transformRoutePrefixFor(pluginName);\n\n if (Array.isArray(plugin.routes)) {\n return plugin.routes.map(transformPrefix).filter(filterContentAPI);\n }\n\n const routes = _.flatMap(plugin.routes, (route) => route.routes.map(transformPrefix)).filter(\n filterContentAPI\n );\n\n if (routes.length === 0) {\n return;\n }\n\n const apiPrefix = strapi.config.get('api.rest.prefix');\n routesMap[`plugin::${pluginName}`] = routes.map((route) => ({\n ...route,\n path: `${apiPrefix}${route.path}`,\n }));\n });\n\n return sanitizeRoutesMapForSerialization(routesMap);\n };\n\n const sanitizer = sanitize.createAPISanitizers({\n getModel(uid: string) {\n return strapi.getModel(uid as UID.Schema);\n },\n // NOTE: use lazy access to allow registration of sanitizers after the creation of the container\n get sanitizers() {\n return {\n input: strapi.sanitizers.get('content-api.input'),\n output: strapi.sanitizers.get('content-api.output'),\n };\n },\n });\n\n const validator = validate.createAPIValidators({\n getModel(uid: string) {\n return strapi.getModel(uid as UID.Schema);\n },\n // NOTE: use lazy access to allow registration of validators after the creation of the container\n get validators() {\n return {\n input: strapi.validators.get('content-api.input'),\n };\n },\n });\n\n return {\n permissions: instantiatePermissionsUtilities(strapi),\n getRoutesMap,\n sanitize: sanitizer,\n validate: validator,\n };\n};\n\nexport default createContentAPI;\n"],"names":["transformRoutePrefixFor","pluginName","route","prefix","config","path","undefined","filterContentAPI","info","type","createContentAPI","strapi","getRoutesMap","routesMap","_","forEach","apis","api","apiName","routes","flatMap","filter","length","apiPrefix","get","map","plugins","plugin","transformPrefix","Array","isArray","sanitizeRoutesMapForSerialization","sanitizer","sanitize","createAPISanitizers","getModel","uid","sanitizers","input","output","validator","validate","createAPIValidators","validators","permissions","instantiatePermissionsUtilities"],"mappings":";;;;;;AAOA,MAAMA,uBAAAA,GAA0B,CAACC,UAAAA,GAAuB,CAACC,KAAAA,GAAAA;AACvD,QAAA,MAAMC,SAASD,KAAME,CAAAA,MAAM,IAAIF,KAAME,CAAAA,MAAM,CAACD,MAAM;AAClD,QAAA,MAAME,IAAOF,GAAAA,MAAAA,KAAWG,SAAY,GAAA,CAAA,EAAGH,SAASD,KAAMG,CAAAA,IAAI,CAAE,CAAA,GAAG,CAAC,CAAC,EAAEJ,UAAaC,CAAAA,EAAAA,KAAAA,CAAMG,IAAI,CAAE,CAAA;QAE5F,OAAO;AACL,YAAA,GAAGH,KAAK;AACRG,YAAAA;AACF,SAAA;AACF,KAAA;AAEA,MAAME,mBAAmB,CAACL,KAAAA,GAAsBA,MAAMM,IAAI,CAACC,IAAI,KAAK,aAAA;AAEpE;;IAGA,MAAMC,mBAAmB,CAACC,MAAAA,GAAAA;AACxB,IAAA,MAAMC,YAAe,GAAA,UAAA;AACnB,QAAA,MAAMC,YAA0C,EAAC;AAEjDC,QAAAA,CAAAA,CAAEC,OAAO,CAACJ,MAAAA,CAAOK,IAAI,EAAE,CAACC,GAAKC,EAAAA,OAAAA,GAAAA;A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GAAG,CAAC,mBAAA;AAC/B,aAAA;AACF;AACF,KAAA,CAAA;IAEA,OAAO;AACLoB,QAAAA,WAAAA,EAAaC,KAAgClC,CAAAA,MAAAA,CAAAA;AAC7CC,QAAAA,YAAAA;QACAqB,QAAUD,EAAAA,SAAAA;QACVS,QAAUD,EAAAA;AACZ,KAAA;AACF;;;;"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../src/services/content-api/index.ts"],"sourcesContent":["import _ from 'lodash';\nimport {\n sanitize,\n validate,\n sanitizeRoutesMapForSerialization,\n ALLOWED_QUERY_PARAM_KEYS,\n RESERVED_INPUT_PARAM_KEYS,\n} from '@strapi/utils';\nimport * as z from 'zod/v4';\n\nimport type { Core, Modules, UID } from '@strapi/types';\n\nimport instantiatePermissionsUtilities from './permissions';\n\nconst transformRoutePrefixFor = (pluginName: string) => (route: Core.Route) => {\n const prefix = route.config && route.config.prefix;\n const path = prefix !== undefined ? `${prefix}${route.path}` : `/${pluginName}${route.path}`;\n\n return {\n ...route,\n path,\n };\n};\n\nconst filterContentAPI = (route: Core.Route) => route.info.type === 'content-api';\n\n/**\n * Runtime check for addQueryParams: we only allow scalar or array-of-scalar schemas (no nested objects).\n * We keep this in addition to the ZodQueryParamSchema type because: (1) TypeScript can be bypassed (JS,\n * any, or schema from another Zod instance); (2) it gives a clear, immediate error at registration\n * time instead of a later failure in validate/sanitize. This list is intentionally tied to Zod v4\n * constructor names; if Zod changes internals, this may need updating.\n * Compatibility: Zod 3 and Zod 4 Classic (zod/v4) both use these constructor names and\n * expose ._def with .innerType / .element for Optional/Default/Array. Zod 4 Core/Mini use\n * ._zod.def instead; we only accept schemas from the same zod/v4 instance used here.\n */\nconst ALLOWED_QUERY_SCHEMA_NAMES = new Set([\n 'ZodString',\n 'ZodNumber',\n 'ZodBoolean',\n 'ZodEnum',\n 'ZodOptional',\n 'ZodDefault',\n 'ZodArray',\n]);\n\nfunction assertQueryParamSchema(schema: unknown, param: string): void {\n const name = (schema as { constructor?: { name?: string } })?.constructor?.name ?? '';\n if (!ALLOWED_QUERY_SCHEMA_NAMES.has(name)) {\n throw new Error(\n `contentAPI.addQueryParams: param \"${param}\" schema must be a scalar (string, number, boolean, enum) or array of scalars; got ${name}. Use addInputParams for nested objects.`\n );\n }\n if (name === 'ZodOptional' || name === 'ZodDefault') {\n const inner = (schema as { _def?: { innerType?: unknown } })?._def?.innerType;\n if (inner) assertQueryParamSchema(inner, param);\n return;\n }\n if (name === 'ZodArray') {\n const element = (schema as { _def?: { element?: unknown } })?._def?.element;\n if (element) assertQueryParamSchema(element, param);\n }\n}\n\nfunction resolveSchema<T>(schemaOrFactory: T | ((zInstance: typeof z) => T)): T {\n if (typeof schemaOrFactory === 'function') {\n return (schemaOrFactory as (zInstance: typeof z) => T)(z);\n }\n return schemaOrFactory;\n}\n\nconst mergeOneQueryParamIntoRoute = (\n route: Core.Route,\n param: string,\n schema: z.ZodType,\n matchRoute?: (route: Core.Route) => boolean\n): void => {\n if (matchRoute && !matchRoute(route)) return;\n const query = { ...(route.request?.query ?? {}) };\n if (param in query) {\n throw new Error(\n `contentAPI.addQueryParams: param \"${param}\" already exists on route ${route.method} ${route.path}`\n );\n }\n route.request = { ...route.request, query: { ...query, [param]: schema } };\n};\n\nconst mergeOneInputParamIntoRoute = (\n route: Core.Route,\n param: string,\n schema: z.ZodType,\n matchRoute?: (route: Core.Route) => boolean\n): void => {\n if (matchRoute && !matchRoute(route)) return;\n const jsonKey = 'application/json';\n type RouteBody = NonNullable<NonNullable<Core.Route['request']>['body']>;\n const body: RouteBody = route.request?.body ? { ...route.request.body } : ({} as RouteBody);\n const existing = body[jsonKey];\n const base =\n existing && typeof existing === 'object' && 'shape' in existing\n ? (existing as { shape: Record<string, z.ZodType> }).shape\n : {};\n if (param in base) {\n throw new Error(\n `contentAPI.addInputParams: param \"${param}\" already exists on route ${route.method} ${route.path}`\n );\n }\n body[jsonKey] = z.object({ ...base, [param]: schema }) as RouteBody[keyof RouteBody];\n route.request = { ...route.request, body };\n};\n\n/** Stored options with schema always resolved (never a function). */\ntype ResolvedQueryParamEntry = {\n param: string;\n schema: z.ZodType;\n matchRoute?: (route: Core.Route) => boolean;\n};\ntype ResolvedInputParamEntry = {\n param: string;\n schema: z.ZodType;\n matchRoute?: (route: Core.Route) => boolean;\n};\n\n/**\n * Create a content API container that holds logic, tools and utils. (eg: permissions, ...)\n */\nconst createContentAPI = (strapi: Core.Strapi) => {\n const extraQueryParams: ResolvedQueryParamEntry[] = [];\n const extraInputParams: ResolvedInputParamEntry[] = [];\n\n const addQueryParam = (options: Modules.ContentAPI.QueryParamEntry & { param: string }) => {\n const { param, schema: schemaOrFactory, matchRoute } = options;\n const schema = resolveSchema(schemaOrFactory);\n assertQueryParamSchema(schema, param);\n if ((ALLOWED_QUERY_PARAM_KEYS as readonly string[]).includes(param)) {\n throw new Error(\n `contentAPI.addQueryParams: param \"${param}\" is reserved by Strapi; use a different name`\n );\n }\n if (extraQueryParams.some((o) => o.param === param)) {\n throw new Error(`contentAPI.addQueryParams: param \"${param}\" has already been added`);\n }\n extraQueryParams.push({ param, schema, matchRoute });\n // Params are merged into routes when initRouting() runs (applyExtraParamsToRoutes).\n // We do not merge here: at register() time routes may not exist yet (lazy creation), and\n // merging here would cause double-merge when initRouting runs and 400 \"invalid param\" or\n // \"param already exists\" errors.\n };\n\n const addInputParam = (options: Modules.ContentAPI.InputParamEntry & { param: string }) => {\n const { param, schema: schemaOrFactory, matchRoute } = options;\n const schema = resolveSchema(schemaOrFactory);\n if ((RESERVED_INPUT_PARAM_KEYS as readonly string[]).includes(param)) {\n throw new Error(\n `contentAPI.addInputParams: param \"${param}\" is reserved by Strapi; use a different name`\n );\n }\n if (extraInputParams.some((o) => o.param === param)) {\n throw new Error(`contentAPI.addInputParams: param \"${param}\" has already been added`);\n }\n extraInputParams.push({ param, schema, matchRoute });\n // Params are merged into routes when initRouting() runs (applyExtraParamsToRoutes).\n };\n\n /**\n * Register extra query params. Keys = param names; values = { schema, matchRoute? }.\n * Schemas must be Zod scalar or array-of-scalars (enforced at runtime via assertQueryParamSchema).\n */\n const addQueryParams = (options: Modules.ContentAPI.AddQueryParamsOptions) => {\n Object.entries(options).forEach(([param, rest]) => addQueryParam({ param, ...rest }));\n };\n\n /**\n * Register extra input params (root-level body.data). Keys = param names; values = { schema, matchRoute? }.\n * Any Zod type allowed; enforced at registration time.\n */\n const addInputParams = (options: Modules.ContentAPI.AddInputParamsOptions) => {\n Object.entries(options).forEach(([param, rest]) => addInputParam({ param, ...rest }));\n };\n\n /** Merge all registered extra params into the given routes (mutates in place). Called at route registration. Throws if a param key already exists. */\n const applyExtraParamsToRoutes = (routes: Core.Route[]): void => {\n routes.forEach((route) => {\n for (const { param, schema, matchRoute } of extraQueryParams) {\n mergeOneQueryParamIntoRoute(route, param, schema, matchRoute);\n }\n for (const { param, schema, matchRoute } of extraInputParams) {\n mergeOneInputParamIntoRoute(route, param, schema, matchRoute);\n }\n });\n };\n\n const getRoutesMap = async () => {\n const routesMap: Record<string, Core.Route[]> = {};\n\n _.forEach(strapi.apis, (api, apiName) => {\n const routes = _.flatMap(api.routes, (route) => {\n if ('routes' in route) {\n return route.routes;\n }\n\n return route;\n }).filter(filterContentAPI);\n\n if (routes.length === 0) {\n return;\n }\n\n const apiPrefix = strapi.config.get('api.rest.prefix');\n routesMap[`api::${apiName}`] = routes.map((route) => ({\n ...route,\n path: `${apiPrefix}${route.path}`,\n }));\n });\n\n _.forEach(strapi.plugins, (plugin, pluginName) => {\n const transformPrefix = transformRoutePrefixFor(pluginName);\n\n if (Array.isArray(plugin.routes)) {\n return plugin.routes.map(transformPrefix).filter(filterContentAPI);\n }\n\n const routes = _.flatMap(plugin.routes, (route) => route.routes.map(transformPrefix)).filter(\n filterContentAPI\n );\n\n if (routes.length === 0) {\n return;\n }\n\n const apiPrefix = strapi.config.get('api.rest.prefix');\n routesMap[`plugin::${pluginName}`] = routes.map((route) => ({\n ...route,\n path: `${apiPrefix}${route.path}`,\n }));\n });\n\n return sanitizeRoutesMapForSerialization(routesMap);\n };\n\n const sanitizer = sanitize.createAPISanitizers({\n getModel(uid: string) {\n return strapi.getModel(uid as UID.Schema);\n },\n get sanitizers() {\n return {\n input: strapi.sanitizers.get('content-api.input'),\n output: strapi.sanitizers.get('content-api.output'),\n };\n },\n });\n\n const validator = validate.createAPIValidators({\n getModel(uid: string) {\n return strapi.getModel(uid as UID.Schema);\n },\n get validators() {\n return {\n input: strapi.validators.get('content-api.input'),\n };\n },\n });\n\n return {\n permissions: instantiatePermissionsUtilities(strapi),\n getRoutesMap,\n sanitize: sanitizer,\n validate: validator,\n addQueryParams,\n addInputParams,\n applyExtraParamsToRoutes,\n };\n};\n\nexport default createContentAPI;\n"],"names":["transformRoutePrefixFor","pluginName","route","prefix","config","path","undefined","filterContentAPI","info","type","ALLOWED_QUERY_SCHEMA_NAMES","Set","assertQueryParamSchema","schema","param","name","has","Error","inner","_def","innerType","element","resolveSchema","schemaOrFactory","z","mergeOneQueryParamIntoRoute","matchRoute","query","request","method","mergeOneInputParamIntoRoute","jsonKey","body","existing","base","shape","object","createContentAPI","strapi","extraQueryParams","extraInputParams","addQueryParam","options","ALLOWED_QUERY_PARAM_KEYS","includes","some","o","push","addInputParam","RESERVED_INPUT_PARAM_KEYS","addQueryParams","Object","entries","forEach","rest","addInputParams","applyExtraParamsToRoutes","routes","getRoutesMap","routesMap","_","apis","api","apiName","flatMap","filter","length","apiPrefix","get","map","plugins","plugin","transformPrefix","Array","isArray","sanitizeRoutesMapForSerialization","sanitizer","sanitize","createAPISanitizers","getModel","uid","sanitizers","input","output","validator","validate","createAPIValidators","validators","permissions","instantiatePermissionsUtilities"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAcA,MAAMA,uBAAAA,GAA0B,CAACC,UAAAA,GAAuB,CAACC,KAAAA,GAAAA;AACvD,QAAA,MAAMC,SAASD,KAAME,CAAAA,MAAM,IAAIF,KAAME,CAAAA,MAAM,CAACD,MAAM;AAClD,QAAA,MAA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/utils';
|
|
2
|
+
import { sanitize, validate, sanitizeRoutesMapForSerialization, ALLOWED_QUERY_PARAM_KEYS, RESERVED_INPUT_PARAM_KEYS } from '@strapi/utils';
|
|
3
|
+
import * as z from 'zod/v4';
|
|
3
4
|
import instantiatePermissionsUtilities from './permissions/index.mjs';
|
|
4
5
|
|
|
5
6
|
const transformRoutePrefixFor = (pluginName)=>(route)=>{
|
|
@@ -11,9 +12,150 @@ const transformRoutePrefixFor = (pluginName)=>(route)=>{
|
|
|
11
12
|
};
|
|
12
13
|
};
|
|
13
14
|
const filterContentAPI = (route)=>route.info.type === 'content-api';
|
|
15
|
+
/**
|
|
16
|
+
* Runtime check for addQueryParams: we only allow scalar or array-of-scalar schemas (no nested objects).
|
|
17
|
+
* We keep this in addition to the ZodQueryParamSchema type because: (1) TypeScript can be bypassed (JS,
|
|
18
|
+
* any, or schema from another Zod instance); (2) it gives a clear, immediate error at registration
|
|
19
|
+
* time instead of a later failure in validate/sanitize. This list is intentionally tied to Zod v4
|
|
20
|
+
* constructor names; if Zod changes internals, this may need updating.
|
|
21
|
+
* Compatibility: Zod 3 and Zod 4 Classic (zod/v4) both use these constructor names and
|
|
22
|
+
* expose ._def with .innerType / .element for Optional/Default/Array. Zod 4 Core/Mini use
|
|
23
|
+
* ._zod.def instead; we only accept schemas from the same zod/v4 instance used here.
|
|
24
|
+
*/ const ALLOWED_QUERY_SCHEMA_NAMES = new Set([
|
|
25
|
+
'ZodString',
|
|
26
|
+
'ZodNumber',
|
|
27
|
+
'ZodBoolean',
|
|
28
|
+
'ZodEnum',
|
|
29
|
+
'ZodOptional',
|
|
30
|
+
'ZodDefault',
|
|
31
|
+
'ZodArray'
|
|
32
|
+
]);
|
|
33
|
+
function assertQueryParamSchema(schema, param) {
|
|
34
|
+
const name = schema?.constructor?.name ?? '';
|
|
35
|
+
if (!ALLOWED_QUERY_SCHEMA_NAMES.has(name)) {
|
|
36
|
+
throw new Error(`contentAPI.addQueryParams: param "${param}" schema must be a scalar (string, number, boolean, enum) or array of scalars; got ${name}. Use addInputParams for nested objects.`);
|
|
37
|
+
}
|
|
38
|
+
if (name === 'ZodOptional' || name === 'ZodDefault') {
|
|
39
|
+
const inner = schema?._def?.innerType;
|
|
40
|
+
if (inner) assertQueryParamSchema(inner, param);
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
if (name === 'ZodArray') {
|
|
44
|
+
const element = schema?._def?.element;
|
|
45
|
+
if (element) assertQueryParamSchema(element, param);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
function resolveSchema(schemaOrFactory) {
|
|
49
|
+
if (typeof schemaOrFactory === 'function') {
|
|
50
|
+
return schemaOrFactory(z);
|
|
51
|
+
}
|
|
52
|
+
return schemaOrFactory;
|
|
53
|
+
}
|
|
54
|
+
const mergeOneQueryParamIntoRoute = (route, param, schema, matchRoute)=>{
|
|
55
|
+
if (matchRoute && !matchRoute(route)) return;
|
|
56
|
+
const query = {
|
|
57
|
+
...route.request?.query ?? {}
|
|
58
|
+
};
|
|
59
|
+
if (param in query) {
|
|
60
|
+
throw new Error(`contentAPI.addQueryParams: param "${param}" already exists on route ${route.method} ${route.path}`);
|
|
61
|
+
}
|
|
62
|
+
route.request = {
|
|
63
|
+
...route.request,
|
|
64
|
+
query: {
|
|
65
|
+
...query,
|
|
66
|
+
[param]: schema
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
};
|
|
70
|
+
const mergeOneInputParamIntoRoute = (route, param, schema, matchRoute)=>{
|
|
71
|
+
if (matchRoute && !matchRoute(route)) return;
|
|
72
|
+
const jsonKey = 'application/json';
|
|
73
|
+
const body = route.request?.body ? {
|
|
74
|
+
...route.request.body
|
|
75
|
+
} : {};
|
|
76
|
+
const existing = body[jsonKey];
|
|
77
|
+
const base = existing && typeof existing === 'object' && 'shape' in existing ? existing.shape : {};
|
|
78
|
+
if (param in base) {
|
|
79
|
+
throw new Error(`contentAPI.addInputParams: param "${param}" already exists on route ${route.method} ${route.path}`);
|
|
80
|
+
}
|
|
81
|
+
body[jsonKey] = z.object({
|
|
82
|
+
...base,
|
|
83
|
+
[param]: schema
|
|
84
|
+
});
|
|
85
|
+
route.request = {
|
|
86
|
+
...route.request,
|
|
87
|
+
body
|
|
88
|
+
};
|
|
89
|
+
};
|
|
14
90
|
/**
|
|
15
91
|
* Create a content API container that holds logic, tools and utils. (eg: permissions, ...)
|
|
16
92
|
*/ const createContentAPI = (strapi)=>{
|
|
93
|
+
const extraQueryParams = [];
|
|
94
|
+
const extraInputParams = [];
|
|
95
|
+
const addQueryParam = (options)=>{
|
|
96
|
+
const { param, schema: schemaOrFactory, matchRoute } = options;
|
|
97
|
+
const schema = resolveSchema(schemaOrFactory);
|
|
98
|
+
assertQueryParamSchema(schema, param);
|
|
99
|
+
if (ALLOWED_QUERY_PARAM_KEYS.includes(param)) {
|
|
100
|
+
throw new Error(`contentAPI.addQueryParams: param "${param}" is reserved by Strapi; use a different name`);
|
|
101
|
+
}
|
|
102
|
+
if (extraQueryParams.some((o)=>o.param === param)) {
|
|
103
|
+
throw new Error(`contentAPI.addQueryParams: param "${param}" has already been added`);
|
|
104
|
+
}
|
|
105
|
+
extraQueryParams.push({
|
|
106
|
+
param,
|
|
107
|
+
schema,
|
|
108
|
+
matchRoute
|
|
109
|
+
});
|
|
110
|
+
// Params are merged into routes when initRouting() runs (applyExtraParamsToRoutes).
|
|
111
|
+
// We do not merge here: at register() time routes may not exist yet (lazy creation), and
|
|
112
|
+
// merging here would cause double-merge when initRouting runs and 400 "invalid param" or
|
|
113
|
+
// "param already exists" errors.
|
|
114
|
+
};
|
|
115
|
+
const addInputParam = (options)=>{
|
|
116
|
+
const { param, schema: schemaOrFactory, matchRoute } = options;
|
|
117
|
+
const schema = resolveSchema(schemaOrFactory);
|
|
118
|
+
if (RESERVED_INPUT_PARAM_KEYS.includes(param)) {
|
|
119
|
+
throw new Error(`contentAPI.addInputParams: param "${param}" is reserved by Strapi; use a different name`);
|
|
120
|
+
}
|
|
121
|
+
if (extraInputParams.some((o)=>o.param === param)) {
|
|
122
|
+
throw new Error(`contentAPI.addInputParams: param "${param}" has already been added`);
|
|
123
|
+
}
|
|
124
|
+
extraInputParams.push({
|
|
125
|
+
param,
|
|
126
|
+
schema,
|
|
127
|
+
matchRoute
|
|
128
|
+
});
|
|
129
|
+
// Params are merged into routes when initRouting() runs (applyExtraParamsToRoutes).
|
|
130
|
+
};
|
|
131
|
+
/**
|
|
132
|
+
* Register extra query params. Keys = param names; values = { schema, matchRoute? }.
|
|
133
|
+
* Schemas must be Zod scalar or array-of-scalars (enforced at runtime via assertQueryParamSchema).
|
|
134
|
+
*/ const addQueryParams = (options)=>{
|
|
135
|
+
Object.entries(options).forEach(([param, rest])=>addQueryParam({
|
|
136
|
+
param,
|
|
137
|
+
...rest
|
|
138
|
+
}));
|
|
139
|
+
};
|
|
140
|
+
/**
|
|
141
|
+
* Register extra input params (root-level body.data). Keys = param names; values = { schema, matchRoute? }.
|
|
142
|
+
* Any Zod type allowed; enforced at registration time.
|
|
143
|
+
*/ const addInputParams = (options)=>{
|
|
144
|
+
Object.entries(options).forEach(([param, rest])=>addInputParam({
|
|
145
|
+
param,
|
|
146
|
+
...rest
|
|
147
|
+
}));
|
|
148
|
+
};
|
|
149
|
+
/** Merge all registered extra params into the given routes (mutates in place). Called at route registration. Throws if a param key already exists. */ const applyExtraParamsToRoutes = (routes)=>{
|
|
150
|
+
routes.forEach((route)=>{
|
|
151
|
+
for (const { param, schema, matchRoute } of extraQueryParams){
|
|
152
|
+
mergeOneQueryParamIntoRoute(route, param, schema, matchRoute);
|
|
153
|
+
}
|
|
154
|
+
for (const { param, schema, matchRoute } of extraInputParams){
|
|
155
|
+
mergeOneInputParamIntoRoute(route, param, schema, matchRoute);
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
};
|
|
17
159
|
const getRoutesMap = async ()=>{
|
|
18
160
|
const routesMap = {};
|
|
19
161
|
_.forEach(strapi.apis, (api, apiName)=>{
|
|
@@ -53,7 +195,6 @@ const filterContentAPI = (route)=>route.info.type === 'content-api';
|
|
|
53
195
|
getModel (uid) {
|
|
54
196
|
return strapi.getModel(uid);
|
|
55
197
|
},
|
|
56
|
-
// NOTE: use lazy access to allow registration of sanitizers after the creation of the container
|
|
57
198
|
get sanitizers () {
|
|
58
199
|
return {
|
|
59
200
|
input: strapi.sanitizers.get('content-api.input'),
|
|
@@ -65,7 +206,6 @@ const filterContentAPI = (route)=>route.info.type === 'content-api';
|
|
|
65
206
|
getModel (uid) {
|
|
66
207
|
return strapi.getModel(uid);
|
|
67
208
|
},
|
|
68
|
-
// NOTE: use lazy access to allow registration of validators after the creation of the container
|
|
69
209
|
get validators () {
|
|
70
210
|
return {
|
|
71
211
|
input: strapi.validators.get('content-api.input')
|
|
@@ -76,7 +216,10 @@ const filterContentAPI = (route)=>route.info.type === 'content-api';
|
|
|
76
216
|
permissions: instantiatePermissionsUtilities(strapi),
|
|
77
217
|
getRoutesMap,
|
|
78
218
|
sanitize: sanitizer,
|
|
79
|
-
validate: validator
|
|
219
|
+
validate: validator,
|
|
220
|
+
addQueryParams,
|
|
221
|
+
addInputParams,
|
|
222
|
+
applyExtraParamsToRoutes
|
|
80
223
|
};
|
|
81
224
|
};
|
|
82
225
|
|