Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Extend extensions API (#17813)

Lukasz Ostrowskib546041c458c
diff --git a/CHANGELOG.md b/CHANGELOG.md
index b9d315b0ca..69d3d1768c 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -32,6 +32,7 @@ All notable, unreleased changes to this project will be documented in this file.
- Stripe Plugin has been deprecated. It will be removed in the future. Please use [the Stripe App](https://docs.saleor.io/developer/app-store/apps/stripe/overview) instead
- App Extensions: Added new allowed extension target: NEW_TAB. Once handled in the Dashboard, an extension will be able to open a link in new tab
- App Extensions: New mount points for Dashboard categories, collections, gift cards, draft orders, discounts, vouchers, pages, pages types and menus
+- App Extensions: Now mount point types have been added, meant to be used as widgets. Additionally, a new target `WIDGET` has been added. For `NEW_TAB` and `WIDGET` targets, new field `options`. See [docs](todo) to learn more
- Changed logging settings of failed requests to reduce logs amount in production:
- Downgraded the "A query had an error" log from INFO to DEBUG level.
diff --git a/saleor/app/installation_utils.py b/saleor/app/installation_utils.py
index 0651209bcd..aadf392d3d 100644
--- a/saleor/app/installation_utils.py
+++ b/saleor/app/installation_utils.py
@@ -231,12 +231,35 @@ def install_app(app_installation: AppInstallation, activate: bool = False):
app.permissions.set(app_installation.permissions.all())
for extension_data in manifest_data.get("extensions", []):
+ # Manifest is already "clean" so values are snake case
+ options = extension_data.get("options", {})
+ new_tab_target = options.get("new_tab_target")
+ widget_target = options.get("widget_target")
+
+ # Ensure proper extraction of the method values from the options
+ http_target_method = None
+
+ if (
+ new_tab_target
+ and isinstance(new_tab_target, dict)
+ and "method" in new_tab_target
+ ):
+ http_target_method = new_tab_target["method"]
+
+ if (
+ widget_target
+ and isinstance(widget_target, dict)
+ and "method" in widget_target
+ ):
+ http_target_method = widget_target["method"]
+
extension = AppExtension.objects.create(
app=app,
label=extension_data.get("label"),
url=extension_data.get("url"),
mount=extension_data.get("mount"),
target=extension_data.get("target", AppExtensionTarget.POPUP),
+ http_target_method=http_target_method,
)
extension.permissions.set(extension_data.get("permissions", []))
diff --git a/saleor/app/manifest_validations.py b/saleor/app/manifest_validations.py
index bc1e0258bd..31eeaffc70 100644
--- a/saleor/app/manifest_validations.py
+++ b/saleor/app/manifest_validations.py
@@ -1,10 +1,13 @@
import logging
from collections import defaultdict
from collections.abc import Iterable
+from urllib.parse import urlparse
+from django.conf import settings
from django.core.exceptions import ValidationError
from django.db.models import Value
from django.db.models.functions import Concat
+from pydantic import ValidationError as PydanticValidationError
from semantic_version import NpmSpec, Version
from semantic_version.base import Range
@@ -22,7 +25,7 @@ from ..webhook.validators import custom_headers_validator
from .error_codes import AppErrorCode
from .models import App
from .types import AppExtensionMount, AppExtensionTarget
-from .validators import AppURLValidator, brand_validator
+from .validators import AppExtensionOptions, AppURLValidator, brand_validator
logger = logging.getLogger(__name__)
@@ -71,12 +74,38 @@ def _clean_extension_url(extension: dict, manifest_data: dict):
"""
extension_url = extension["url"]
target = extension.get("target") or AppExtensionTarget.POPUP
+
+ # Assume app URL is the one that originally received the token.
+ app_url = manifest_data.get("tokenTargetUrl")
+
+ new_tab_method_post = (
+ extension.get("options", {}).get("newTabTarget", {}).get("method") == "POST"
+ )
+ widget_method_post = (
+ extension.get("options", {}).get("widgetTarget", {}).get("method") == "POST"
+ )
+
+ if not app_url:
+ raise ValidationError("Manifest is invalid, token_target_url is missing")
+
if extension_url.startswith("/"):
_clean_extension_url_with_only_path(manifest_data, target, extension_url)
elif target == AppExtensionTarget.APP_PAGE:
msg = "Url cannot start with protocol when target == APP_PAGE"
logger.warning(msg)
raise ValidationError(msg)
+ elif (target == AppExtensionTarget.NEW_TAB and new_tab_method_post) or (
+ target == AppExtensionTarget.WIDGET and widget_method_post
+ ):
+ parsed_app_url = urlparse(app_url)
+ parsed_extension_url = urlparse(extension_url)
+
+ if parsed_extension_url.scheme != "https" and settings.ENABLE_SSL:
+ raise ValidationError("Extension must start with https")
+
+ if parsed_app_url.hostname != parsed_extension_url.hostname:
+ raise ValidationError("Extension URL must match App URL")
+
else:
_clean_app_url(extension_url)
@@ -206,8 +235,42 @@ def _clean_extension_enum_field(enum, field_name, extension, errors):
)
+def _clean_extension_options(extension, errors):
+ """Validate the options field in an extension."""
+ options = extension.get("options", {})
+ try:
+ validated_options = AppExtensionOptions.model_validate(options)
+
+ if (
+ validated_options.widget_target
+ and extension.get("target") != AppExtensionTarget.WIDGET
+ ):
+ raise ValidationError(
+ "widgetTarget options must be set only on WIDGET target"
+ )
+
+ if (
+ validated_options.new_tab_target
+ and extension.get("target") != AppExtensionTarget.NEW_TAB
+ ):
+ raise ValidationError(
+ "newTabTarget options must be set only on NEW_TAB target"
+ )
+
+ # Update the extension with the validated options
+ extension["options"] = validated_options.model_dump(exclude_none=True)
+ except (ValidationError, PydanticValidationError) as e:
+ errors["extensions"].append(
+ ValidationError(
+ f"Invalid options field: {str(e)}",
+ code=AppErrorCode.INVALID.value,
+ )
+ )
+
+
def _clean_extensions(manifest_data, app_permissions, errors):
extensions = manifest_data.get("extensions", [])
+
for extension in extensions:
if "target" not in extension:
extension["target"] = AppExtensionTarget.POPUP
@@ -228,6 +291,8 @@ def _clean_extensions(manifest_data, app_permissions, errors):
_clean_extension_permissions(extension, app_permissions, errors)
+ _clean_extension_options(extension, errors)
+
def _clean_webhooks(manifest_data, errors):
webhooks = manifest_data.get("webhooks", [])
diff --git a/saleor/app/migrations/0032_appextension_http_target_method_and_more.py b/saleor/app/migrations/0032_appextension_http_target_method_and_more.py
new file mode 100644
index 0000000000..7e54af95c9
--- /dev/null
+++ b/saleor/app/migrations/0032_appextension_http_target_method_and_more.py
@@ -0,0 +1,124 @@
+# Generated by Django 5.2.1 on 2025-06-13 10:02
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+ dependencies = [
+ ("app", "0031_alter_appextension_mount_alter_appextension_target"),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name="appextension",
+ name="http_target_method",
+ field=models.CharField(
+ choices=[("GET", "GET"), ("POST", "POST")], null=True
+ ),
+ ),
+ migrations.AlterField(
+ model_name="appextension",
+ name="mount",
+ field=models.CharField(
+ choices=[
+ ("category_overview_create", "category_overview_create"),
+ (
+ "category_overview_more_actions",
+ "category_overview_more_actions",
+ ),
+ ("category_details_more_actions", "category_details_more_actions"),
+ ("collection_overview_create", "collection_overview_create"),
+ (
+ "collection_overview_more_actions",
+ "collection_overview_more_actions",
+ ),
+ (
+ "collection_details_more_actions",
+ "collection_details_more_actions",
+ ),
+ ("collection_details_widgets", "collection_details_widgets"),
+ ("gift_card_overview_create", "gift_card_overview_create"),
+ (
+ "gift_card_overview_more_actions",
+ "gift_card_overview_more_actions",
+ ),
+ (
+ "gift_card_details_more_actions",
+ "gift_card_details_more_actions",
+ ),
+ ("gift_card_details_widgets", "gift_card_details_widgets"),
+ ("customer_overview_create", "customer_overview_create"),
+ (
+ "customer_overview_more_actions",
+ "customer_overview_more_actions",
+ ),
+ ("customer_details_more_actions", "customer_details_more_actions"),
+ ("customer_details_widgets", "customer_details_widgets"),
+ ("product_overview_create", "product_overview_create"),
+ ("product_overview_more_actions", "product_overview_more_actions"),
+ ("product_details_more_actions", "product_details_more_actions"),
+ ("product_details_widgets", "product_details_widgets"),
+ ("navigation_catalog", "navigation_catalog"),
+ ("navigation_orders", "navigation_orders"),
+ ("navigation_customers", "navigation_customers"),
+ ("navigation_discounts", "navigation_discounts"),
+ ("navigation_translations", "navigation_translations"),
+ ("navigation_pages", "navigation_pages"),
+ ("order_details_more_actions", "order_details_more_actions"),
+ ("order_overview_create", "order_overview_create"),
+ ("order_overview_more_actions", "order_overview_more_actions"),
+ ("order_details_widgets", "order_details_widgets"),
+ (
+ "draft_order_details_more_actions",
+ "draft_order_details_more_actions",
+ ),
+ ("draft_order_overview_create", "draft_order_overview_create"),
+ (
+ "draft_order_overview_more_actions",
+ "draft_order_overview_more_actions",
+ ),
+ ("draft_order_details_widgets", "draft_order_details_widgets"),
+ ("discount_details_more_actions", "discount_details_more_actions"),
+ ("discount_overview_create", "discount_overview_create"),
+ (
+ "discount_overview_more_actions",
+ "discount_overview_more_actions",
+ ),
+ ("voucher_details_more_actions", "voucher_details_more_actions"),
+ ("voucher_overview_create", "voucher_overview_create"),
+ ("voucher_overview_more_actions", "voucher_overview_more_actions"),
+ ("voucher_details_widgets", "voucher_details_widgets"),
+ ("page_details_more_actions", "page_details_more_actions"),
+ ("page_overview_create", "page_overview_create"),
+ ("page_overview_more_actions", "page_overview_more_actions"),
+ ("page_type_overview_create", "page_type_overview_create"),
+ (
+ "page_type_overview_more_actions",
+ "page_type_overview_more_actions",
+ ),
+ (
+ "page_type_details_more_actions",
+ "page_type_details_more_actions",
+ ),
+ ("menu_overview_create", "menu_overview_create"),
+ ("menu_overview_more_actions", "menu_overview_more_actions"),
+ ("menu_details_more_actions", "menu_details_more_actions"),
+ ],
+ max_length=256,
+ ),
+ ),
+ migrations.AlterField(
+ model_name="appextension",
+ name="target",
+ field=models.CharField(
+ choices=[
+ ("popup", "popup"),
+ ("app_page", "app_page"),
+ ("new_tab", "new_tab"),
+ ("widget", "widget"),
+ ],
+ default="popup",
+ max_length=128,
+ ),
+ ),
+ ]
diff --git a/saleor/app/models.py b/saleor/app/models.py
index e153ba708f..c560428a45 100644
--- a/saleor/app/models.py
+++ b/saleor/app/models.py
@@ -11,7 +11,12 @@ from ..core.models import Job, ModelWithMetadata
from ..permission.enums import AppPermission, BasePermissionEnum
from ..permission.models import Permission
from ..webhook.event_types import WebhookEventAsyncType, WebhookEventSyncType
-from .types import AppExtensionMount, AppExtensionTarget, AppType
+from .types import (
+ AppExtensionHttpMethod,
+ AppExtensionMount,
+ AppExtensionTarget,
+ AppType,
+)
class AppQueryset(models.QuerySet["App"]):
@@ -163,6 +168,11 @@ class AppExtension(models.Model):
blank=True,
help_text="Specific permissions for this app extension.",
)
+ http_target_method = models.CharField(
+ blank=False,
+ null=True,
+ choices=AppExtensionHttpMethod.CHOICES,
+ )
class AppInstallation(Job):
diff --git a/saleor/app/tests/test_installation_utils.py b/saleor/app/tests/test_installation_utils.py
index ceb438e01f..6c74d292db 100644
--- a/saleor/app/tests/test_installation_utils.py
+++ b/saleor/app/tests/test_installation_utils.py
@@ -274,6 +274,7 @@ def test_install_app_with_extension(
# given
label = "Create product with app"
url = "http://127.0.0.1:8080/app-extension"
+ options: dict = {}
app_manifest["permissions"] = ["MANAGE_PRODUCTS", "MANAGE_ORDERS"]
app_manifest["extensions"] = [
{
@@ -281,6 +282,7 @@ def test_install_app_with_extension(
"url": url,
"mount": "PRODUCT_OVERVIEW_CREATE",
"permissions": ["MANAGE_PRODUCTS"],
+ "options": options,
}
]
mocked_get_response = Mock()
@@ -305,6 +307,55 @@ def test_install_app_with_extension(
assert app_extension.mount == AppExtensionMount.PRODUCT_OVERVIEW_CREATE
assert app_extension.target == AppExtensionTarget.POPUP
assert list(app_extension.permissions.all()) == [permission_manage_products]
+ assert app_extension.http_target_method is None
+
+
+def test_install_app_with_extension_widget(
+ app_manifest,
+ app_installation,
+ monkeypatch,
+ permission_manage_products,
+ permission_manage_orders,
+):
+ # given
+ label = "Create product with app"
+ url = "https://example.com/app-extension"
+ options = {"widgetTarget": {"method": "POST"}}
+ app_manifest["permissions"] = ["MANAGE_PRODUCTS", "MANAGE_ORDERS"]
+ app_manifest["tokenTargetUrl"] = "https://example.com/install"
+ app_manifest["extensions"] = [
+ {
+ "label": label,
+ "url": url,
+ "mount": "PRODUCT_OVERVIEW_CREATE",
+ "permissions": ["MANAGE_PRODUCTS"],
+ "target": "WIDGET",
+ "options": options,
+ }
+ ]
+ mocked_get_response = Mock()
+ mocked_get_response.json.return_value = app_manifest
+
+ monkeypatch.setattr(HTTPSession, "request", Mock(return_value=mocked_get_response))
+ monkeypatch.setattr("saleor.app.installation_utils.send_app_token", Mock())
+
+ app_installation.permissions.set(
+ [permission_manage_products, permission_manage_orders]
+ )
+
+ # when
+ app, _ = install_app(app_installation, activate=True)
+
+ # then
+ assert App.objects.get().id == app.id
+ app_extension = app.extensions.get()
+
+ assert app_extension.label == label
+ assert app_extension.url == url
+ assert app_extension.mount == AppExtensionMount.PRODUCT_OVERVIEW_CREATE
+ assert app_extension.target == AppExtensionTarget.WIDGET
+ assert list(app_extension.permissions.all()) == [permission_manage_products]
+ assert app_extension.http_target_method == "POST"
@pytest.mark.parametrize(
@@ -345,6 +396,126 @@ def test_install_app_extension_permission_out_of_scope(
install_app(app_installation, activate=True)
+def test_install_app_with_extension_new_tab_target(
+ app_manifest,
+ app_installation,
+ monkeypatch,
+ permission_manage_products,
+):
+ # given
+ label = "Open in new tab"
+ url = "http://127.0.0.1:8080/app-extension"
+ options = {"newTabTarget": {"method": "GET"}}
+ app_manifest["permissions"] = ["MANAGE_PRODUCTS"]
+ app_manifest["extensions"] = [
+ {
+ "label": label,
+ "url": url,
+ "mount": "PRODUCT_OVERVIEW_CREATE",
+ "permissions": ["MANAGE_PRODUCTS"],
+ "options": options,
+ "target": "NEW_TAB",
+ }
+ ]
+ mocked_get_response = Mock()
+ mocked_get_response.json.return_value = app_manifest
+
+ monkeypatch.setattr(HTTPSession, "request", Mock(return_value=mocked_get_response))
+ monkeypatch.setattr("saleor.app.installation_utils.send_app_token", Mock())
+
+ app_installation.permissions.set([permission_manage_products])
+
+ # when
+ app, _ = install_app(app_installation, activate=True)
+
+ # then
+ assert App.objects.get().id == app.id
+ app_extension = app.extensions.get()
+ assert app_extension.label == label
+ assert app_extension.url == url
+ assert app_extension.mount == AppExtensionMount.PRODUCT_OVERVIEW_CREATE
+ assert app_extension.target == "new_tab"
+ assert list(app_extension.permissions.all()) == [permission_manage_products]
+ assert app_extension.http_target_method == "GET"
+
+
+def test_install_app_with_extension_new_tab_target_post_url_non_https(
+ app_manifest,
+ app_installation,
+ monkeypatch,
+ permission_manage_products,
+):
+ # given
+ label = "Open in new tab"
+ # Non-https url is prohibited
+ url = "http://extenal-url.com"
+ options = {"newTabTarget": {"method": "POST"}}
+ app_manifest["permissions"] = ["MANAGE_PRODUCTS"]
+ app_manifest["extensions"] = [
+ {
+ "label": label,
+ "url": url,
+ "mount": "PRODUCT_OVERVIEW_CREATE",
+ "permissions": ["MANAGE_PRODUCTS"],
+ "options": options,
+ "target": "NEW_TAB",
+ }
+ ]
+ mocked_get_response = Mock()
+ mocked_get_response.json.return_value = app_manifest
+
+ monkeypatch.setattr(HTTPSession, "request", Mock(return_value=mocked_get_response))
+ monkeypatch.setattr("saleor.app.installation_utils.send_app_token", Mock())
+
+ app_installation.permissions.set([permission_manage_products])
+
+ # when
+ # then
+ with pytest.raises(ValidationError) as error:
+ app, _ = install_app(app_installation, activate=True)
+
+ assert error.value.messages[0] == "Incorrect value for field: url."
+
+
+def test_install_app_with_extension_new_tab_target_post_url_other_than_app(
+ app_manifest,
+ app_installation,
+ monkeypatch,
+ permission_manage_products,
+):
+ # given
+ label = "Open in new tab"
+ # Url other than app's URL is prohibited
+ url = "https://extenal-url.com"
+ app_manifest["tokenTargetUrl"] = "https://app-url.com"
+ options = {"newTabTarget": {"method": "POST"}}
+ app_manifest["permissions"] = ["MANAGE_PRODUCTS"]
+ app_manifest["extensions"] = [
+ {
+ "label": label,
+ "url": url,
+ "mount": "PRODUCT_OVERVIEW_CREATE",
+ "permissions": ["MANAGE_PRODUCTS"],
+ "options": options,
+ "target": "NEW_TAB",
+ }
+ ]
+ mocked_get_response = Mock()
+ mocked_get_response.json.return_value = app_manifest
+
+ monkeypatch.setattr(HTTPSession, "request", Mock(return_value=mocked_get_response))
+ monkeypatch.setattr("saleor.app.installation_utils.send_app_token", Mock())
+
+ app_installation.permissions.set([permission_manage_products])
+
+ # when
+ # then
+ with pytest.raises(ValidationError) as error:
+ app, _ = install_app(app_installation, activate=True)
+
+ assert error.value.messages[0] == "Incorrect value for field: url."
+
+
@pytest.mark.parametrize(
"url",
[
@@ -452,6 +623,90 @@ def test_install_app_extension_incorrect_values(
install_app(app_installation, activate=True)
+ "incorrect_options",
+ [
+ {"newTabTarget": {"method": "INVALID"}},
+ {"newTabTarget": {}},
+ {"newTabTarget": "invalid"},
+ {"widgetTarget": {"method": "INVALID"}},
+ {"widgetTarget": {}},
+ {"widgetTarget": "invalid"},
+ ],
+)
+def test_install_app_extension_incorrect_options(
+ incorrect_options, app_manifest, app_installation, monkeypatch
+):
+ # given
+ label = "Create product with app"
+ url = "http://127.0.0.1:8080/app-extension"
+ app_manifest["permissions"] = []
+ app_manifest["extensions"] = [
+ {
+ "label": label,
+ "url": url,
+ "mount": "PRODUCT_OVERVIEW_CREATE",
+ "target": "POPUP",
+ "permissions": ["MANAGE_PRODUCTS"],
+ "options": incorrect_options,
+ }
+ ]
+ mocked_get_response = Mock()
+ mocked_get_response.json.return_value = app_manifest
+
+ monkeypatch.setattr(HTTPSession, "request", Mock(return_value=mocked_get_response))
+ monkeypatch.setattr("saleor.app.installation_utils.send_app_token", Mock())
+
+ # when & then
+ with pytest.raises(ValidationError):
+ install_app(app_installation, activate=True)
+
+
+def test_install_app_with_extension_post_method(
+ app_manifest,
+ app_installation,
+ monkeypatch,
+ permission_manage_products,
+):
+ # given
+ label = "Create product with app"
+ url = "https://example.com/extension" # extension url must be under the same origin as app
+ options = {"newTabTarget": {"method": "POST"}}
+ app_manifest["tokenTargetUrl"] = "https://example.com/install"
+ app_manifest["permissions"] = ["MANAGE_PRODUCTS"]
+ app_manifest["extensions"] = [
+ {
+ "label": label,
+ "url": url,
+ "mount": "PRODUCT_OVERVIEW_CREATE",
+ "permissions": ["MANAGE_PRODUCTS"],
+ "options": options,
+ "target": "NEW_TAB",
+ }
+ ]
+ mocked_get_response = Mock()
+ mocked_get_response.json.return_value = app_manifest
+
+ monkeypatch.setattr(HTTPSession, "request", Mock(return_value=mocked_get_response))
+ monkeypatch.setattr("saleor.app.installation_utils.send_app_token", Mock())
+
+ app_installation.permissions.set([permission_manage_products])
+
+ # when
+ app, _ = install_app(app_installation, activate=True)
+
+ # then
+ assert App.objects.get().id == app.id
+ app_extension = app.extensions.get()
+
+ assert app_extension.label == label
+ assert app_extension.url == url
+ assert app_extension.mount == AppExtensionMount.PRODUCT_OVERVIEW_CREATE
+ assert app_extension.target == AppExtensionTarget.NEW_TAB
+ assert list(app_extension.permissions.all()) == [permission_manage_products]
+ assert app_extension.http_target_method == "POST"
+
+
def test_install_app_with_webhook(
app_manifest, app_manifest_webhook, app_installation, monkeypatch
):
diff --git a/saleor/app/tests/test_validators.py b/saleor/app/tests/test_validators.py
index 393a1da157..3f0bf07ab0 100644
--- a/saleor/app/tests/test_validators.py
+++ b/saleor/app/tests/test_validators.py
@@ -2,10 +2,14 @@ import pytest
from django.core.exceptions import ValidationError
from ... import __version__
-from ...app.validators import AppURLValidator
+from ...app.validators import (
+ AppExtensionOptions,
+ AppURLValidator,
+)
from ..error_codes import AppErrorCode
from ..manifest_validations import (
_clean_author,
+ _clean_extension_options,
_clean_extension_url,
_clean_required_saleor_version,
_parse_version,
@@ -103,3 +107,301 @@ def test_clean_extensions_new_tab_valid_relative_url(app_manifest):
_clean_extension_url(extension, app_manifest)
assert error.value.message == "NEW_TAB target should be absolute path"
+
+
+ ("extension", "manifest", "should_raise"),
+ [
+ # url starts with /, target APP_PAGE, appUrl provided
+ (
+ {"url": "/page", "target": AppExtensionTarget.APP_PAGE},
+ {
+ "tokenTargetUrl": "https://app.example.com",
+ "appUrl": "https://app.example.com",
+ },
+ False,
+ ),
+ # url starts with /, target NEW_TAB, should raise
+ (
+ {"url": "/tab", "target": AppExtensionTarget.NEW_TAB},
+ {
+ "tokenTargetUrl": "https://app.example.com",
+ "appUrl": "https://app.example.com",
+ },
+ True,
+ ),
+ # url starts with protocol, target APP_PAGE, should raise
+ (
+ {
+ "url": "https://app.example.com/page",
+ "target": AppExtensionTarget.APP_PAGE,
+ },
+ {"tokenTargetUrl": "https://app.example.com"},
+ True,
+ ),
+ # url starts with protocol, target NEW_TAB, method POST, valid host
+ (
+ {
+ "url": "https://app.example.com/page",
+ "target": AppExtensionTarget.NEW_TAB,
+ "options": {"newTabTarget": {"method": "POST"}},
+ },
+ {"tokenTargetUrl": "https://app.example.com"},
+ False,
+ ),
+ # url starts with protocol, target NEW_TAB, method POST, invalid host
+ (
+ {
+ "url": "https://other.com/page",
+ "target": AppExtensionTarget.NEW_TAB,
+ "options": {"newTabTarget": {"method": "POST"}},
+ },
+ {"tokenTargetUrl": "https://app.example.com"},
+ True,
+ ),
+ # url is valid absolute, target POPUP
+ (
+ {"url": "https://app.example.com/page", "target": AppExtensionTarget.POPUP},
+ {"tokenTargetUrl": "https://app.example.com"},
+ False,
+ ),
+ ],
+)
+def test_clean_extension_url(extension, manifest, should_raise):
+ if should_raise:
+ with pytest.raises(ValidationError):
+ _clean_extension_url(extension, manifest)
+
+ else:
+ _clean_extension_url(extension, manifest)
+
+
+def test_clean_extension_url_https_only(settings):
+ settings.ENABLE_SSL = True
+
+ with pytest.raises(ValidationError):
+ _clean_extension_url(
+ {
+ "url": "http://app.example.com/page",
+ "target": AppExtensionTarget.NEW_TAB,
+ "options": {"newTabTarget": {"method": "POST"}},
+ },
+ {
+ "tokenTargetUrl": "https://app.example.com",
+ "appUrl": "https://app.example.com",
+ },
+ )
+
+
+def test_clean_extension_url_http_if_SSL_disabled(settings):
+ settings.ENABLE_SSL = False
+
+ result = _clean_extension_url(
+ {"url": "http://app.example.com/page", "target": AppExtensionTarget.NEW_TAB},
+ {
+ "tokenTargetUrl": "https://app.example.com",
+ "appUrl": "https://app.example.com",
+ },
+ )
+
+ assert result is None
+
+
+def test_app_extension_options_accepts_only_one():
+ parsed = AppExtensionOptions().model_validate({"widgetTarget": {"method": "GET"}})
+
+ assert parsed.new_tab_target is None
+ assert parsed.widget_target is not None
+
+ parsed = AppExtensionOptions().model_validate({"newTabTarget": {"method": "GET"}})
+
+ assert parsed.new_tab_target is not None
+ assert parsed.widget_target is None
+
+ with pytest.raises(
+ ValueError, match="Only one of 'newTabTarget' or 'widgetTarget' can be set."
+ ):
+ AppExtensionOptions.model_validate(
+ {
+ "newTabTarget": {"method": "GET"},
+ "widgetTarget": {"method": "GET"},
+ }
+ )
+
+ parsed = AppExtensionOptions().model_validate({})
+
+ assert parsed.new_tab_target is None
+ assert parsed.widget_target is None
+
+
+ ("app_url", "extension_url", "should_raise"),
+ [
+ (None, "/some-path", True), # Test missing token_target_url
+ ("https://example.com", "/some-path", False), # Test valid token_target_url
+ ],
+)
+def test_clean_extension_url_token_target_url(app_url, extension_url, should_raise):
+ # Given
+ extension = {"url": extension_url, "target": "APP_PAGE"}
+ manifest_data = {"tokenTargetUrl": app_url, "appUrl": "https://example.com"}
+
+ # When & Then
+ if should_raise:
+ with pytest.raises(ValidationError, match="token_target_url is missing"):
+ _clean_extension_url(extension, manifest_data)
+ else:
+ # Should not raise ValidationError
+ _clean_extension_url(extension, manifest_data)
+
+
+def test_clean_extension_options_valid_widget_options():
+ # Given
+ extension = {
+ "target": AppExtensionTarget.WIDGET,
+ "options": {"widgetTarget": {"method": "POST"}},
+ }
+ errors = {"extensions": []}
+
+ # When
+ _clean_extension_options(extension, errors)
+
+ # Then
+ assert "extensions" in errors
+ assert len(errors["extensions"]) == 0
+ assert "options" in extension
+ assert "widget_target" in extension["options"]
+ assert extension["options"]["widget_target"]["method"] == "POST"
+
+
+def test_clean_extension_options_valid_new_tab_options():
+ # Given
+ extension = {
+ "target": AppExtensionTarget.NEW_TAB,
+ "options": {"newTabTarget": {"method": "GET"}},
+ }
+ errors = {"extensions": []}
+
+ # When
+ _clean_extension_options(extension, errors)
+
+ # Then
+ assert "extensions" in errors
+ assert len(errors["extensions"]) == 0
+ assert "options" in extension
+ assert "new_tab_target" in extension["options"]
+ assert extension["options"]["new_tab_target"]["method"] == "GET"
+
+
+def test_clean_extension_options_both_targets():
+ # Given
+ extension = {
+ "target": AppExtensionTarget.NEW_TAB,
+ "options": {
+ "newTabTarget": {"method": "GET"},
+ "widgetTarget": {"method": "POST"},
+ },
+ }
+ errors = {"extensions": []}
+
+ # When
+ _clean_extension_options(extension, errors)
+
+ # Then
+ assert "extensions" in errors
+ assert len(errors["extensions"]) == 1
+ assert (
+ "Only one of 'newTabTarget' or 'widgetTarget'"
+ in errors["extensions"][0].message
+ )
+
+
+def test_clean_extension_options_widget_target_with_wrong_target():
+ # Given
+ extension = {
+ "target": AppExtensionTarget.NEW_TAB,
+ "options": {"widgetTarget": {"method": "POST"}},
+ }
+ errors = {"extensions": []}
+
+ # When
+ _clean_extension_options(extension, errors)
+
+ # Then
+ assert "extensions" in errors
+ assert len(errors["extensions"]) == 1
+ assert (
+ "widgetTarget options must be set only on WIDGET target"
+ in errors["extensions"][0].message
+ )
+
+
+def test_clean_extension_options_new_tab_target_with_wrong_target():
+ # Given
+ extension = {
+ "target": AppExtensionTarget.WIDGET,
+ "options": {"newTabTarget": {"method": "GET"}},
+ }
+ errors = {"extensions": []}
+
+ # When
+ _clean_extension_options(extension, errors)
+
+ # Then
+ assert "extensions" in errors
+ assert len(errors["extensions"]) == 1
+ assert (
+ "newTabTarget options must be set only on NEW_TAB target"
+ in errors["extensions"][0].message
+ )
+
+
+def test_clean_extension_options_invalid_options():
+ # Given
+ extension = {
+ "target": AppExtensionTarget.WIDGET,
+ "options": {
+ "widgetTarget": {
+ "method": "INVALID_METHOD" # Only POST and GET are valid
+ }
+ },
+ }
+ errors = {"extensions": []}
+
+ # When
+ _clean_extension_options(extension, errors)
+
+ # Then
+ assert "extensions" in errors
+ assert len(errors["extensions"]) == 1
+ assert "Invalid options field" in errors["extensions"][0].message
+
+
+def test_clean_extension_options_empty():
+ # Given
+ extension = {"target": AppExtensionTarget.WIDGET, "options": {}}
+ errors = {}
+
+ # When
+ _clean_extension_options(extension, errors)
+
+ # Then
+ assert "extensions" not in errors
+ assert "options" in extension
+ assert extension["options"] == {}
+
+
+def test_clean_extension_options_no_options():
+ # Given
+ extension = {
+ "target": AppExtensionTarget.WIDGET,
+ }
+ errors = {}
+
+ # When
+ _clean_extension_options(extension, errors)
+
+ # Then
+ assert "extensions" not in errors
+ assert "options" in extension
+ assert extension["options"] == {}
diff --git a/saleor/app/types.py b/saleor/app/types.py
index e44bf86cfe..8311c2c7ee 100644
--- a/saleor/app/types.py
+++ b/saleor/app/types.py
@@ -15,18 +15,22 @@ class AppExtensionMount:
COLLECTION_OVERVIEW_CREATE = "collection_overview_create"
COLLECTION_OVERVIEW_MORE_ACTIONS = "collection_overview_more_actions"
COLLECTION_DETAILS_MORE_ACTIONS = "collection_details_more_actions"
+ COLLECTION_DETAILS_WIDGETS = "collection_details_widgets"
GIFT_CARD_OVERVIEW_CREATE = "gift_card_overview_create"
GIFT_CARD_OVERVIEW_MORE_ACTIONS = "gift_card_overview_more_actions"
GIFT_CARD_DETAILS_MORE_ACTIONS = "gift_card_details_more_actions"
+ GIFT_CARD_DETAILS_WIDGETS = "gift_card_details_widgets"
CUSTOMER_OVERVIEW_CREATE = "customer_overview_create"
CUSTOMER_OVERVIEW_MORE_ACTIONS = "customer_overview_more_actions"
CUSTOMER_DETAILS_MORE_ACTIONS = "customer_details_more_actions"
+ CUSTOMER_DETAILS_WIDGETS = "customer_details_widgets"
PRODUCT_OVERVIEW_CREATE = "product_overview_create"
PRODUCT_OVERVIEW_MORE_ACTIONS = "product_overview_more_actions"
PRODUCT_DETAILS_MORE_ACTIONS = "product_details_more_actions"
+ PRODUCT_DETAILS_WIDGETS = "product_details_widgets"
NAVIGATION_CATALOG = "navigation_catalog"
NAVIGATION_ORDERS = "navigation_orders"
@@ -38,10 +42,12 @@ class AppExtensionMount:
ORDER_DETAILS_MORE_ACTIONS = "order_details_more_actions"
ORDER_OVERVIEW_CREATE = "order_overview_create"
ORDER_OVERVIEW_MORE_ACTIONS = "order_overview_more_actions"
+ ORDER_DETAILS_WIDGETS = "order_details_widgets"
DRAFT_ORDER_DETAILS_MORE_ACTIONS = "draft_order_details_more_actions"
DRAFT_ORDER_OVERVIEW_CREATE = "draft_order_overview_create"
DRAFT_ORDER_OVERVIEW_MORE_ACTIONS = "draft_order_overview_more_actions"
+ DRAFT_ORDER_DETAILS_WIDGETS = "draft_order_details_widgets"
DISCOUNT_DETAILS_MORE_ACTIONS = "discount_details_more_actions"
DISCOUNT_OVERVIEW_CREATE = "discount_overview_create"
@@ -50,6 +56,7 @@ class AppExtensionMount:
VOUCHER_DETAILS_MORE_ACTIONS = "voucher_details_more_actions"
VOUCHER_OVERVIEW_CREATE = "voucher_overview_create"
VOUCHER_OVERVIEW_MORE_ACTIONS = "voucher_overview_more_actions"
+ VOUCHER_DETAILS_WIDGETS = "voucher_details_widgets"
PAGE_DETAILS_MORE_ACTIONS = "page_details_more_actions"
PAGE_OVERVIEW_CREATE = "page_overview_create"
@@ -70,15 +77,19 @@ class AppExtensionMount:
(COLLECTION_OVERVIEW_CREATE, "collection_overview_create"),
(COLLECTION_OVERVIEW_MORE_ACTIONS, "collection_overview_more_actions"),
(COLLECTION_DETAILS_MORE_ACTIONS, "collection_details_more_actions"),
+ (COLLECTION_DETAILS_WIDGETS, "collection_details_widgets"),
(GIFT_CARD_OVERVIEW_CREATE, "gift_card_overview_create"),
(GIFT_CARD_OVERVIEW_MORE_ACTIONS, "gift_card_overview_more_actions"),
(GIFT_CARD_DETAILS_MORE_ACTIONS, "gift_card_details_more_actions"),
+ (GIFT_CARD_DETAILS_WIDGETS, "gift_card_details_widgets"),
(CUSTOMER_OVERVIEW_CREATE, "customer_overview_create"),
(CUSTOMER_OVERVIEW_MORE_ACTIONS, "customer_overview_more_actions"),
(CUSTOMER_DETAILS_MORE_ACTIONS, "customer_details_more_actions"),
+ (CUSTOMER_DETAILS_WIDGETS, "customer_details_widgets"),
(PRODUCT_OVERVIEW_CREATE, "product_overview_create"),
(PRODUCT_OVERVIEW_MORE_ACTIONS, "product_overview_more_actions"),
(PRODUCT_DETAILS_MORE_ACTIONS, "product_details_more_actions"),
+ (PRODUCT_DETAILS_WIDGETS, "product_details_widgets"),
(NAVIGATION_CATALOG, "navigation_catalog"),
(NAVIGATION_ORDERS, "navigation_orders"),
(NAVIGATION_CUSTOMERS, "navigation_customers"),
@@ -88,15 +99,18 @@ class AppExtensionMount:
(ORDER_DETAILS_MORE_ACTIONS, "order_details_more_actions"),
(ORDER_OVERVIEW_CREATE, "order_overview_create"),
(ORDER_OVERVIEW_MORE_ACTIONS, "order_overview_more_actions"),
+ (ORDER_DETAILS_WIDGETS, "order_details_widgets"),
(DRAFT_ORDER_DETAILS_MORE_ACTIONS, "draft_order_details_more_actions"),
(DRAFT_ORDER_OVERVIEW_CREATE, "draft_order_overview_create"),
(DRAFT_ORDER_OVERVIEW_MORE_ACTIONS, "draft_order_overview_more_actions"),
+ (DRAFT_ORDER_DETAILS_WIDGETS, "draft_order_details_widgets"),
(DISCOUNT_DETAILS_MORE_ACTIONS, "discount_details_more_actions"),
(DISCOUNT_OVERVIEW_CREATE, "discount_overview_create"),
(DISCOUNT_OVERVIEW_MORE_ACTIONS, "discount_overview_more_actions"),
(VOUCHER_DETAILS_MORE_ACTIONS, "voucher_details_more_actions"),
(VOUCHER_OVERVIEW_CREATE, "voucher_overview_create"),
(VOUCHER_OVERVIEW_MORE_ACTIONS, "voucher_overview_more_actions"),
+ (VOUCHER_DETAILS_WIDGETS, "voucher_details_widgets"),
(PAGE_DETAILS_MORE_ACTIONS, "page_details_more_actions"),
(PAGE_OVERVIEW_CREATE, "page_overview_create"),
(PAGE_OVERVIEW_MORE_ACTIONS, "page_overview_more_actions"),
@@ -119,5 +133,23 @@ class AppExtensionTarget:
POPUP = "popup"
APP_PAGE = "app_page"
NEW_TAB = "new_tab"
+ WIDGET = "widget"
- CHOICES = [(POPUP, "popup"), (APP_PAGE, "app_page"), (NEW_TAB, "new_tab")]
+ CHOICES = [
+ (POPUP, "popup"),
+ (APP_PAGE, "app_page"),
+ (NEW_TAB, "new_tab"),
+ (WIDGET, "widget"),
+ ]
+
+
+class AppExtensionHttpMethod:
+ """HTTP methods available for app extensions.
+
+ Represents available HTTPS methods for frontend to work with extension (WIDGET and NEW_TAB)
+ """
+
+ GET = "GET"
+ POST = "POST"
+
+ CHOICES = [("GET", "GET"), ("POST", "POST")]
diff --git a/saleor/app/validators.py b/saleor/app/validators.py
index 3e7983a2ed..ca0bf7b46f 100644
--- a/saleor/app/validators.py
+++ b/saleor/app/validators.py
@@ -1,11 +1,14 @@
import mimetypes
import re
+from typing import Annotated, Literal
from django.core.exceptions import ValidationError
from django.core.validators import URLValidator
+from pydantic import BaseModel, Field, field_validator, model_validator
from ..thumbnail import ICON_MIME_TYPES
from .error_codes import AppErrorCode
+from .types import AppExtensionHttpMethod
class AppURLValidator(URLValidator):
@@ -44,3 +47,58 @@ def brand_validator(brand):
"Invalid file type for field: logo.default.",
code=AppErrorCode.INVALID_URL_FORMAT.value,
)
+
+
+def validate_POST_or_GET_http_method(value):
+ """Validate that the HTTP method is either GET or POST."""
+ if value not in [
+ AppExtensionHttpMethod.GET,
+ AppExtensionHttpMethod.POST,
+ ]:
+ raise ValueError(
+ f"Method must be either {AppExtensionHttpMethod.GET} or {AppExtensionHttpMethod.POST}"
+ )
+ return value
+
+
+class NewTabTargetOptions(BaseModel):
+ method: Literal["GET", "POST"]
+
+ @field_validator("method")
+ def validate_method(cls, value):
+ return validate_POST_or_GET_http_method(value)
+
+
+class WidgetTargetOptions(BaseModel):
+ method: Literal["GET", "POST"]
+
+ @field_validator("method")
+ def validate_method(cls, value):
+ return validate_POST_or_GET_http_method(value)
+
+
+class AppExtensionOptions(BaseModel):
+ new_tab_target: Annotated[
+ NewTabTargetOptions | None,
+ Field(
+ validation_alias="newTabTarget",
+ description="Settings for extension target NEW_TAB",
+ ),
+ ] = None
+ widget_target: Annotated[
+ WidgetTargetOptions | None,
+ Field(
+ validation_alias="widgetTarget",
+ description="Settings for extension target WIDGET",
+ ),
+ ] = None
+
+ @model_validator(mode="after")
+ def validate_either_or(cls, values):
+ new_tab = values.new_tab_target
+ widget = values.widget_target
+
+ if new_tab and widget:
+ raise ValueError("Only one of 'newTabTarget' or 'widgetTarget' can be set.")
+
+ return values
diff --git a/saleor/graphql/app/tests/mutations/test_app_fetch_manifest.py b/saleor/graphql/app/tests/mutations/test_app_fetch_manifest.py
index 4d26070009..1de2d105cf 100644
--- a/saleor/graphql/app/tests/mutations/test_app_fetch_manifest.py
+++ b/saleor/graphql/app/tests/mutations/test_app_fetch_manifest.py
@@ -439,7 +439,7 @@ def test_app_fetch_manifest_extensions_incorrect_enum_values(
("/app", AppExtensionTargetEnum.APP_PAGE.name, "https://www.example.com/app"),
("/app", AppExtensionTargetEnum.POPUP.name, "https://www.example.com/app"),
(
- "https://app-absolute-url.com",
+ "https://www.example.com/app/form",
AppExtensionTargetEnum.NEW_TAB.name,
"https://www.example.com/app",
),
diff --git a/saleor/graphql/app/tests/queries/test_app_extension.py b/saleor/graphql/app/tests/queries/test_app_extension.py
index 25095f0b87..3e3ae059d2 100644
--- a/saleor/graphql/app/tests/queries/test_app_extension.py
+++ b/saleor/graphql/app/tests/queries/test_app_extension.py
@@ -1,7 +1,7 @@
import graphene
from .....app.models import AppExtension
-from .....app.types import AppExtensionMount
+from .....app.types import AppExtensionMount, AppExtensionTarget
from .....core.jwt import jwt_decode
from ....tests.utils import assert_no_permission, get_graphql_content
@@ -17,6 +17,19 @@ query ($id: ID!){
permissions{
code
}
+ options {
+ ... on AppExtensionOptionsWidget{
+ widgetTarget {
+ method
+ }
+ }
+ ...on AppExtensionOptionsNewTab {
+ newTabTarget{
+ method
+ }
+ }
+
+ }
}
}
"""
@@ -29,6 +42,8 @@ def test_app_extension_staff_user(app, staff_api_client, permission_manage_produ
label="Create product with App",
url="https://www.example.com/app-product",
mount=AppExtensionMount.PRODUCT_OVERVIEW_MORE_ACTIONS,
+ http_target_method="POST",
+ target=AppExtensionTarget.WIDGET,
)
app_extension.permissions.add(permission_manage_products)
id = graphene.Node.to_global_id("AppExtension", app_extension.id)
@@ -53,6 +68,8 @@ def test_app_extension_staff_user(app, staff_api_client, permission_manage_produ
permission_code = extension_data["permissions"][0]["code"].lower()
assert app_extension.permissions.first().codename == permission_code
+ assert extension_data["options"]["widgetTarget"]["method"] == "POST"
+
def test_app_extension_by_app(app, app_api_client, permission_manage_products):
# given
diff --git a/saleor/graphql/app/tests/queries/test_app_extensions.py b/saleor/graphql/app/tests/queries/test_app_extensions.py
index decbee135d..a6c494e272 100644
--- a/saleor/graphql/app/tests/queries/test_app_extensions.py
+++ b/saleor/graphql/app/tests/queries/test_app_extensions.py
@@ -17,6 +17,19 @@ query ($filter: AppExtensionFilterInput){
target
id
accessToken
+ options {
+ ... on AppExtensionOptionsWidget{
+ widgetTarget {
+ method
+ }
+ }
+ ...on AppExtensionOptionsNewTab {
+ newTabTarget{
+ method
+ }
+ }
+
+ }
permissions{
code
}
@@ -34,6 +47,8 @@ def test_app_extensions(staff_api_client, app, permission_manage_products):
label="Create product with App",
url="https://www.example.com/app-product",
mount=AppExtensionMount.PRODUCT_OVERVIEW_MORE_ACTIONS,
+ http_target_method="POST",
+ target=AppExtensionTarget.WIDGET,
)
app_extension.permissions.add(permission_manage_products)
variables = {}
@@ -66,6 +81,8 @@ def test_app_extensions(staff_api_client, app, permission_manage_products):
decode_token = jwt_decode(extension_data["accessToken"])
decode_token["permissions"] = ["MANAGE_PRODUCTS"]
+ assert extension_data["options"]["widgetTarget"]["method"] == "POST"
+
def test_app_extensions_app_not_active(
staff_api_client, app, permission_manage_products
diff --git a/saleor/graphql/app/types.py b/saleor/graphql/app/types.py
index 9ff4e43c0e..1d4e787112 100644
--- a/saleor/graphql/app/types.py
+++ b/saleor/graphql/app/types.py
@@ -4,7 +4,7 @@ import datetime
import graphene
from ...app import models
-from ...app.types import AppExtensionTarget
+from ...app.types import AppExtensionHttpMethod, AppExtensionTarget
from ...core.exceptions import PermissionDenied
from ...core.jwt import JWT_THIRDPARTY_ACCESS_TYPE
from ...core.utils import build_absolute_uri
@@ -27,11 +27,12 @@ from ..core import ResolveInfo, SaleorContext
from ..core.connection import CountableConnection
from ..core.context import get_database_connection_name
from ..core.dataloaders import DataLoader
-from ..core.descriptions import ADDED_IN_319, ADDED_IN_321
+from ..core.descriptions import ADDED_IN_319, ADDED_IN_321, ADDED_IN_322
from ..core.doc_category import DOC_CATEGORY_APPS
from ..core.federation import federated_entity, resolve_federation_references
from ..core.scalars import DateTime
from ..core.types import (
+ BaseEnum,
BaseObjectType,
IconThumbnailField,
Job,
@@ -137,6 +138,64 @@ class AppManifestExtension(BaseObjectType):
return resolve_app_extension_url(root)
+class HttpMethod(BaseEnum):
+ POST = AppExtensionHttpMethod.POST
+ GET = AppExtensionHttpMethod.GET
+
+
+class NewTabTargetOptions(BaseObjectType):
+ method = graphene.Field(
+ HttpMethod,
+ required=True,
+ description="HTTP method for New Tab target (GET or POST)",
+ )
+
+ class Meta:
+ description = "Represents the NEW_TAB target options for an app extension."
+ doc_category = DOC_CATEGORY_APPS
+
+
+class WidgetTargetOptions(BaseObjectType):
+ method = graphene.Field(
+ HttpMethod,
+ required=True,
+ description="HTTP method for Widget target (GET or POST)",
+ )
+
+ class Meta:
+ description = "Represents the WIDGET target options for an app extension."
+ doc_category = DOC_CATEGORY_APPS
+
+
+class AppExtensionOptionsWidget(BaseObjectType):
+ widget_target = graphene.Field(
+ WidgetTargetOptions,
+ description="Options for displaying a Widget",
+ required=False,
+ )
+
+ class Meta:
+ description = "Represents the options for an app extension."
+ doc_category = DOC_CATEGORY_APPS
+
+
+class AppExtensionOptionsNewTab(BaseObjectType):
+ new_tab_target = graphene.Field(
+ NewTabTargetOptions,
+ description="Options controlling behavior of the NEW_TAB extension target",
+ required=False,
+ )
+
+ class Meta:
+ description = "Represents the options for an app extension."
+ doc_category = DOC_CATEGORY_APPS
+
+
+class AppExtensionPossibleOptions(graphene.Union):
+ class Meta:
+ types = (AppExtensionOptionsWidget, AppExtensionOptionsNewTab)
+
+
class AppExtension(AppManifestExtension, ModelObjectType[models.AppExtension]):
id = graphene.GlobalID(required=True, description="The ID of the app extension.")
app = graphene.Field(
@@ -147,6 +206,10 @@ class AppExtension(AppManifestExtension, ModelObjectType[models.AppExtension]):
access_token = graphene.String(
description="JWT token used to authenticate by third-party app extension."
)
+ options = graphene.Field(
+ AppExtensionPossibleOptions,
+ description="App extension options." + ADDED_IN_322,
+ )
class Meta:
description = "Represents app data."
@@ -201,6 +264,22 @@ class AppExtension(AppManifestExtension, ModelObjectType[models.AppExtension]):
return AppByIdLoader(info.context).load(root.app_id).then(_resolve_access_token)
+ @staticmethod
+ def resolve_options(root: models.AppExtension, _info: ResolveInfo):
+ http_method = root.http_target_method
+
+ if root.target == AppExtensionTarget.WIDGET:
+ return AppExtensionOptionsWidget(
+ widget_target=WidgetTargetOptions(method=http_method),
+ )
+
+ if root.target == AppExtensionTarget.NEW_TAB:
+ return AppExtensionOptionsNewTab(
+ new_tab_target=NewTabTargetOptions(method=http_method),
+ )
+
+ return None
+
class AppExtensionCountableConnection(CountableConnection):
class Meta:
diff --git a/saleor/graphql/schema.graphql b/saleor/graphql/schema.graphql
index 8410200fad..7498a78012 100644
--- a/saleor/graphql/schema.graphql
+++ b/saleor/graphql/schema.graphql
@@ -2942,6 +2942,13 @@ type AppExtension implements Node @doc(category: "Apps") {
"""JWT token used to authenticate by third-party app extension."""
accessToken: String
+
+ """
+ App extension options.
+
+ Added in Saleor 3.22.
+ """
+ options: AppExtensionPossibleOptions
}
"""All places where app extension can be mounted."""
@@ -2952,15 +2959,19 @@ enum AppExtensionMountEnum @doc(category: "Apps") {
COLLECTION_OVERVIEW_CREATE
COLLECTION_OVERVIEW_MORE_ACTIONS
COLLECTION_DETAILS_MORE_ACTIONS
+ COLLECTION_DETAILS_WIDGETS
GIFT_CARD_OVERVIEW_CREATE
GIFT_CARD_OVERVIEW_MORE_ACTIONS
GIFT_CARD_DETAILS_MORE_ACTIONS
+ GIFT_CARD_DETAILS_WIDGETS
CUSTOMER_OVERVIEW_CREATE
CUSTOMER_OVERVIEW_MORE_ACTIONS
CUSTOMER_DETAILS_MORE_ACTIONS
+ CUSTOMER_DETAILS_WIDGETS
PRODUCT_OVERVIEW_CREATE
PRODUCT_OVERVIEW_MORE_ACTIONS
PRODUCT_DETAILS_MORE_ACTIONS
+ PRODUCT_DETAILS_WIDGETS
NAVIGATION_CATALOG
NAVIGATION_ORDERS
NAVIGATION_CUSTOMERS
@@ -2970,15 +2981,18 @@ enum AppExtensionMountEnum @doc(category: "Apps") {
ORDER_DETAILS_MORE_ACTIONS
ORDER_OVERVIEW_CREATE
ORDER_OVERVIEW_MORE_ACTIONS
+ ORDER_DETAILS_WIDGETS
DRAFT_ORDER_DETAILS_MORE_ACTIONS
DRAFT_ORDER_OVERVIEW_CREATE
DRAFT_ORDER_OVERVIEW_MORE_ACTIONS
+ DRAFT_ORDER_DETAILS_WIDGETS
DISCOUNT_DETAILS_MORE_ACTIONS
DISCOUNT_OVERVIEW_CREATE
DISCOUNT_OVERVIEW_MORE_ACTIONS
VOUCHER_DETAILS_MORE_ACTIONS
VOUCHER_OVERVIEW_CREATE
VOUCHER_OVERVIEW_MORE_ACTIONS
+ VOUCHER_DETAILS_WIDGETS
PAGE_DETAILS_MORE_ACTIONS
PAGE_OVERVIEW_CREATE
PAGE_OVERVIEW_MORE_ACTIONS
@@ -3000,6 +3014,38 @@ enum AppExtensionTargetEnum @doc(category: "Apps") {
POPUP
APP_PAGE
NEW_TAB
+ WIDGET
+}
+
+union AppExtensionPossibleOptions = AppExtensionOptionsWidget | AppExtensionOptionsNewTab
+
+"""Represents the options for an app extension."""
+type AppExtensionOptionsWidget @doc(category: "Apps") {
+ """Options for displaying a Widget"""
+ widgetTarget: WidgetTargetOptions
+}
+
+"""Represents the WIDGET target options for an app extension."""
+type WidgetTargetOptions @doc(category: "Apps") {
+ """HTTP method for Widget target (GET or POST)"""
+ method: HttpMethod!
+}
+
+enum HttpMethod {
+ POST
+ GET
+}
+
+"""Represents the options for an app extension."""
+type AppExtensionOptionsNewTab @doc(category: "Apps") {
+ """Options controlling behavior of the NEW_TAB extension target"""
+ newTabTarget: NewTabTargetOptions
+}
+
+"""Represents the NEW_TAB target options for an app extension."""
+type NewTabTargetOptions @doc(category: "Apps") {
+ """HTTP method for New Tab target (GET or POST)"""
+ method: HttpMethod!
}
"""Represents the app's brand data."""