@flowerforce/flowerbase 1.2.0 → 1.2.1-beta.3
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/auth/controller.d.ts.map +1 -1
- package/dist/auth/controller.js +3 -0
- package/dist/auth/providers/custom-function/controller.d.ts.map +1 -1
- package/dist/auth/providers/custom-function/controller.js +5 -2
- package/dist/auth/providers/local-userpass/controller.d.ts.map +1 -1
- package/dist/auth/providers/local-userpass/controller.js +7 -10
- package/dist/auth/utils.d.ts +1 -1
- package/dist/auth/utils.d.ts.map +1 -1
- package/dist/auth/utils.js +4 -3
- package/dist/constants.d.ts +5 -0
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +5 -1
- package/dist/features/functions/controller.d.ts.map +1 -1
- package/dist/features/functions/controller.js +28 -2
- package/dist/features/rules/utils.d.ts.map +1 -1
- package/dist/features/rules/utils.js +11 -2
- package/dist/features/triggers/utils.d.ts.map +1 -1
- package/dist/features/triggers/utils.js +52 -2
- package/dist/index.d.ts +8 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -9
- package/dist/services/mongodb-atlas/index.d.ts.map +1 -1
- package/dist/services/mongodb-atlas/index.js +540 -483
- package/dist/services/mongodb-atlas/utils.d.ts +9 -2
- package/dist/services/mongodb-atlas/utils.d.ts.map +1 -1
- package/dist/services/mongodb-atlas/utils.js +113 -23
- package/dist/shared/handleUserRegistration.d.ts.map +1 -1
- package/dist/shared/handleUserRegistration.js +1 -0
- package/dist/shared/models/handleUserRegistration.model.d.ts +6 -2
- package/dist/shared/models/handleUserRegistration.model.d.ts.map +1 -1
- package/dist/utils/context/helpers.d.ts +6 -5
- package/dist/utils/context/helpers.d.ts.map +1 -1
- package/dist/utils/context/helpers.js +3 -0
- package/dist/utils/context/index.d.ts.map +1 -1
- package/dist/utils/context/index.js +2 -0
- package/dist/utils/initializer/exposeRoutes.d.ts.map +1 -1
- package/dist/utils/initializer/exposeRoutes.js +11 -4
- package/dist/utils/initializer/registerPlugins.d.ts +3 -1
- package/dist/utils/initializer/registerPlugins.d.ts.map +1 -1
- package/dist/utils/initializer/registerPlugins.js +9 -6
- package/dist/utils/roles/helpers.js +9 -2
- package/dist/utils/roles/machines/commonValidators.d.ts.map +1 -1
- package/dist/utils/roles/machines/commonValidators.js +10 -6
- package/dist/utils/roles/machines/read/B/validators.d.ts +4 -0
- package/dist/utils/roles/machines/read/B/validators.d.ts.map +1 -0
- package/dist/utils/roles/machines/read/B/validators.js +8 -0
- package/dist/utils/roles/machines/read/C/index.d.ts.map +1 -1
- package/dist/utils/roles/machines/read/C/index.js +10 -7
- package/dist/utils/roles/machines/read/C/validators.d.ts +5 -0
- package/dist/utils/roles/machines/read/C/validators.d.ts.map +1 -0
- package/dist/utils/roles/machines/read/C/validators.js +29 -0
- package/dist/utils/roles/machines/read/D/index.d.ts.map +1 -1
- package/dist/utils/roles/machines/read/D/index.js +13 -11
- package/dist/utils/rules.d.ts +1 -1
- package/dist/utils/rules.d.ts.map +1 -1
- package/dist/utils/rules.js +26 -17
- package/jest.config.ts +2 -12
- package/jest.setup.ts +28 -0
- package/package.json +1 -1
- package/src/auth/controller.ts +3 -0
- package/src/auth/providers/custom-function/controller.ts +5 -2
- package/src/auth/providers/local-userpass/controller.ts +13 -10
- package/src/auth/utils.ts +7 -4
- package/src/constants.ts +7 -2
- package/src/fastify.d.ts +32 -15
- package/src/features/functions/controller.ts +36 -2
- package/src/features/rules/utils.ts +11 -2
- package/src/features/triggers/utils.ts +59 -2
- package/src/index.ts +21 -8
- package/src/services/mongodb-atlas/__tests__/utils.test.ts +141 -0
- package/src/services/mongodb-atlas/index.ts +143 -90
- package/src/services/mongodb-atlas/utils.ts +158 -22
- package/src/shared/handleUserRegistration.ts +3 -3
- package/src/shared/models/handleUserRegistration.model.ts +8 -3
- package/src/types/fastify-raw-body.d.ts +22 -0
- package/src/utils/__tests__/STEP_B_STATES.test.ts +1 -1
- package/src/utils/__tests__/STEP_C_STATES.test.ts +1 -1
- package/src/utils/__tests__/STEP_D_STATES.test.ts +2 -2
- package/src/utils/__tests__/checkIsValidFieldNameFn.test.ts +9 -4
- package/src/utils/__tests__/registerPlugins.test.ts +16 -1
- package/src/utils/context/helpers.ts +3 -0
- package/src/utils/context/index.ts +1 -0
- package/src/utils/initializer/exposeRoutes.ts +15 -8
- package/src/utils/initializer/registerPlugins.ts +15 -7
- package/src/utils/roles/helpers.ts +20 -3
- package/src/utils/roles/machines/commonValidators.ts +10 -5
- package/src/utils/roles/machines/read/B/validators.ts +8 -0
- package/src/utils/roles/machines/read/C/index.ts +11 -7
- package/src/utils/roles/machines/read/C/validators.ts +21 -0
- package/src/utils/roles/machines/read/D/index.ts +22 -12
- package/src/utils/rules.ts +31 -22
- package/tsconfig.spec.json +7 -0
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
2
|
checkFieldsPropertyExists,
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
evaluateTopLevelReadFn,
|
|
4
|
+
evaluateTopLevelWriteFn
|
|
5
|
+
} from './validators'
|
|
5
6
|
import { States } from '../../interface'
|
|
6
7
|
import { logMachineInfo } from '../../utils'
|
|
7
8
|
|
|
@@ -13,10 +14,13 @@ export const STEP_C_STATES: States = {
|
|
|
13
14
|
step: 1,
|
|
14
15
|
stepName: 'evaluateTopLevelRead'
|
|
15
16
|
})
|
|
16
|
-
const check = await
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
const check = await evaluateTopLevelReadFn(context)
|
|
18
|
+
if (check) {
|
|
19
|
+
return checkFieldsPropertyExists(context)
|
|
20
|
+
? next('checkFieldsProperty')
|
|
21
|
+
: endValidation({ success: true })
|
|
22
|
+
}
|
|
23
|
+
return next('evaluateTopLevelWrite', { check })
|
|
20
24
|
},
|
|
21
25
|
evaluateTopLevelWrite: async ({ context, next, endValidation }) => {
|
|
22
26
|
logMachineInfo({
|
|
@@ -25,7 +29,7 @@ export const STEP_C_STATES: States = {
|
|
|
25
29
|
step: 2,
|
|
26
30
|
stepName: 'evaluateTopLevelWrite'
|
|
27
31
|
})
|
|
28
|
-
const check = await
|
|
32
|
+
const check = await evaluateTopLevelWriteFn(context)
|
|
29
33
|
if (check) return endValidation({ success: true })
|
|
30
34
|
return context?.prevParams?.check === false
|
|
31
35
|
? endValidation({ success: false })
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { MachineContext } from '../../interface'
|
|
2
|
+
import {
|
|
3
|
+
checkFieldsPropertyExists,
|
|
4
|
+
evaluateTopLevelPermissionsFn
|
|
5
|
+
} from '../../commonValidators'
|
|
6
|
+
|
|
7
|
+
export const evaluateTopLevelReadFn = async (context: MachineContext) => {
|
|
8
|
+
if (context.params.type !== 'read') {
|
|
9
|
+
return false
|
|
10
|
+
}
|
|
11
|
+
return evaluateTopLevelPermissionsFn(context, 'read')
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export const evaluateTopLevelWriteFn = async (context: MachineContext) => {
|
|
15
|
+
if (!['read', 'write'].includes(context.params.type)) {
|
|
16
|
+
return undefined
|
|
17
|
+
}
|
|
18
|
+
return evaluateTopLevelPermissionsFn(context, 'write')
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export { checkFieldsPropertyExists } from '../../commonValidators'
|
|
@@ -1,7 +1,25 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Document } from 'mongodb'
|
|
2
|
+
import { MachineContext, States } from '../../interface'
|
|
2
3
|
import { logMachineInfo } from '../../utils'
|
|
3
4
|
import { checkAdditionalFieldsFn, checkIsValidFieldNameFn } from './validators'
|
|
4
5
|
|
|
6
|
+
const runCheckIsValidFieldName = async ({
|
|
7
|
+
context,
|
|
8
|
+
endValidation
|
|
9
|
+
}: {
|
|
10
|
+
context: MachineContext
|
|
11
|
+
endValidation: ({ success, document }: { success: boolean; document?: Document }) => void
|
|
12
|
+
}) => {
|
|
13
|
+
logMachineInfo({
|
|
14
|
+
enabled: context.enableLog,
|
|
15
|
+
machine: 'D',
|
|
16
|
+
step: 2,
|
|
17
|
+
stepName: 'checkIsValidFieldName'
|
|
18
|
+
})
|
|
19
|
+
const document = checkIsValidFieldNameFn(context)
|
|
20
|
+
return endValidation({ success: !!Object.keys(document).length, document })
|
|
21
|
+
}
|
|
22
|
+
|
|
5
23
|
export const STEP_D_STATES: States = {
|
|
6
24
|
checkAdditionalFields: async ({ context, next, endValidation }) => {
|
|
7
25
|
logMachineInfo({
|
|
@@ -11,16 +29,8 @@ export const STEP_D_STATES: States = {
|
|
|
11
29
|
stepName: 'checkAdditionalFields'
|
|
12
30
|
})
|
|
13
31
|
const check = checkAdditionalFieldsFn(context)
|
|
14
|
-
return check ? next('
|
|
32
|
+
return check ? next('evaluateRead') : endValidation({ success: false })
|
|
15
33
|
},
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
enabled: context.enableLog,
|
|
19
|
-
machine: 'D',
|
|
20
|
-
step: 2,
|
|
21
|
-
stepName: 'checkIsValidFieldName'
|
|
22
|
-
})
|
|
23
|
-
const document = checkIsValidFieldNameFn(context)
|
|
24
|
-
return endValidation({ success: !!Object.keys(document).length, document })
|
|
25
|
-
}
|
|
34
|
+
evaluateRead: runCheckIsValidFieldName,
|
|
35
|
+
checkIsValidFieldName: runCheckIsValidFieldName
|
|
26
36
|
}
|
package/src/utils/rules.ts
CHANGED
|
@@ -1,31 +1,40 @@
|
|
|
1
1
|
import get from 'lodash/get'
|
|
2
2
|
|
|
3
|
-
const
|
|
4
|
-
|
|
3
|
+
const resolvePlaceholder = (value: string, objs: Record<string, unknown>) => {
|
|
4
|
+
if (!value.startsWith('%%')) return value
|
|
5
|
+
|
|
6
|
+
const path = value.slice(2)
|
|
7
|
+
const [rootKey, ...rest] = path.split('.')
|
|
8
|
+
const rootToken = `%%${rootKey}`
|
|
9
|
+
const rootValue = objs[rootToken]
|
|
10
|
+
|
|
11
|
+
if (!rest.length) {
|
|
12
|
+
return rootValue === undefined ? value : rootValue
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const resolved = get(rootValue as object, rest.join('.'))
|
|
16
|
+
return resolved === undefined ? value : resolved
|
|
5
17
|
}
|
|
6
18
|
|
|
7
|
-
|
|
19
|
+
const expandValue = (input: unknown, objs: Record<string, unknown>): unknown => {
|
|
20
|
+
if (Array.isArray(input)) {
|
|
21
|
+
return input.map((item) => expandValue(item, objs))
|
|
22
|
+
}
|
|
23
|
+
if (input && typeof input === 'object') {
|
|
24
|
+
return Object.fromEntries(
|
|
25
|
+
Object.entries(input).map(([key, val]) => [key, expandValue(val, objs)])
|
|
26
|
+
)
|
|
27
|
+
}
|
|
28
|
+
if (typeof input === 'string') {
|
|
29
|
+
return resolvePlaceholder(input, objs)
|
|
30
|
+
}
|
|
31
|
+
return input
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Espande dinamicamente i placeholder con supporto per array e percorsi annidati
|
|
8
35
|
export function expandQuery(
|
|
9
36
|
template: Record<string, unknown>,
|
|
10
37
|
objs: Record<string, unknown>
|
|
11
38
|
) {
|
|
12
|
-
|
|
13
|
-
const regex = /:\s*"%%([a-zA-Z0-9_.]+)"/g
|
|
14
|
-
Object.keys(objs).forEach(() => {
|
|
15
|
-
// Espandi tutti i placeholder %%values.<nested.property>
|
|
16
|
-
|
|
17
|
-
const callback = (match: string, path: string) => {
|
|
18
|
-
const value = get(objs, `%%${path}`) // Recupera il valore annidato da values
|
|
19
|
-
const finalValue = typeof value === 'string' ? `"${value}"` : value && JSON.stringify(value)
|
|
20
|
-
// TODO tolto i primi : creava questo tipo di oggetto {"userId"::"%%user.id"}
|
|
21
|
-
const val = `:${value !== undefined ? finalValue : match}`; // Sostituisci se esiste, altrimenti lascia il placeholder
|
|
22
|
-
return removeExtraColons(val)
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
expandedQuery = expandedQuery.replace(
|
|
26
|
-
regex,
|
|
27
|
-
callback as Parameters<typeof expandedQuery.replaceAll>[1]
|
|
28
|
-
)
|
|
29
|
-
})
|
|
30
|
-
return JSON.parse(expandedQuery) // Converti la stringa JSON di nuovo in un oggetto
|
|
39
|
+
return expandValue(template, objs) as Record<string, unknown>
|
|
31
40
|
}
|