diff --git a/Cargo.lock b/Cargo.lock index 63af5ce..4bf0b5b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3101,6 +3101,18 @@ dependencies = [ "thiserror", ] +[[package]] +name = "tauri-plugin-specta-example" +version = "0.0.0" +dependencies = [ + "rand 0.8.5", + "serde", + "specta", + "tauri", + "tauri-plugin", + "tauri-specta", +] + [[package]] name = "tauri-runtime" version = "2.0.0-beta.13" @@ -3169,18 +3181,6 @@ dependencies = [ "tauri-specta", ] -[[package]] -name = "tauri-specta-example-custom-plugin" -version = "0.0.0" -dependencies = [ - "rand 0.8.5", - "serde", - "specta", - "tauri", - "tauri-plugin", - "tauri-specta", -] - [[package]] name = "tauri-specta-example-custom-plugin-app" version = "0.0.0" @@ -3189,7 +3189,7 @@ dependencies = [ "serde_json", "tauri", "tauri-build 2.0.0-beta.13 (registry+https://github.com/rust-lang/crates.io-index)", - "tauri-specta-example-custom-plugin", + "tauri-plugin-specta-example", ] [[package]] diff --git a/examples/custom-plugin/app/src-tauri/Cargo.toml b/examples/custom-plugin/app/src-tauri/Cargo.toml index f9743c6..584d758 100644 --- a/examples/custom-plugin/app/src-tauri/Cargo.toml +++ b/examples/custom-plugin/app/src-tauri/Cargo.toml @@ -14,7 +14,7 @@ tauri-build = { version = "2.0.0-beta.13", features = [] } tauri = { version = "=2.0.0-beta.16", features = [] } serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" -tauri-specta-example-custom-plugin = { path = "../../plugin" } +tauri-plugin-specta-example = { path = "../../plugin" } [features] # this feature is used for production builds or when `devPath` points to the filesystem diff --git a/examples/custom-plugin/app/src-tauri/capabilities/main.json b/examples/custom-plugin/app/src-tauri/capabilities/main.json index e3a6a39..0cb7ffa 100644 --- a/examples/custom-plugin/app/src-tauri/capabilities/main.json +++ b/examples/custom-plugin/app/src-tauri/capabilities/main.json @@ -3,5 +3,5 @@ "identifier": "main-capability", "description": "Capability for the main window", "windows": ["main"], - "permissions": ["allow-add_numbers"] + "permissions": ["event:default", "specta-example:allow-add-numbers"] } diff --git a/examples/custom-plugin/app/src-tauri/src/main.rs b/examples/custom-plugin/app/src-tauri/src/main.rs index 445fc18..3dc4dee 100644 --- a/examples/custom-plugin/app/src-tauri/src/main.rs +++ b/examples/custom-plugin/app/src-tauri/src/main.rs @@ -3,7 +3,7 @@ fn main() { tauri::Builder::default() - .plugin(tauri_specta_example_custom_plugin::init()) + .plugin(tauri_plugin_specta_example::init()) .run(tauri::generate_context!()) .expect("error while running tauri application"); } diff --git a/examples/custom-plugin/plugin/Cargo.toml b/examples/custom-plugin/plugin/Cargo.toml index 0d425f3..243560f 100644 --- a/examples/custom-plugin/plugin/Cargo.toml +++ b/examples/custom-plugin/plugin/Cargo.toml @@ -1,7 +1,8 @@ [package] -name = "tauri-specta-example-custom-plugin" +name = "tauri-plugin-specta-example" version = "0.0.0" edition = "2021" +links = "tauri-plugin-specta-example" [build-dependencies] tauri-plugin = { version = "=2.0.0-beta.13", features = ["build"] } diff --git a/examples/custom-plugin/plugin/permissions/autogenerated/commands/add_numbers.toml b/examples/custom-plugin/plugin/permissions/autogenerated/commands/add_numbers.toml new file mode 100644 index 0000000..d99cdee --- /dev/null +++ b/examples/custom-plugin/plugin/permissions/autogenerated/commands/add_numbers.toml @@ -0,0 +1,13 @@ +# Automatically generated - DO NOT EDIT! + +"$schema" = "../../schemas/schema.json" + +[[permission]] +identifier = "allow-add-numbers" +description = "Enables the add_numbers command without any pre-configured scope." +commands.allow = ["add_numbers"] + +[[permission]] +identifier = "deny-add-numbers" +description = "Denies the add_numbers command without any pre-configured scope." +commands.deny = ["add_numbers"] diff --git a/examples/custom-plugin/plugin/permissions/autogenerated/reference.md b/examples/custom-plugin/plugin/permissions/autogenerated/reference.md new file mode 100644 index 0000000..172e6c9 --- /dev/null +++ b/examples/custom-plugin/plugin/permissions/autogenerated/reference.md @@ -0,0 +1,4 @@ +| Permission | Description | +|------|-----| +|`allow-add-numbers`|Enables the add_numbers command without any pre-configured scope.| +|`deny-add-numbers`|Denies the add_numbers command without any pre-configured scope.| diff --git a/examples/custom-plugin/plugin/permissions/schemas/schema.json b/examples/custom-plugin/plugin/permissions/schemas/schema.json new file mode 100644 index 0000000..7695941 --- /dev/null +++ b/examples/custom-plugin/plugin/permissions/schemas/schema.json @@ -0,0 +1,314 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "PermissionFile", + "description": "Permission file that can define a default permission, a set of permissions or a list of inlined permissions.", + "type": "object", + "properties": { + "default": { + "description": "The default permission set for the plugin", + "anyOf": [ + { + "$ref": "#/definitions/DefaultPermission" + }, + { + "type": "null" + } + ] + }, + "set": { + "description": "A list of permissions sets defined", + "type": "array", + "items": { + "$ref": "#/definitions/PermissionSet" + } + }, + "permission": { + "description": "A list of inlined permissions", + "default": [], + "type": "array", + "items": { + "$ref": "#/definitions/Permission" + } + } + }, + "definitions": { + "DefaultPermission": { + "description": "The default permission set of the plugin.\n\nWorks similarly to a permission with the \"default\" identifier.", + "type": "object", + "required": [ + "permissions" + ], + "properties": { + "version": { + "description": "The version of the permission.", + "type": [ + "integer", + "null" + ], + "format": "uint64", + "minimum": 1.0 + }, + "description": { + "description": "Human-readable description of what the permission does.", + "type": [ + "string", + "null" + ] + }, + "permissions": { + "description": "All permissions this set contains.", + "type": "array", + "items": { + "type": "string" + } + } + } + }, + "PermissionSet": { + "description": "A set of direct permissions grouped together under a new name.", + "type": "object", + "required": [ + "description", + "identifier", + "permissions" + ], + "properties": { + "identifier": { + "description": "A unique identifier for the permission.", + "type": "string" + }, + "description": { + "description": "Human-readable description of what the permission does.", + "type": "string" + }, + "permissions": { + "description": "All permissions this set contains.", + "type": "array", + "items": { + "$ref": "#/definitions/PermissionKind" + } + } + } + }, + "Permission": { + "description": "Descriptions of explicit privileges of commands.\n\nIt can enable commands to be accessible in the frontend of the application.\n\nIf the scope is defined it can be used to fine grain control the access of individual or multiple commands.", + "type": "object", + "required": [ + "identifier" + ], + "properties": { + "version": { + "description": "The version of the permission.", + "type": [ + "integer", + "null" + ], + "format": "uint64", + "minimum": 1.0 + }, + "identifier": { + "description": "A unique identifier for the permission.", + "type": "string" + }, + "description": { + "description": "Human-readable description of what the permission does.", + "type": [ + "string", + "null" + ] + }, + "commands": { + "description": "Allowed or denied commands when using this permission.", + "default": { + "allow": [], + "deny": [] + }, + "allOf": [ + { + "$ref": "#/definitions/Commands" + } + ] + }, + "scope": { + "description": "Allowed or denied scoped when using this permission.", + "allOf": [ + { + "$ref": "#/definitions/Scopes" + } + ] + }, + "platforms": { + "description": "Target platforms this permission applies. By default all platforms are affected by this permission.", + "type": [ + "array", + "null" + ], + "items": { + "$ref": "#/definitions/Target" + } + } + } + }, + "Commands": { + "description": "Allowed and denied commands inside a permission.\n\nIf two commands clash inside of `allow` and `deny`, it should be denied by default.", + "type": "object", + "properties": { + "allow": { + "description": "Allowed command.", + "default": [], + "type": "array", + "items": { + "type": "string" + } + }, + "deny": { + "description": "Denied command, which takes priority.", + "default": [], + "type": "array", + "items": { + "type": "string" + } + } + } + }, + "Scopes": { + "description": "A restriction of the command/endpoint functionality.\n\nIt can be of any serde serializable type and is used for allowing or preventing certain actions inside a Tauri command.\n\nThe scope is passed to the command and handled/enforced by the command itself.", + "type": "object", + "properties": { + "allow": { + "description": "Data that defines what is allowed by the scope.", + "type": [ + "array", + "null" + ], + "items": { + "$ref": "#/definitions/Value" + } + }, + "deny": { + "description": "Data that defines what is denied by the scope.", + "type": [ + "array", + "null" + ], + "items": { + "$ref": "#/definitions/Value" + } + } + } + }, + "Value": { + "description": "All supported ACL values.", + "anyOf": [ + { + "description": "Represents a null JSON value.", + "type": "null" + }, + { + "description": "Represents a [`bool`].", + "type": "boolean" + }, + { + "description": "Represents a valid ACL [`Number`].", + "allOf": [ + { + "$ref": "#/definitions/Number" + } + ] + }, + { + "description": "Represents a [`String`].", + "type": "string" + }, + { + "description": "Represents a list of other [`Value`]s.", + "type": "array", + "items": { + "$ref": "#/definitions/Value" + } + }, + { + "description": "Represents a map of [`String`] keys to [`Value`]s.", + "type": "object", + "additionalProperties": { + "$ref": "#/definitions/Value" + } + } + ] + }, + "Number": { + "description": "A valid ACL number.", + "anyOf": [ + { + "description": "Represents an [`i64`].", + "type": "integer", + "format": "int64" + }, + { + "description": "Represents a [`f64`].", + "type": "number", + "format": "double" + } + ] + }, + "Target": { + "description": "Platform target.", + "oneOf": [ + { + "description": "MacOS.", + "type": "string", + "enum": [ + "macOS" + ] + }, + { + "description": "Windows.", + "type": "string", + "enum": [ + "windows" + ] + }, + { + "description": "Linux.", + "type": "string", + "enum": [ + "linux" + ] + }, + { + "description": "Android.", + "type": "string", + "enum": [ + "android" + ] + }, + { + "description": "iOS.", + "type": "string", + "enum": [ + "iOS" + ] + } + ] + }, + "PermissionKind": { + "type": "string", + "oneOf": [ + { + "description": "allow-add-numbers -> Enables the add_numbers command without any pre-configured scope.", + "type": "string", + "enum": [ + "allow-add-numbers" + ] + }, + { + "description": "deny-add-numbers -> Denies the add_numbers command without any pre-configured scope.", + "type": "string", + "enum": [ + "deny-add-numbers" + ] + } + ] + } + } +} \ No newline at end of file