Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .oxfmtrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"arrowParens": "avoid",
"singleQuote": false,
"trailingComma": "all",
"bracketSpacing": false,
"semi": true,
"tabWidth": 2,
"printWidth": 80,
"jsxSingleQuote": false,
"bracketSameLine": false,
"sortPackageJson": false,
"ignorePatterns": [
"**/dist/**",
"**/node_modules/**",
"**/.shopify/**",
"**/generated/**",
"**/package.json"
]
}
27 changes: 27 additions & 0 deletions .oxlintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"$schema": "./node_modules/oxlint/configuration_schema.json",
"categories": {
"correctness": "off",
"suspicious": "off",
"pedantic": "off",
"perf": "off",
"style": "off",
"restriction": "off"
},
"ignorePatterns": [
"**/node_modules/**",
"**/dist/**",
"**/.shopify/**",
"**/generated/**",
"examples/mock-http-server/**"
],
"overrides": [
{
"files": ["**/*.{js,jsx}"],
"rules": {
"no-console": ["error", {"allow": ["error"]}],
"no-debugger": "error"
}
}
]
}
12 changes: 6 additions & 6 deletions docs/reference/components/DiscountClasses.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Card, Checkbox, Text, BlockStack, Box } from "@shopify/polaris";
import React, { useState, useCallback } from "react";
import {Card, Checkbox, Text, BlockStack, Box} from "@shopify/polaris";
import React, {useState, useCallback} from "react";

