json-rest-api 1.0.14 → 1.0.16
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/connectors_ideas/fastify.js +66 -68
- package/connectors_ideas/koa-plugin.js +50 -51
- package/eslint.config.js +11 -2
- package/examples/url-override-example.js +63 -63
- package/index.js +13 -13
- package/lib/enhanced-logger.js +51 -51
- package/lib/error-formatter.js +61 -61
- package/lib/rest-api-errors.js +28 -28
- package/package.json +1 -1
- package/plugins/core/bulk-operations-plugin.js +142 -145
- package/plugins/core/connectors/express-plugin.js +210 -217
- package/plugins/core/connectors/lib/busboy-detector.js +84 -84
- package/plugins/core/connectors/lib/formidable-detector.js +50 -50
- package/plugins/core/connectors/lib/request-helpers.js +74 -74
- package/plugins/core/file-handling-plugin.js +125 -125
- package/plugins/core/lib/anyapi/anyapi-registry.js +254 -254
- package/plugins/core/lib/anyapi/query/anyapi-query-adapter.js +287 -287
- package/plugins/core/lib/anyapi/schema-utils.js +101 -101
- package/plugins/core/lib/anyapi/utils/descriptor-helpers.js +41 -41
- package/plugins/core/lib/dbTablesOperations.js +134 -135
- package/plugins/core/lib/fractional-positioning.js +74 -76
- package/plugins/core/lib/querying/knex-cross-table-search.js +320 -320
- package/plugins/core/lib/querying/knex-json-api-transformers-querying.js +144 -144
- package/plugins/core/lib/querying/knex-pagination-helpers.js +164 -164
- package/plugins/core/lib/querying/knex-process-includes.js +50 -50
- package/plugins/core/lib/querying/knex-query-helpers-base.js +31 -31
- package/plugins/core/lib/querying/knex-query-helpers.js +451 -452
- package/plugins/core/lib/querying/knex-relationship-includes.js +1160 -1170
- package/plugins/core/lib/querying/knex-window-queries.js +89 -89
- package/plugins/core/lib/querying/url-helpers.js +35 -35
- package/plugins/core/lib/querying-writing/compile-schemas.js +99 -99
- package/plugins/core/lib/querying-writing/connectors-query-parser.js +31 -31
- package/plugins/core/lib/querying-writing/database-capabilities.js +94 -94
- package/plugins/core/lib/querying-writing/database-value-normalizers.js +76 -76
- package/plugins/core/lib/querying-writing/default-data-helpers.js +27 -27
- package/plugins/core/lib/querying-writing/field-utils.js +44 -42
- package/plugins/core/lib/querying-writing/knex-constants.js +15 -16
- package/plugins/core/lib/querying-writing/knex-field-helpers.js +117 -115
- package/plugins/core/lib/querying-writing/knex-json-api-transformers.js +41 -41
- package/plugins/core/lib/querying-writing/payload-validators.js +275 -275
- package/plugins/core/lib/querying-writing/schema-helpers.js +129 -129
- package/plugins/core/lib/querying-writing/scope-validations.js +143 -146
- package/plugins/core/lib/querying-writing/simplified-helpers.js +133 -129
- package/plugins/core/lib/storage/storage-adapter.js +68 -68
- package/plugins/core/lib/writing/knex-json-api-transformers-writing.js +31 -31
- package/plugins/core/lib/writing/many-to-many-manipulations.js +81 -81
- package/plugins/core/lib/writing/relationship-processor.js +58 -58
- package/plugins/core/rest-api-access.js +11 -15
- package/plugins/core/rest-api-anyapi-knex-plugin.js +920 -920
- package/plugins/core/rest-api-cors-plugin.js +170 -171
- package/plugins/core/rest-api-knex-plugin.js +482 -493
- package/plugins/core/rest-api-multihome-plugin.js +247 -251
- package/plugins/core/rest-api-plugin-hooks/compile-resource-schemas.js +5 -5
- package/plugins/core/rest-api-plugin-hooks/register-relationship-routes.js +20 -21
- package/plugins/core/rest-api-plugin-hooks/register-scope-routes.js +44 -44
- package/plugins/core/rest-api-plugin-hooks/turn-scope-init-into-vars.js +23 -23
- package/plugins/core/rest-api-plugin-hooks/validate-include-configurations.js +15 -15
- package/plugins/core/rest-api-plugin-methods/add-route.js +9 -9
- package/plugins/core/rest-api-plugin-methods/check-permissions.js +5 -6
- package/plugins/core/rest-api-plugin-methods/common.js +295 -297
- package/plugins/core/rest-api-plugin-methods/delete-relationship.js +35 -37
- package/plugins/core/rest-api-plugin-methods/delete.js +57 -59
- package/plugins/core/rest-api-plugin-methods/enrich-attributes.js +172 -171
- package/plugins/core/rest-api-plugin-methods/get-related.js +96 -96
- package/plugins/core/rest-api-plugin-methods/get-relationship.js +16 -18
- package/plugins/core/rest-api-plugin-methods/get.js +86 -86
- package/plugins/core/rest-api-plugin-methods/patch-relationship.js +16 -17
- package/plugins/core/rest-api-plugin-methods/patch.js +63 -64
- package/plugins/core/rest-api-plugin-methods/post-relationship.js +54 -55
- package/plugins/core/rest-api-plugin-methods/post.js +61 -62
- package/plugins/core/rest-api-plugin-methods/put.js +86 -87
- package/plugins/core/rest-api-plugin-methods/query.js +88 -88
- package/plugins/core/rest-api-plugin-methods/release.js +5 -6
- package/plugins/core/rest-api-plugin.js +76 -78
- package/plugins/core/rest-api-positioning-plugin.js +251 -252
- package/plugins/core/socketio-plugin.js +240 -236
- package/plugins/storage/local-storage.js +103 -103
- package/plugins/storage/s3-storage.js +41 -42
- package/quickTest.js +37 -37
- package/scripts/debug-anyapi-review-filter.mjs +18 -18
- package/scripts/inspect-anyapi-descriptor-country.mjs +10 -10
- package/scripts/inspect-anyapi-descriptor.mjs +10 -10
- package/scripts/run-docs.js +112 -113
- package/test-debug.js +28 -28
- package/tests/TEST_TEMPLATE.test.js +51 -51
- package/tests/anyapi-basic.test.js +42 -42
- package/tests/anyapi-cursor-pagination.test.js +48 -48
- package/tests/bulk-operations.test.js +208 -208
- package/tests/computed-fields.test.js +204 -204
- package/tests/cors.test.js +412 -413
- package/tests/curl.test.js +275 -276
- package/tests/custom-idproperty-relationships.test.js +266 -266
- package/tests/field-getters.test.js +132 -132
- package/tests/field-setters.test.js +110 -110
- package/tests/fixtures/api-configs.js +699 -699
- package/tests/helpers/storage-mode.js +32 -32
- package/tests/helpers/test-utils.js +76 -76
- package/tests/include-depth-validation.test.js +76 -76
- package/tests/includes.test.js +145 -145
- package/tests/multihome.test.js +175 -175
- package/tests/nested-includes.test.js +255 -255
- package/tests/pagination-cursor-multifield.test.js +164 -164
- package/tests/pagination-enhanced.test.js +225 -225
- package/tests/polymorphic-relationships.test.js +96 -96
- package/tests/polymorphic-simple.test.js +44 -44
- package/tests/positioning-advanced.test.js +226 -226
- package/tests/positioning-extended.test.js +399 -399
- package/tests/positioning-multifilter.test.js +204 -204
- package/tests/positioning.test.js +266 -266
- package/tests/queries.test.js +184 -184
- package/tests/query-limits.test.js +154 -155
- package/tests/relationship-endpoints.test.js +127 -127
- package/tests/relationships.test.js +178 -179
- package/tests/rest-api-access.test.js +86 -86
- package/tests/rest-api.test.js +103 -103
- package/tests/searchschema-merge.test.js +93 -93
- package/tests/socketio.test.js +326 -326
- package/tests/virtual-fields.test.js +164 -164
|
@@ -4,7 +4,7 @@ export const AccessPlugin = {
|
|
|
4
4
|
name: 'rest-api-access',
|
|
5
5
|
dependencies: ['rest-api'],
|
|
6
6
|
|
|
7
|
-
async install({ addHook, helpers, log, pluginOptions = {}, scopes }) {
|
|
7
|
+
async install ({ addHook, helpers, log, pluginOptions = {}, scopes }) {
|
|
8
8
|
const ownershipOptions = pluginOptions.ownership || pluginOptions.autoOwnership || {}
|
|
9
9
|
|
|
10
10
|
const config = {
|
|
@@ -27,7 +27,6 @@ export const AccessPlugin = {
|
|
|
27
27
|
const evaluateOwnership = ({ record, field, schemaInfo, userId }) => {
|
|
28
28
|
if (!record) return 'unknown'
|
|
29
29
|
|
|
30
|
-
debugger
|
|
31
30
|
const idProperty = schemaInfo?.idProperty || 'id'
|
|
32
31
|
const schemaStructure = schemaInfo?.schemaStructure || {}
|
|
33
32
|
const schemaRelationships = schemaInfo?.schemaRelationships || {}
|
|
@@ -105,7 +104,7 @@ export const AccessPlugin = {
|
|
|
105
104
|
return storageAdapter.translateFilterValue(field, value)
|
|
106
105
|
}
|
|
107
106
|
|
|
108
|
-
function registerBuiltinCheckers() {
|
|
107
|
+
function registerBuiltinCheckers () {
|
|
109
108
|
state.authCheckers.set('public', () => true)
|
|
110
109
|
|
|
111
110
|
state.authCheckers.set('authenticated', (context) => {
|
|
@@ -146,7 +145,6 @@ export const AccessPlugin = {
|
|
|
146
145
|
const auth = context.scopeOptions?.auth
|
|
147
146
|
if (!auth) return
|
|
148
147
|
|
|
149
|
-
debugger
|
|
150
148
|
scope.vars.authRules = auth
|
|
151
149
|
scope.vars.ownershipField = context.scopeOptions?.ownershipField
|
|
152
150
|
|
|
@@ -159,11 +157,11 @@ export const AccessPlugin = {
|
|
|
159
157
|
})
|
|
160
158
|
})
|
|
161
159
|
|
|
162
|
-
addHook('schema:enrich', 'rest-auth-auto-ownership-field', {}, ({ context
|
|
160
|
+
addHook('schema:enrich', 'rest-auth-auto-ownership-field', {}, ({ context }) => {
|
|
163
161
|
if (!config.ownership.enabled) return
|
|
164
|
-
const { fields, scopeName } = context
|
|
162
|
+
const { fields, scopeName, scopeOptions = {} } = context
|
|
165
163
|
if (config.ownership.excludeResources.includes(scopeName)) return
|
|
166
|
-
if (scopeOptions
|
|
164
|
+
if (scopeOptions.ownership === false) return
|
|
167
165
|
|
|
168
166
|
const field = ownershipField()
|
|
169
167
|
const relationshipName = fields[field]?.as || fields[field]?.belongsTo || field
|
|
@@ -188,7 +186,7 @@ export const AccessPlugin = {
|
|
|
188
186
|
}
|
|
189
187
|
})
|
|
190
188
|
|
|
191
|
-
function setOwnerOnInput({ context, scopeName, scopes, scopeOptions }) {
|
|
189
|
+
function setOwnerOnInput ({ context, scopeName, scopes, scopeOptions }) {
|
|
192
190
|
if (!config.ownership.enabled) return
|
|
193
191
|
if (config.ownership.excludeResources.includes(scopeName)) return
|
|
194
192
|
if (!context.auth?.userId) {
|
|
@@ -285,7 +283,6 @@ export const AccessPlugin = {
|
|
|
285
283
|
|
|
286
284
|
addHook('checkPermissions', 'rest-auth-enforce', { sequence: -100 }, async ({ context, scope, scopeName }) => {
|
|
287
285
|
const operation = context.method
|
|
288
|
-
debugger
|
|
289
286
|
const scopeVars = scope?.vars
|
|
290
287
|
const authRules = scopeVars?.authRules
|
|
291
288
|
const minimalRecord = context.originalContext?.minimalRecord
|
|
@@ -300,7 +297,6 @@ export const AccessPlugin = {
|
|
|
300
297
|
const failures = []
|
|
301
298
|
|
|
302
299
|
for (const rule of rules) {
|
|
303
|
-
// if (rule === 'owns') debugger
|
|
304
300
|
try {
|
|
305
301
|
const [checkerName, ...paramParts] = rule.split(':')
|
|
306
302
|
const checker = state.authCheckers.get(checkerName)
|
|
@@ -384,7 +380,7 @@ export const AccessPlugin = {
|
|
|
384
380
|
helpers.auth = {}
|
|
385
381
|
}
|
|
386
382
|
|
|
387
|
-
helpers.auth.requireAuth = function requireAuth(context) {
|
|
383
|
+
helpers.auth.requireAuth = function requireAuth (context) {
|
|
388
384
|
if (!context.auth?.userId) {
|
|
389
385
|
const error = new Error('Authentication required')
|
|
390
386
|
error.statusCode = 401
|
|
@@ -393,7 +389,7 @@ export const AccessPlugin = {
|
|
|
393
389
|
return context.auth
|
|
394
390
|
}
|
|
395
391
|
|
|
396
|
-
helpers.auth.requireOwnership = function requireOwnership(context, resourceOrUserId) {
|
|
392
|
+
helpers.auth.requireOwnership = function requireOwnership (context, resourceOrUserId) {
|
|
397
393
|
const auth = helpers.auth.requireAuth(context)
|
|
398
394
|
const field = ownershipField()
|
|
399
395
|
|
|
@@ -424,11 +420,11 @@ export const AccessPlugin = {
|
|
|
424
420
|
return auth
|
|
425
421
|
}
|
|
426
422
|
|
|
427
|
-
helpers.auth.registerChecker = function registerChecker(name, checkerFn) {
|
|
423
|
+
helpers.auth.registerChecker = function registerChecker (name, checkerFn) {
|
|
428
424
|
state.authCheckers.set(name, checkerFn)
|
|
429
425
|
}
|
|
430
426
|
|
|
431
|
-
helpers.auth.checkPermission = async function checkPermission(context, rules, options = {}) {
|
|
427
|
+
helpers.auth.checkPermission = async function checkPermission (context, rules, options = {}) {
|
|
432
428
|
if (!rules || rules.length === 0) return true
|
|
433
429
|
|
|
434
430
|
const { existingRecord, scopeVars } = options
|
|
@@ -447,7 +443,7 @@ export const AccessPlugin = {
|
|
|
447
443
|
return false
|
|
448
444
|
}
|
|
449
445
|
|
|
450
|
-
helpers.auth.cleanup = function cleanup() {
|
|
446
|
+
helpers.auth.cleanup = function cleanup () {
|
|
451
447
|
state.authCheckers.clear()
|
|
452
448
|
}
|
|
453
449
|
}
|