2024-02-27 16:50:48 +00:00
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
|
2024-03-06 15:42:04 +00:00
|
|
|
use crate::{config::Config, webhooks::WebhookManifest};
|
2024-02-27 16:50:48 +00:00
|
|
|
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
|
|
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
|
|
|
|
pub enum AppPermission {
|
|
|
|
ManageUsers,
|
|
|
|
ManageStaff,
|
|
|
|
ImpersonateUser,
|
|
|
|
ManageObservability,
|
|
|
|
ManageCheckouts,
|
|
|
|
HandleCheckouts,
|
|
|
|
HandleTaxes,
|
|
|
|
ManageTaxes,
|
|
|
|
ManageChannels,
|
|
|
|
ManageDiscounts,
|
|
|
|
ManageGiftCard,
|
|
|
|
ManageMenus,
|
|
|
|
ManageOrders,
|
2024-03-11 13:11:47 +00:00
|
|
|
ManageOrdersImport,
|
2024-02-27 16:50:48 +00:00
|
|
|
ManagePages,
|
|
|
|
ManagePageTypesAndAttributes,
|
|
|
|
HandlePayments,
|
|
|
|
ManagePlugins,
|
|
|
|
ManageProducts,
|
|
|
|
ManageProductTypesAndAttributes,
|
|
|
|
ManageShipping,
|
|
|
|
ManageSettings,
|
|
|
|
ManageTranslations,
|
|
|
|
ManageApps,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
|
|
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
|
|
|
|
pub enum AppExtensionMount {
|
|
|
|
ProductDetailsMoreActions,
|
|
|
|
ProductOverviewCreate,
|
|
|
|
ProductOverviewMoreActions,
|
|
|
|
NavigationCatalog,
|
|
|
|
NavigationOrders,
|
|
|
|
NavigationCustomers,
|
|
|
|
NavigationDiscounts,
|
|
|
|
NavigationTranslations,
|
|
|
|
NavigationPages,
|
|
|
|
OrderDetailsMoreActions,
|
|
|
|
OrderOverviewCreate,
|
|
|
|
OrderOverviewMoreActions,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
|
|
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
|
|
|
|
pub enum AppExtensionTarget {
|
|
|
|
Popup,
|
|
|
|
AppPage,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub struct AppExtension {
|
|
|
|
/** Name which will be displayed in the dashboard */
|
|
|
|
pub label: String,
|
|
|
|
/** the place where the extension will be mounted */
|
|
|
|
pub mount: AppExtensionMount,
|
|
|
|
/** Method of presenting the interface
|
|
|
|
`POPUP` will present the interface in a modal overlay
|
|
|
|
`APP_PAGE` will navigate to the application page
|
|
|
|
@default `POPUP`
|
|
|
|
*/
|
|
|
|
pub target: AppExtensionTarget,
|
|
|
|
pub permissions: Vec<AppPermission>,
|
|
|
|
/** URL of the view to display,
|
|
|
|
you can skip the domain and protocol when target is set to `APP_PAGE`, or when your manifest defines an `appUrl`.
|
|
|
|
|
|
|
|
When target is set to `POPUP`, the url will be used to render an `<iframe>`.
|
|
|
|
*/
|
|
|
|
pub url: String,
|
|
|
|
}
|
|
|
|
|
2024-03-06 15:42:04 +00:00
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
|
2024-02-27 16:50:48 +00:00
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub struct AppManifest {
|
|
|
|
/** ID of the application used internally by Saleor */
|
|
|
|
pub id: String,
|
|
|
|
pub version: String,
|
|
|
|
/** App's name displayed in the dashboard */
|
|
|
|
pub name: String,
|
|
|
|
/** Description of the app displayed in the dashboard */
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
|
|
pub about: Option<String>,
|
|
|
|
/** Array of permissions requested by the app */
|
|
|
|
pub permissions: Vec<AppPermission>,
|
|
|
|
/** App website rendered in the dashboard */
|
|
|
|
pub app_url: String,
|
|
|
|
/** Address to the app configuration page, which is rendered in the dashboard
|
|
|
|
@deprecated in Saleor 3.5, use appUrl instead
|
|
|
|
*/
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
|
|
pub configuration_url: Option<String>,
|
|
|
|
/** Endpoint used during process of app installation
|
|
|
|
|
|
|
|
@see [Installing an app](https://docs.saleor.io/docs/3.x/developer/extending/apps/installing-apps#installing-an-app)
|
|
|
|
*/
|
|
|
|
pub token_target_url: String,
|
|
|
|
/** Short description of privacy policy displayed in the dashboard
|
|
|
|
|
|
|
|
@deprecated in Saleor 3.5, use dataPrivacyUrl instead
|
|
|
|
*/
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
|
|
pub data_privacy: Option<String>,
|
|
|
|
/** URL to the full privacy policy */
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
|
|
pub data_privacy_url: Option<String>,
|
|
|
|
/** External URL to the app homepage */
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
|
|
pub homepage_url: Option<String>,
|
|
|
|
/** External URL to the page where app users can find support */
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
|
|
pub support_url: Option<String>,
|
|
|
|
/** List of extensions that will be mounted in Saleor's dashboard
|
|
|
|
|
|
|
|
@see For details, please see the [extension section](https://docs.saleor.io/docs/3.x/developer/extending/apps/extending-dashboard-with-apps#key-concepts)
|
|
|
|
*/
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
|
|
pub extensions: Option<Vec<AppExtension>>,
|
|
|
|
/** List of webhooks that will be set.
|
|
|
|
|
|
|
|
@see For details, please look at [asynchronous webhooks](https://docs.saleor.io/docs/3.x/developer/extending/apps/asynchronous-webhooks),
|
|
|
|
[synchronous-webhooks](https://docs.saleor.io/docs/3.x/developer/extending/apps/synchronous-webhooks/key-concepts)
|
|
|
|
and [webhooks' subscription](https://docs.saleor.io/docs/3.x/developer/extending/apps/subscription-webhook-payloads)
|
|
|
|
|
|
|
|
Be aware that subscription queries are required in manifest sections
|
|
|
|
*/
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
|
|
pub webhooks: Option<Vec<WebhookManifest>>,
|
|
|
|
/**
|
2024-07-15 14:02:51 +00:00
|
|
|
Allows app installation for specific Saleor versions, using semver.
|
|
|
|
https://github.com/npm/node-semver#versions
|
|
|
|
|
|
|
|
If not set, Saleor will allow installation for every version
|
|
|
|
|
|
|
|
In Saleor versions lower than 3.13, this field will be ignored
|
|
|
|
|
|
|
|
Examples:
|
|
|
|
">=3.10" - allow for versions 3.10 or newer
|
|
|
|
">=3.10 <4" - allow for versions 3.10 and newer, but not 4.0 and newer
|
|
|
|
">=3.10 <4 || 4.0.0" - 3.10 and newer, less than 4, but allow exactly 4.0.0
|
|
|
|
*/
|
2024-02-27 16:50:48 +00:00
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
|
|
pub required_saleor_version: Option<String>,
|
|
|
|
/**
|
2024-07-15 14:02:51 +00:00
|
|
|
App author name displayed in the dashboard
|
|
|
|
|
|
|
|
In Saleor versions lower than 3.13, this field will be ignored
|
|
|
|
*/
|
2024-02-27 16:50:48 +00:00
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
|
|
pub author: Option<String>,
|
|
|
|
/**
|
2024-07-15 14:02:51 +00:00
|
|
|
Add brand-specific metadata to the app
|
|
|
|
|
|
|
|
Available from Saleor 3.15. In previous versions will be ignored
|
|
|
|
*/
|
2024-02-27 16:50:48 +00:00
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
|
|
pub brand: Option<SaleorAppBranding>,
|
|
|
|
}
|
2024-03-06 15:42:04 +00:00
|
|
|
|
|
|
|
pub struct AppManifestBuilder {
|
|
|
|
pub manifest: AppManifest,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl AppManifestBuilder {
|
|
|
|
/**
|
2024-07-15 14:02:51 +00:00
|
|
|
to simply create a webhook manifest, you can use WebhookManifest::new()
|
|
|
|
*/
|
2024-03-06 15:42:04 +00:00
|
|
|
pub fn add_webhook(mut self, webhook: WebhookManifest) -> Self {
|
|
|
|
if let Some(webhooks) = &mut self.manifest.webhooks {
|
|
|
|
webhooks.push(webhook)
|
|
|
|
} else {
|
|
|
|
self.manifest.webhooks = Some(vec![webhook]);
|
|
|
|
}
|
|
|
|
self
|
|
|
|
}
|
|
|
|
pub fn add_permission(mut self, permissions: AppPermission) -> Self {
|
|
|
|
self.manifest.permissions.push(permissions);
|
|
|
|
self
|
|
|
|
}
|
|
|
|
pub fn add_permissions(mut self, mut permissions: Vec<AppPermission>) -> Self {
|
|
|
|
self.manifest.permissions.append(&mut permissions);
|
|
|
|
self
|
|
|
|
}
|
|
|
|
pub fn build(self) -> AppManifest {
|
|
|
|
self.manifest
|
|
|
|
}
|
|
|
|
}
|
2024-03-21 15:21:01 +00:00
|
|
|
pub struct CargoInfo {
|
|
|
|
pub name: String,
|
|
|
|
pub description: String,
|
|
|
|
pub authors: String,
|
|
|
|
pub version: String,
|
|
|
|
pub homepage: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! cargo_info {
|
|
|
|
() => {
|
|
|
|
saleor_app_sdk::manifest::CargoInfo {
|
|
|
|
name: env!("CARGO_PKG_NAME").to_owned(),
|
|
|
|
description: env!("CARGO_PKG_DESCRIPTION").to_owned(),
|
|
|
|
authors: env!("CARGO_PKG_AUTHORS").to_owned(),
|
|
|
|
version: env!("CARGO_PKG_VERSION").to_owned(),
|
|
|
|
homepage: env!("CARGO_PKG_HOMEPAGE").to_owned(),
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
2024-03-06 15:42:04 +00:00
|
|
|
|
2024-03-21 15:21:01 +00:00
|
|
|
pub use cargo_info;
|
2024-04-03 17:47:23 +00:00
|
|
|
impl AppManifestBuilder {
|
2024-03-06 15:42:04 +00:00
|
|
|
/**
|
2024-07-15 14:02:51 +00:00
|
|
|
Builder for AppManifest
|
|
|
|
|
|
|
|
Takes these out of config:
|
|
|
|
- Takes fields id, saleor_version, logo, token_target_url
|
|
|
|
|
|
|
|
And these out of the environment:
|
|
|
|
- name(CARGO_PKG_NAME), about(CARGO_PKG_DESCRIPTION), author(CARGO_PKG_AUTHORS),
|
|
|
|
|
|
|
|
version(CARGO_PKG_VERSION), homepage_url(CARGO_PKG_HOMEPAGE)
|
|
|
|
|
|
|
|
To set webhooks and permissions use the add_webhook() and add_permissions()
|
|
|
|
|
|
|
|
*/
|
2024-04-03 17:47:23 +00:00
|
|
|
pub fn new(config: &Config, info: CargoInfo) -> Self {
|
2024-03-06 15:42:04 +00:00
|
|
|
AppManifestBuilder {
|
|
|
|
manifest: AppManifest {
|
2024-03-21 15:21:01 +00:00
|
|
|
id: info.name.clone(),
|
2024-03-06 15:42:04 +00:00
|
|
|
required_saleor_version: Some(config.required_saleor_version.clone()),
|
2024-03-21 15:21:01 +00:00
|
|
|
name: info.name,
|
|
|
|
about: Some(info.description),
|
|
|
|
author: Some(info.authors),
|
|
|
|
version: info.version,
|
2024-03-06 15:42:04 +00:00
|
|
|
app_url: config.app_api_base_url.clone(),
|
|
|
|
configuration_url: Some(config.app_api_base_url.clone()),
|
|
|
|
token_target_url: format!("{}/api/register", config.app_api_base_url.clone()),
|
|
|
|
permissions: vec![],
|
2024-03-21 15:21:01 +00:00
|
|
|
homepage_url: Some(info.homepage.clone()),
|
|
|
|
data_privacy_url: Some(info.homepage.clone()),
|
|
|
|
support_url: Some(info.homepage.clone()),
|
2024-03-06 15:42:04 +00:00
|
|
|
brand: Some(SaleorAppBranding {
|
|
|
|
logo: SaleorAppBrandingDefault {
|
|
|
|
default: format!("{}/logo.png", config.app_api_base_url),
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
..Default::default()
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-02-27 16:50:48 +00:00
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub struct SaleorAppBranding {
|
|
|
|
pub logo: SaleorAppBrandingDefault,
|
|
|
|
}
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub struct SaleorAppBrandingDefault {
|
|
|
|
pub default: String,
|
|
|
|
}
|