const DiscountClass = {
Product: "PRODUCT",
Expand All @@ -25,7 +25,7 @@ const DISCOUNT_CLASS_LABELS = {
* @returns A Polaris Card containing discount class selection checkboxes
*/
function DiscountClasses(props) {
const { discountClasses = [DiscountClass.Product], onChange } = props;
const {discountClasses = [DiscountClass.Product], onChange} = props;

const [selectedClasses, setSelectedClasses] = useState(
discountClasses.length > 0 ? discountClasses : [DiscountClass.Product],
Expand All @@ -35,7 +35,7 @@ function DiscountClasses(props) {
(checked, discountClass) => {
const updatedClasses = checked
? [...selectedClasses, discountClass]
: selectedClasses.filter((cls) => cls !== discountClass);
: selectedClasses.filter(cls => cls !== discountClass);

if (updatedClasses.length === 0) {
return;
Expand All @@ -62,7 +62,7 @@ function DiscountClasses(props) {

<Box paddingBlockStart="400">
<BlockStack gap="200">
{Object.values(DiscountClass).map((discountClass) => {
{Object.values(DiscountClass).map(discountClass => {
const isChecked = selectedClasses.includes(discountClass);
const isDisabled = isChecked && selectedClasses.length === 1;
return (
Expand All @@ -71,7 +71,7 @@ function DiscountClasses(props) {
label={DISCOUNT_CLASS_LABELS[discountClass]}
checked={isChecked}
disabled={isDisabled}
onChange={(checked) => handleChange(checked, discountClass)}
onChange={checked => handleChange(checked, discountClass)}
/>
);
})}
Expand Down
21 changes: 21 additions & 0 deletions docs/reference/shopify/javascript/create-intent-schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"$schema": "https://extensions.shopifycdn.com/shopifycloud/schemas/v1/shopify-intent.json",
"inputSchema": {
"type": "object",
"$ref": "https://extensions.shopifycdn.com/shopifycloud/schemas/v1/shopify/discount.json",
"additionalProperties": true,
"properties": {
"functionId": {
"matchValue": "YOUR_FUNCTION_ID"
}
}
},
"outputSchema": {
"type": "object",
"properties": {
"id": {
"$ref": "https://extensions.shopifycdn.com/shopifycloud/schemas/v1/shopify/discount/gid.json"
}
}
}
}
26 changes: 26 additions & 0 deletions docs/reference/shopify/javascript/edit-intent-schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"$schema": "https://extensions.shopifycdn.com/shopifycloud/schemas/v1/shopify-intent.json",
"value": {
"$ref": "https://extensions.shopifycdn.com/shopifycloud/schemas/v1/shopify/discount/gid.json",
"mapTo": "param",
"fieldName": "id"
},
"inputSchema": {
"type": "object",
"$ref": "https://extensions.shopifycdn.com/shopifycloud/schemas/v1/shopify/discount.json",
"additionalProperties": true,
"properties": {
"functionId": {
"matchValue": "YOUR_FUNCTION_ID"
}
}
},
"outputSchema": {
"type": "object",
"properties": {
"id": {
"$ref": "https://extensions.shopifycdn.com/shopifycloud/schemas/v1/shopify/discount/gid.json"
}
}
}
}
5 changes: 5 additions & 0 deletions docs/reference/shopify/javascript/instructions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Use this app when the merchant wants to create or edit a metafield-configured discount powered by this app's Shopify Function.

When invoking `create:shopify/Discount`, pass `functionId: "YOUR_FUNCTION_ID"` so Shopify resolves directly to this app's create flow.

When invoking `edit:shopify/Discount`, pass the discount's GID (default to the canonical `gid://shopify/DiscountNode/{id}`) and `functionId: "YOUR_FUNCTION_ID"` so Shopify resolves the edit directly to this app.
39 changes: 39 additions & 0 deletions docs/reference/shopify/javascript/shopify.extension.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,42 @@ handle = "ui-multiclass-metafield-js"
create = "/app/discount/:functionId/new"
details = "/app/discount/:functionId/:id"
# [END discount-function.ui-paths]

# [START discount-function.app-intent-link]
# Register app intent links so Sidekick can create and edit discounts backed by
# this app's Function. Each admin.app.intent.link target maps a shopify/Discount
# action (create or edit) to a page in your app.
[[extensions]]
name = "Create discount"
description = "Create a metafield-configured discount powered by this app's Shopify Function."
handle = "discount-app-intent-link-create"
type = "admin_link"

[[extensions.targeting]]
target = "admin.app.intent.link"
# Hardcode your deployed Function's ID (see "Set your Function ID" below).
url = "/app/discount/YOUR_FUNCTION_ID/new"
instructions = "./instructions.md"

[[extensions.targeting.intents]]
type = "shopify/Discount"
action = "create"
schema = "./create-intent-schema.json"

[[extensions]]
name = "Edit discount"
description = "Edit a metafield-configured discount powered by this app's Shopify Function."
handle = "discount-app-intent-link-edit"
type = "admin_link"

[[extensions.targeting]]
target = "admin.app.intent.link"
# {id} receives the discount ID; the Function ID stays hardcoded.
url = "/app/discount/YOUR_FUNCTION_ID/{id}"
instructions = "./instructions.md"

[[extensions.targeting.intents]]
type = "shopify/Discount"
action = "edit"
schema = "./edit-intent-schema.json"
# [END discount-function.app-intent-link]
2 changes: 1 addition & 1 deletion docs/reference/shopify/pnpm-workspace.yaml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
packages:
- "extensions/*"
- 'extensions/*'
21 changes: 21 additions & 0 deletions docs/reference/shopify/rust/create-intent-schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"$schema": "https://extensions.shopifycdn.com/shopifycloud/schemas/v1/shopify-intent.json",
"inputSchema": {
"type": "object",
"$ref": "https://extensions.shopifycdn.com/shopifycloud/schemas/v1/shopify/discount.json",
"additionalProperties": true,
"properties": {
"functionId": {
"matchValue": "YOUR_FUNCTION_ID"
}
}
},
"outputSchema": {
"type": "object",
"properties": {
"id": {
"$ref": "https://extensions.shopifycdn.com/shopifycloud/schemas/v1/shopify/discount/gid.json"
}
}
}
}
26 changes: 26 additions & 0 deletions docs/reference/shopify/rust/edit-intent-schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"$schema": "https://extensions.shopifycdn.com/shopifycloud/schemas/v1/shopify-intent.json",
"value": {
"$ref": "https://extensions.shopifycdn.com/shopifycloud/schemas/v1/shopify/discount/gid.json",
"mapTo": "param",
"fieldName": "id"
},
"inputSchema": {
"type": "object",
"$ref": "https://extensions.shopifycdn.com/shopifycloud/schemas/v1/shopify/discount.json",
"additionalProperties": true,
"properties": {
"functionId": {
"matchValue": "YOUR_FUNCTION_ID"
}
}
},
"outputSchema": {
"type": "object",
"properties": {
"id": {
"$ref": "https://extensions.shopifycdn.com/shopifycloud/schemas/v1/shopify/discount/gid.json"
}
}
}
}
5 changes: 5 additions & 0 deletions docs/reference/shopify/rust/instructions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Use this app when the merchant wants to create or edit a metafield-configured discount powered by this app's Shopify Function.

When invoking `create:shopify/Discount`, pass `functionId: "YOUR_FUNCTION_ID"` so Shopify resolves directly to this app's create flow.

When invoking `edit:shopify/Discount`, pass the discount's GID (default to the canonical `gid://shopify/DiscountNode/{id}`) and `functionId: "YOUR_FUNCTION_ID"` so Shopify resolves the edit directly to this app.
39 changes: 39 additions & 0 deletions docs/reference/shopify/rust/shopify.extension.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,42 @@ key = "function-configuration"
create = "/app/discount/:functionId/new"
details = "/app/discount/:functionId/:id"
# [END discount-function.ui-paths]

# [START discount-function.app-intent-link]
# Register app intent links so Sidekick can create and edit discounts backed by
# this app's Function. Each admin.app.intent.link target maps a shopify/Discount
# action (create or edit) to a page in your app.
[[extensions]]
name = "Create discount"
description = "Create a metafield-configured discount powered by this app's Shopify Function."
handle = "discount-app-intent-link-create"
type = "admin_link"

[[extensions.targeting]]
target = "admin.app.intent.link"
# Hardcode your deployed Function's ID (see "Set your Function ID" below).
url = "/app/discount/YOUR_FUNCTION_ID/new"
instructions = "./instructions.md"

[[extensions.targeting.intents]]
type = "shopify/Discount"
action = "create"
schema = "./create-intent-schema.json"

[[extensions]]
name = "Edit discount"
description = "Edit a metafield-configured discount powered by this app's Shopify Function."
handle = "discount-app-intent-link-edit"
type = "admin_link"

[[extensions.targeting]]
target = "admin.app.intent.link"
# {id} receives the discount ID; the Function ID stays hardcoded.
url = "/app/discount/YOUR_FUNCTION_ID/{id}"
instructions = "./instructions.md"

[[extensions.targeting.intents]]
type = "shopify/Discount"
action = "edit"
schema = "./edit-intent-schema.json"
# [END discount-function.app-intent-link]
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
name: "How to build a combined Discount Function applying 10% off orders, 20% off the most expensive product, and free shipping"
name: 'How to build a combined Discount Function applying 10% off orders, 20% off the most expensive product, and free shipping'
api_name: discount
api_version: 2025-04
api_type: functions
Expand Down
Loading