Files
metabuilder/packages/shared/seed/script_v2.json
2025-12-31 12:55:42 +00:00

277 lines
7.6 KiB
JSON

{
"schema_version": "2.0.0",
"package": "shared",
"description": "Shared package scripts - permissions and utilities",
"functions": [
{
"id": "check_access",
"name": "check_access",
"async": false,
"exported": true,
"params": [
{
"name": "userLevel",
"type": "number",
"description": "Current user's permission level (0-6)"
},
{
"name": "permissions",
"type": "object",
"description": "Permission requirements"
},
{
"name": "featureFlags",
"type": "table",
"optional": true,
"default": {}
},
{
"name": "databaseEnabled",
"type": "boolean",
"optional": true,
"default": true
}
],
"returnType": "PermissionCheckResult",
"body": [
{
"type": "comment",
"text": "Default feature flags and database state"
},
{
"type": "if_statement",
"condition": {
"type": "binary_expression",
"left": "$ref:params.featureFlags",
"operator": "==",
"right": null
},
"then": [
{
"type": "assignment",
"target": "$ref:params.featureFlags",
"value": {
"type": "object_literal",
"properties": {}
}
}
]
},
{
"type": "if_statement",
"condition": {
"type": "binary_expression",
"left": "$ref:params.databaseEnabled",
"operator": "==",
"right": false
},
"then": [
{
"type": "assignment",
"target": "$ref:params.databaseEnabled",
"value": true
}
]
},
{
"type": "comment",
"text": "Check if resource is enabled"
},
{
"type": "if_statement",
"condition": {
"type": "binary_expression",
"left": {
"type": "member_access",
"object": "$ref:params.permissions",
"property": "enabled"
},
"operator": "===",
"right": false
},
"then": [
{
"type": "return",
"value": {
"type": "object_literal",
"properties": {
"allowed": false,
"reason": "Resource is currently disabled"
}
}
}
]
},
{
"type": "comment",
"text": "Check minimum permission level"
},
{
"type": "const_declaration",
"name": "minLevel",
"value": {
"type": "logical_expression",
"left": {
"type": "member_access",
"object": "$ref:params.permissions",
"property": "minLevel"
},
"operator": "||",
"right": 0
}
},
{
"type": "if_statement",
"condition": {
"type": "binary_expression",
"left": "$ref:params.userLevel",
"operator": "<",
"right": "$ref:local.minLevel"
},
"then": [
{
"type": "return",
"value": {
"type": "object_literal",
"properties": {
"allowed": false,
"reason": "Insufficient permission level",
"requiredLevel": "$ref:local.minLevel"
}
}
}
]
},
{
"type": "comment",
"text": "Check database requirement"
},
{
"type": "if_statement",
"condition": {
"type": "logical_expression",
"left": {
"type": "member_access",
"object": "$ref:params.permissions",
"property": "databaseRequired"
},
"operator": "&&",
"right": {
"type": "unary_expression",
"operator": "!",
"argument": "$ref:params.databaseEnabled"
}
},
"then": [
{
"type": "return",
"value": {
"type": "object_literal",
"properties": {
"allowed": false,
"reason": "Database is required but not enabled"
}
}
}
]
},
{
"type": "if_statement",
"condition": {
"type": "logical_expression",
"left": {
"type": "member_access",
"object": "$ref:params.permissions",
"property": "requireDatabase"
},
"operator": "&&",
"right": {
"type": "unary_expression",
"operator": "!",
"argument": "$ref:params.databaseEnabled"
}
},
"then": [
{
"type": "return",
"value": {
"type": "object_literal",
"properties": {
"allowed": false,
"reason": "Database is required but not enabled"
}
}
}
]
},
{
"type": "comment",
"text": "Check feature flags (only if specified)"
},
{
"type": "if_statement",
"condition": {
"type": "member_access",
"object": "$ref:params.permissions",
"property": "featureFlags"
},
"then": [
{
"type": "for_each_loop",
"iterator": "flag",
"iterable": {
"type": "member_access",
"object": "$ref:params.permissions",
"property": "featureFlags"
},
"body": [
{
"type": "if_statement",
"condition": {
"type": "unary_expression",
"operator": "!",
"argument": {
"type": "member_access",
"object": "$ref:params.featureFlags",
"property": "$ref:local.flag"
}
},
"then": [
{
"type": "return",
"value": {
"type": "object_literal",
"properties": {
"allowed": false,
"reason": {
"type": "template_literal",
"template": "Required feature flag '${flag}' is not enabled"
}
}
}
}
]
}
]
}
]
},
{
"type": "comment",
"text": "All checks passed"
},
{
"type": "return",
"value": {
"type": "object_literal",
"properties": {
"allowed": true
}
}
}
]
}
]
}