From 7eaea916749a690a6380fef27a123ca5424d60a7 Mon Sep 17 00:00:00 2001 From: Thomas Devisscher Date: Fri, 21 Mar 2025 16:37:45 -0400 Subject: [PATCH] Rename discount schema properties --- .../discount/default/src/discount.test.liquid | 6 +- .../default/src/generate_cart_run.liquid | 16 +- .../default/src/generate_delivery_run.liquid | 12 +- .../default/src/generate_cart_fetch.liquid | 8 +- .../default/src/generate_cart_run.liquid | 8 +- .../src/generate_delivery_fetch.liquid | 8 +- .../default/src/generate_delivery_run.liquid | 8 +- .../network/default/src/network.test.liquid | 10 +- .../rust/discount/default/schema.graphql | 168 +++++++++--------- .../discount/default/src/generate_cart_run.rs | 14 +- .../default/src/generate_delivery_run.rs | 45 ++--- discounts/rust/network/default/schema.graphql | 164 +++++++++-------- .../default/shopify.extension.toml.liquid | 2 +- .../default/src/generate_cart_fetch.rs | 10 +- .../network/default/src/generate_cart_run.rs | 29 +-- .../default/src/generate_delivery_fetch.rs | 10 +- .../default/src/generate_delivery_run.rs | 23 ++- 17 files changed, 276 insertions(+), 265 deletions(-) diff --git a/discounts/javascript/discount/default/src/discount.test.liquid b/discounts/javascript/discount/default/src/discount.test.liquid index 52f2c49e..6b1855b6 100644 --- a/discounts/javascript/discount/default/src/discount.test.liquid +++ b/discounts/javascript/discount/default/src/discount.test.liquid @@ -27,7 +27,7 @@ describe("discount", () => { expect(result.operations.length).toBe(2); expect(result.operations[0]).toMatchObject({ - addOrderDiscounts: { + orderDiscountsAdd: { candidates: [ { message: "10% OFF ORDER", @@ -50,7 +50,7 @@ describe("discount", () => { }); expect(result.operations[1]).toMatchObject({ - addProductDiscounts: { + productDiscountsAdd: { candidates: [ { message: "20% OFF PRODUCT", @@ -88,7 +88,7 @@ describe("discount", () => { expect(result.operations.length).toBe(1); expect(result.operations[0]).toMatchObject({ - addDeliveryDiscounts: { + deliveryDiscountsAdd: { candidates: [ { message: "FREE DELIVERY", diff --git a/discounts/javascript/discount/default/src/generate_cart_run.liquid b/discounts/javascript/discount/default/src/generate_cart_run.liquid index 7fbe2043..a8460324 100644 --- a/discounts/javascript/discount/default/src/generate_cart_run.liquid +++ b/discounts/javascript/discount/default/src/generate_cart_run.liquid @@ -8,13 +8,13 @@ import { /** * @typedef {import("../generated/api").CartInput} CartInput - * @typedef {import("../generated/api").FunctionCartRunResult} FunctionCartRunResult + * @typedef {import("../generated/api").CartLinesDiscountsGenerateRunResult} CartLinesDiscountsGenerateRunResult */ /** * generateCartRun * @param {CartInput} input - The CartInput - * @returns {FunctionCartRunResult} - The function result with discounts. + * @returns {CartLinesDiscountsGenerateRunResult} - The function result with discounts. */ export function generateCartRun(input) { if (!input.cart.lines.length) { @@ -29,7 +29,7 @@ export function generateCartRun(input) { return { operations: [ { - addOrderDiscounts: { + orderDiscountsAdd: { candidates: [ { message: '10% OFF ORDER', @@ -51,7 +51,7 @@ export function generateCartRun(input) { }, }, { - addProductDiscounts: { + productDiscountsAdd: { candidates: [ { message: '20% OFF PRODUCT', @@ -80,10 +80,10 @@ import { OrderDiscountSelectionStrategy, ProductDiscountSelectionStrategy, CartInput, - FunctionCartRunResult, + CartLinesDiscountsGenerateRunResult, } from '../generated/api'; -export function generateCartRun(input: CartInput): FunctionCartRunResult { +export function generateCartRun(input: CartInput): CartLinesDiscountsGenerateRunResult { if (!input.cart.lines.length) { throw new Error('No cart lines found'); } @@ -98,7 +98,7 @@ export function generateCartRun(input: CartInput): FunctionCartRunResult { return { operations: [ { - addOrderDiscounts: { + orderDiscountsAdd: { candidates: [ { message: '10% OFF ORDER', @@ -120,7 +120,7 @@ export function generateCartRun(input: CartInput): FunctionCartRunResult { }, }, { - addProductDiscounts: { + productDiscountsAdd: { candidates: [ { message: '20% OFF PRODUCT', diff --git a/discounts/javascript/discount/default/src/generate_delivery_run.liquid b/discounts/javascript/discount/default/src/generate_delivery_run.liquid index 45a034a9..40ee591d 100644 --- a/discounts/javascript/discount/default/src/generate_delivery_run.liquid +++ b/discounts/javascript/discount/default/src/generate_delivery_run.liquid @@ -5,12 +5,12 @@ import { DeliveryDiscountSelectionStrategy} from '../generated/api'; /** * @typedef {import("../generated/api").DeliveryInput} RunInput - * @typedef {import("../generated/api").FunctionDeliveryRunResult} FunctionDeliveryRunResult + * @typedef {import("../generated/api").CartDeliveryOptionsDiscountsGenerateRunResult} CartDeliveryOptionsDiscountsGenerateRunResult */ /** * generateDeliveryRun * @param {RunInput} input - The DeliveryInput - * @returns {FunctionDeliveryRunResult} - The function result with discounts. + * @returns {CartDeliveryOptionsDiscountsGenerateRunResult} - The function result with discounts. */ export function generateDeliveryRun(input) { const firstDeliveryGroup = input.cart.deliveryGroups[0]; @@ -20,7 +20,7 @@ export function generateDeliveryRun(input) { return { operations: [ { - addDeliveryDiscounts: { + deliveryDiscountsAdd: { candidates: [ { message: 'FREE DELIVERY', @@ -48,12 +48,12 @@ export function generateDeliveryRun(input) { import { DeliveryDiscountSelectionStrategy, DeliveryInput, - FunctionDeliveryRunResult, + CartDeliveryOptionsDiscountsGenerateRunResult, } from '../generated/api'; export function generateDeliveryRun( input: DeliveryInput, -): FunctionDeliveryRunResult { +): CartDeliveryOptionsDiscountsGenerateRunResult { const firstDeliveryGroup = input.cart.deliveryGroups[0]; if (!firstDeliveryGroup) { throw new Error('No delivery groups found'); @@ -62,7 +62,7 @@ export function generateDeliveryRun( return { operations: [ { - addDeliveryDiscounts: { + deliveryDiscountsAdd: { candidates: [ { message: 'FREE DELIVERY', diff --git a/discounts/javascript/network/default/src/generate_cart_fetch.liquid b/discounts/javascript/network/default/src/generate_cart_fetch.liquid index 498ae4a7..efd7694a 100644 --- a/discounts/javascript/network/default/src/generate_cart_fetch.liquid +++ b/discounts/javascript/network/default/src/generate_cart_fetch.liquid @@ -5,12 +5,12 @@ import {HttpRequestMethod} from '../generated/api'; /** * @typedef {import("../generated/api").InputCartFetch} InputCartFetch - * @typedef {import("../generated/api").FunctionCartFetchResult} FunctionCartFetchResult + * @typedef {import("../generated/api").CartLinesDiscountsGenerateFetchResult} CartLinesDiscountsGenerateFetchResult */ /** * Generates a network request to fetch cart discount information * @param {InputCartFetch} input - The cart fetch input data - * @returns {FunctionCartFetchResult} - The function result with network request configuration + * @returns {CartLinesDiscountsGenerateFetchResult} - The function result with network request configuration */ export function generateCartFetch(input) { const { enteredDiscountCodes } = input; @@ -36,12 +36,12 @@ export function generateCartFetch(input) { import { HttpRequestMethod, InputCartFetch, - FunctionCartFetchResult, + CartLinesDiscountsGenerateFetchResult, } from '../generated/api'; export function generateCartFetch( input: InputCartFetch, -): FunctionCartFetchResult { +): CartLinesDiscountsGenerateFetchResult { const {enteredDiscountCodes} = input; const jsonBody = {enteredDiscountCodes}; const request = { diff --git a/discounts/javascript/network/default/src/generate_cart_run.liquid b/discounts/javascript/network/default/src/generate_cart_run.liquid index 04c3ba8d..20d8f859 100644 --- a/discounts/javascript/network/default/src/generate_cart_run.liquid +++ b/discounts/javascript/network/default/src/generate_cart_run.liquid @@ -2,12 +2,12 @@ // @ts-check /** * @typedef {import("../generated/api").InputCartRun} InputCartRun - * @typedef {import("../generated/api").FunctionCartRunResult} FunctionCartRunResult + * @typedef {import("../generated/api").CartLinesDiscountsGenerateRunResult} CartLinesDiscountsGenerateRunResult */ /** * Processes the fetched cart discount data and generates operations * @param {InputCartRun} input - The cart run input data including fetch results - * @returns {FunctionCartRunResult} - The function result with discount operations + * @returns {CartLinesDiscountsGenerateRunResult} - The function result with discount operations */ export function generateCartRun(input) { const { fetchResult } = input; @@ -20,9 +20,9 @@ export function generateCartRun(input) { return { operations }; } {%- elsif flavor contains "typescript" -%} -import {InputCartRun, FunctionCartRunResult} from '../generated/api'; +import {InputCartRun, CartLinesDiscountsGenerateRunResult} from '../generated/api'; -export function generateCartRun(input: InputCartRun): FunctionCartRunResult { +export function generateCartRun(input: InputCartRun): CartLinesDiscountsGenerateRunResult { const {fetchResult} = input; const body = fetchResult?.body; diff --git a/discounts/javascript/network/default/src/generate_delivery_fetch.liquid b/discounts/javascript/network/default/src/generate_delivery_fetch.liquid index c959a69c..9d2dfad0 100644 --- a/discounts/javascript/network/default/src/generate_delivery_fetch.liquid +++ b/discounts/javascript/network/default/src/generate_delivery_fetch.liquid @@ -4,12 +4,12 @@ import {HttpRequestMethod} from '../generated/api'; /** * @typedef {import("../generated/api").InputDeliveryFetch} InputDeliveryFetch - * @typedef {import("../generated/api").FunctionDeliveryFetchResult} FunctionDeliveryFetchResult + * @typedef {import("../generated/api").CartDeliveryOptionsDiscountsGenerateFetchResult} CartDeliveryOptionsDiscountsGenerateFetchResult */ /** * Generates a network request to fetch delivery discount information * @param {InputDeliveryFetch} input - The delivery fetch input data - * @returns {FunctionDeliveryFetchResult} - The function result with network request configuration + * @returns {CartDeliveryOptionsDiscountsGenerateFetchResult} - The function result with network request configuration */ export function generateDeliveryFetch(input) { const { enteredDiscountCodes } = input; @@ -35,11 +35,11 @@ export function generateDeliveryFetch(input) { import { HttpRequestMethod, InputDeliveryFetch, - FunctionDeliveryFetchResult, + CartDeliveryOptionsDiscountsGenerateFetchResult, } from '../generated/api'; export function generateDeliveryFetch( input: InputDeliveryFetch, -): FunctionDeliveryFetchResult { +): CartDeliveryOptionsDiscountsGenerateFetchResult { const {enteredDiscountCodes} = input; const jsonBody = {enteredDiscountCodes}; diff --git a/discounts/javascript/network/default/src/generate_delivery_run.liquid b/discounts/javascript/network/default/src/generate_delivery_run.liquid index 48ec221c..c3544042 100644 --- a/discounts/javascript/network/default/src/generate_delivery_run.liquid +++ b/discounts/javascript/network/default/src/generate_delivery_run.liquid @@ -2,12 +2,12 @@ // @ts-check /** * @typedef {import("../generated/api").InputDeliveryRun} InputDeliveryRun - * @typedef {import("../generated/api").FunctionDeliveryRunResult} FunctionDeliveryRunResult + * @typedef {import("../generated/api").CartDeliveryOptionsDiscountsGenerateRunResult} CartDeliveryOptionsDiscountsGenerateRunResult */ /** * Processes the fetched delivery discount data and generates operations * @param {InputDeliveryRun} input - The delivery run input data including fetch results - * @returns {FunctionDeliveryRunResult} - The function result with discount operations + * @returns {CartDeliveryOptionsDiscountsGenerateRunResult} - The function result with discount operations */ export function generateDeliveryRun(input) { const { fetchResult } = input; @@ -20,11 +20,11 @@ export function generateDeliveryRun(input) { return { operations }; } {%- elsif flavor contains "typescript" -%} -import {InputDeliveryRun, FunctionDeliveryRunResult} from '../generated/api'; +import {InputDeliveryRun, CartDeliveryOptionsDiscountsGenerateRunResult} from '../generated/api'; export function generateDeliveryRun( input: InputDeliveryRun, -): FunctionDeliveryRunResult { +): CartDeliveryOptionsDiscountsGenerateRunResult { const {fetchResult} = input; const body = fetchResult?.body; diff --git a/discounts/javascript/network/default/src/network.test.liquid b/discounts/javascript/network/default/src/network.test.liquid index 2110e7d6..e04c682c 100644 --- a/discounts/javascript/network/default/src/network.test.liquid +++ b/discounts/javascript/network/default/src/network.test.liquid @@ -62,12 +62,12 @@ describe("discount", () => { it("cart.lines.discounts.generate.run returns a list of operations", () => { const operations = [ { - addDiscountCodeValidations: { + enteredDiscountCodesAccept: { codes: ["10% OFF ORDER", "20% OFF PRODUCT"], }, }, { - addOrderDiscounts: { + orderDiscountsAdd: { candidates: [ { message: "10% OFF ORDER", @@ -89,7 +89,7 @@ describe("discount", () => { }, }, { - addProductDiscounts: { + productDiscountsAdd: { candidates: [ { message: "20% OFF PRODUCT", @@ -126,12 +126,12 @@ describe("discount", () => { it("cart.delivery-options.discounts.generate.run returns a list of operations", () => { const operations = [ { - addDiscountCodeValidations: { + enteredDiscountCodesAccept: { codes: ["FREE_DELIVERY"], }, }, { - addDeliveryDiscounts: { + deliveryDiscountsAdd: { candidates: [ { message: "FREE DELIVERY", diff --git a/discounts/rust/discount/default/schema.graphql b/discounts/rust/discount/default/schema.graphql index 2c2f866b..524ae957 100644 --- a/discounts/rust/discount/default/schema.graphql +++ b/discounts/rust/discount/default/schema.graphql @@ -213,6 +213,27 @@ type CartDeliveryOption { title: String } +""" +The cart.delivery-options.discounts.generate.fetch target result. Refer to +[network access](https://shopify.dev/apps/build/functions/input-output/network-access/graphql) for Shopify Functions. +""" +input CartDeliveryOptionsDiscountsGenerateFetchResult { + """ + The http request. + """ + request: HttpRequest +} + +""" +The cart.delivery-options.discounts.generate.run target result. +""" +input CartDeliveryOptionsDiscountsGenerateRunResult { + """ + The list of operations to apply discounts to the delivery lines. + """ + operations: [DeliveryOperation!]! +} + """ Represents information about the merchandise in the cart. """ @@ -332,25 +353,46 @@ input CartLineTarget { quantity: Int } +""" +The cart.lines.discounts.generate.fetch target result. Refer to [network access] +(https://shopify.dev/apps/build/functions/input-output/network-access/graphql) for Shopify Functions. +""" +input CartLinesDiscountsGenerateFetchResult { + """ + The http request. + """ + request: HttpRequest +} + +""" +The cart.lines.discounts.generate.run target result. +""" +input CartLinesDiscountsGenerateRunResult { + """ + The list of operations to apply discounts to the cart. + """ + operations: [CartOperation!]! +} + """ The operations that can be performed to apply discounts to the cart. """ input CartOperation @oneOf { """ - A list of valid discount codes that correspond to external discounts. This can - only be used by Functions with network access. + An operation that selects which entered discount codes to accept. Use this to + validate discount codes from external systems. """ - addDiscountCodeValidations: ValidDiscountCodes + enteredDiscountCodesAccept: EnteredDiscountCodesAcceptOperation """ - A group of order discounts that share a selection strategy. + An operation that applies order discounts to a cart that share a selection strategy. """ - addOrderDiscounts: OrderDiscounts + orderDiscountsAdd: OrderDiscountsAddOperation """ - A group of product discounts that share a selection strategy. + An operation that applies product discounts to a cart that share a selection strategy. """ - addProductDiscounts: ProductDiscounts + productDiscountsAdd: ProductDiscountsAddOperation } """ @@ -2805,9 +2847,9 @@ enum DeliveryDiscountSelectionStrategy { } """ -A group of delivery discounts that share a selection strategy. +An operation that applies delivery discounts to a cart that share a selection strategy. """ -input DeliveryDiscounts { +input DeliveryDiscountsAddOperation { """ The list of delivery discount candidates to be applied. """ @@ -2869,15 +2911,15 @@ The operations that can be performed to apply discounts to the delivery lines. """ input DeliveryOperation @oneOf { """ - A group of delivery discounts that share a selection strategy. + An operation that applies delivery discounts to a cart that share a selection strategy. """ - addDeliveryDiscounts: DeliveryDiscounts + deliveryDiscountsAdd: DeliveryDiscountsAddOperation """ - A list of valid discount codes that correspond to external discounts. This can - only be used by Functions with network access. + An operation that selects which entered discount codes to accept. Use this to + validate discount codes from external systems. """ - addDiscountCodeValidations: ValidDiscountCodes + enteredDiscountCodesAccept: EnteredDiscountCodesAcceptOperation } """ @@ -2943,57 +2985,35 @@ enum DiscountClass { } """ -A fixed amount value. -""" -input FixedAmount { - """ - The fixed amount value of the discount, in the currency of the cart. - - The amount must be greater than or equal to 0. - """ - amount: Decimal! -} - -""" -The cart.fetch target result. Refer to [network access] -(https://shopify.dev/apps/build/functions/input-output/network-access/graphql) for Shopify Functions. +A discount code used by the buyer to add a discount to the cart. """ -input FunctionCartFetchResult { +input DiscountCode { """ - The http request. + The discount code. """ - request: HttpRequest + code: String! } """ -The cart.run target result. +An operation that selects which entered discount codes to accept. Use this to validate discount codes from external systems. """ -input FunctionCartRunResult { +input EnteredDiscountCodesAcceptOperation { """ - The list of operations to apply discounts to the cart. + The list of discount codes to accept. """ - operations: [CartOperation!]! + codes: [DiscountCode!]! } """ -The delivery.fetch target result. Refer to -[network access](https://shopify.dev/apps/build/functions/input-output/network-access/graphql) for Shopify Functions. +A fixed amount value. """ -input FunctionDeliveryFetchResult { - """ - The http request. +input FixedAmount { """ - request: HttpRequest -} + The fixed amount value of the discount, in the currency of the cart. -""" -The delivery.run target result. -""" -input FunctionDeliveryRunResult { - """ - The list of operations to apply discounts to the delivery lines. + The amount must be greater than or equal to 0. """ - operations: [DeliveryOperation!]! + amount: Decimal! } """ @@ -3070,7 +3090,7 @@ interface HasGates { The handle of the gate configurations to search for. """ handle: Handle - ): [GateSubject!]! + ): [GateSubject!]! @deprecated(reason: "Gates API is being sunset and will be removed in a future version. Use `metafields` instead for gate configuration.") } """ @@ -3216,9 +3236,9 @@ type HttpResponse { headers: [HttpResponseHeader!]! @deprecated(reason: "Use `header` instead.") """ - The HTTP response body parsed as JSON. - If the body is valid JSON, it will be parsed and returned as a JSON object. - If parsing fails, then raw body is returned as a string. + The HTTP response body parsed as JSON. + If the body is valid JSON, it will be parsed and returned as a JSON object. + If parsing fails, then raw body is returned as a string. Use this field when you expect the response to be JSON, or when you're dealing with mixed response types, meaning both JSON and non-JSON. Using this field reduces function instruction consumption and ensures that the data is formatted in logs. @@ -4552,7 +4572,7 @@ type MutationRoot { """ The result of the Function. """ - result: FunctionDeliveryFetchResult! + result: CartDeliveryOptionsDiscountsGenerateFetchResult! ): Void! """ @@ -4562,7 +4582,7 @@ type MutationRoot { """ The result of the Function. """ - result: FunctionDeliveryRunResult! + result: CartDeliveryOptionsDiscountsGenerateRunResult! ): Void! """ @@ -4572,7 +4592,7 @@ type MutationRoot { """ The result of the Function. """ - result: FunctionCartFetchResult! + result: CartLinesDiscountsGenerateFetchResult! ): Void! """ @@ -4582,7 +4602,7 @@ type MutationRoot { """ The result of the Function. """ - result: FunctionCartRunResult! + result: CartLinesDiscountsGenerateRunResult! ): Void! } @@ -4657,9 +4677,9 @@ enum OrderDiscountSelectionStrategy { } """ -A group of order discounts that share a selection strategy. +An operation that applies order discounts to a cart that share a selection strategy. """ -input OrderDiscounts { +input OrderDiscountsAddOperation { """ The list of order discount candidates to be applied. """ @@ -4721,7 +4741,7 @@ type Product implements HasGates & HasMetafields { The handle of the gate configurations to search for. """ handle: Handle - ): [GateSubject!]! + ): [GateSubject!]! @deprecated(reason: "Gates API is being sunset and will be removed in a future version. Use `metafields` instead for gate configuration.") """ A unique human-friendly string of the product's title. @@ -4860,7 +4880,7 @@ A target of a product discount candidate, which determines which cart line(s) th Multiple targets with the same type and ID are the same as a single target of that type and ID with their quantities added together, or `null` if any of those targets have a quantity of `null`. -See the [Discounts API reference](https://shopify.dev/docs/api/functions/reference/product-discounts/graphql#functionrunresult) for examples. +See the [Discounts API reference](https://shopify.dev/docs/api/functions/reference/discount/graphql/functioncartrunresult) for examples. """ input ProductDiscountCandidateTarget @oneOf { """ @@ -4906,9 +4926,9 @@ enum ProductDiscountSelectionStrategy { } """ -A group of product discounts that share a selection strategy. +An operation that applies product discounts to a cart that share a selection strategy. """ -input ProductDiscounts { +input ProductDiscountsAddOperation { """ The list of product discount candidates to be applied. """ @@ -5119,28 +5139,6 @@ For example, `"https://example.myshopify.com"` is a valid URL. It includes a sch """ scalar URL -""" -A discount code that corresponds to a valid external discount. -This can only be used by Functions with network access. -""" -input ValidDiscountCode { - """ - The discount code. - """ - code: String! -} - -""" -A list of valid discount codes that correspond to external discounts. This can -only be used by Functions with network access. -""" -input ValidDiscountCodes { - """ - The list of valid discount codes. - """ - codes: [ValidDiscountCode!]! -} - """ A void type that can be used to return a null value from a mutation. """ diff --git a/discounts/rust/discount/default/src/generate_cart_run.rs b/discounts/rust/discount/default/src/generate_cart_run.rs index 5318921b..90557c36 100644 --- a/discounts/rust/discount/default/src/generate_cart_run.rs +++ b/discounts/rust/discount/default/src/generate_cart_run.rs @@ -2,11 +2,11 @@ use shopify_function::prelude::*; use shopify_function::Result; use cart_lines_discounts_generate_run::output::{ - CartLineTarget, CartOperation, FunctionCartRunResult, OrderDiscountCandidate, + CartLineTarget, CartLinesDiscountsGenerateRunResult, CartOperation, OrderDiscountCandidate, OrderDiscountCandidateTarget, OrderDiscountCandidateValue, OrderDiscountSelectionStrategy, - OrderDiscounts, OrderSubtotalTarget, Percentage, ProductDiscountCandidate, + OrderDiscountsAddOperation, OrderSubtotalTarget, Percentage, ProductDiscountCandidate, ProductDiscountCandidateTarget, ProductDiscountCandidateValue, - ProductDiscountSelectionStrategy, ProductDiscounts, + ProductDiscountSelectionStrategy, ProductDiscountsAddOperation, }; use cart_lines_discounts_generate_run::input::ResponseData; @@ -16,7 +16,7 @@ use cart_lines_discounts_generate_run::input::ResponseData; query_path = "src/generate_cart_run.graphql", schema_path = "schema.graphql" )] -fn generate_cart_run(input: ResponseData) -> Result { +fn generate_cart_run(input: ResponseData) -> Result { let max_cart_line = input .cart .lines @@ -30,9 +30,9 @@ fn generate_cart_run(input: ResponseData) -> Result { }) .ok_or("No cart lines found")?; - Ok(FunctionCartRunResult { + Ok(CartLinesDiscountsGenerateRunResult { operations: vec![ - CartOperation::AddOrderDiscounts(OrderDiscounts { + CartOperation::OrderDiscountsAdd(OrderDiscountsAddOperation { selection_strategy: OrderDiscountSelectionStrategy::FIRST, candidates: vec![OrderDiscountCandidate { targets: vec![OrderDiscountCandidateTarget::OrderSubtotal( @@ -48,7 +48,7 @@ fn generate_cart_run(input: ResponseData) -> Result { associated_discount_code: None, }], }), - CartOperation::AddProductDiscounts(ProductDiscounts { + CartOperation::ProductDiscountsAdd(ProductDiscountsAddOperation { selection_strategy: ProductDiscountSelectionStrategy::FIRST, candidates: vec![ProductDiscountCandidate { targets: vec![ProductDiscountCandidateTarget::CartLine(CartLineTarget { diff --git a/discounts/rust/discount/default/src/generate_delivery_run.rs b/discounts/rust/discount/default/src/generate_delivery_run.rs index 6575c467..b2792691 100644 --- a/discounts/rust/discount/default/src/generate_delivery_run.rs +++ b/discounts/rust/discount/default/src/generate_delivery_run.rs @@ -2,9 +2,10 @@ use shopify_function::prelude::*; use shopify_function::Result; use cart_delivery_options_discounts_generate_run::output::{ - DeliveryDiscountCandidate, DeliveryDiscountCandidateTarget, DeliveryDiscountCandidateValue, - DeliveryDiscountSelectionStrategy, DeliveryDiscounts, DeliveryGroupTarget, DeliveryOperation, - FunctionDeliveryRunResult, Percentage, + CartDeliveryOptionsDiscountsGenerateRunResult, DeliveryDiscountCandidate, + DeliveryDiscountCandidateTarget, DeliveryDiscountCandidateValue, + DeliveryDiscountSelectionStrategy, DeliveryDiscountsAddOperation, DeliveryGroupTarget, + DeliveryOperation, Percentage, }; use cart_delivery_options_discounts_generate_run::input::ResponseData; @@ -14,28 +15,32 @@ use cart_delivery_options_discounts_generate_run::input::ResponseData; query_path = "src/generate_delivery_run.graphql", schema_path = "schema.graphql" )] -fn generate_delivery_run(input: ResponseData) -> Result { +fn generate_delivery_run( + input: ResponseData, +) -> Result { let first_delivery_group = input .cart .delivery_groups .first() .ok_or("No delivery groups found")?; - Ok(FunctionDeliveryRunResult { - operations: vec![DeliveryOperation::AddDeliveryDiscounts(DeliveryDiscounts { - selection_strategy: DeliveryDiscountSelectionStrategy::ALL, - candidates: vec![DeliveryDiscountCandidate { - targets: vec![DeliveryDiscountCandidateTarget::DeliveryGroup( - DeliveryGroupTarget { - id: first_delivery_group.id.clone(), - }, - )], - value: DeliveryDiscountCandidateValue::Percentage(Percentage { - value: Decimal(100.0), - }), - message: Some("FREE DELIVERY".to_string()), - associated_discount_code: None, - }], - })], + Ok(CartDeliveryOptionsDiscountsGenerateRunResult { + operations: vec![DeliveryOperation::DeliveryDiscountsAdd( + DeliveryDiscountsAddOperation { + selection_strategy: DeliveryDiscountSelectionStrategy::ALL, + candidates: vec![DeliveryDiscountCandidate { + targets: vec![DeliveryDiscountCandidateTarget::DeliveryGroup( + DeliveryGroupTarget { + id: first_delivery_group.id.clone(), + }, + )], + value: DeliveryDiscountCandidateValue::Percentage(Percentage { + value: Decimal(100.0), + }), + message: Some("FREE DELIVERY".to_string()), + associated_discount_code: None, + }], + }, + )], }) } diff --git a/discounts/rust/network/default/schema.graphql b/discounts/rust/network/default/schema.graphql index 751e21de..524ae957 100644 --- a/discounts/rust/network/default/schema.graphql +++ b/discounts/rust/network/default/schema.graphql @@ -213,6 +213,27 @@ type CartDeliveryOption { title: String } +""" +The cart.delivery-options.discounts.generate.fetch target result. Refer to +[network access](https://shopify.dev/apps/build/functions/input-output/network-access/graphql) for Shopify Functions. +""" +input CartDeliveryOptionsDiscountsGenerateFetchResult { + """ + The http request. + """ + request: HttpRequest +} + +""" +The cart.delivery-options.discounts.generate.run target result. +""" +input CartDeliveryOptionsDiscountsGenerateRunResult { + """ + The list of operations to apply discounts to the delivery lines. + """ + operations: [DeliveryOperation!]! +} + """ Represents information about the merchandise in the cart. """ @@ -332,25 +353,46 @@ input CartLineTarget { quantity: Int } +""" +The cart.lines.discounts.generate.fetch target result. Refer to [network access] +(https://shopify.dev/apps/build/functions/input-output/network-access/graphql) for Shopify Functions. +""" +input CartLinesDiscountsGenerateFetchResult { + """ + The http request. + """ + request: HttpRequest +} + +""" +The cart.lines.discounts.generate.run target result. +""" +input CartLinesDiscountsGenerateRunResult { + """ + The list of operations to apply discounts to the cart. + """ + operations: [CartOperation!]! +} + """ The operations that can be performed to apply discounts to the cart. """ input CartOperation @oneOf { """ - A list of valid discount codes that correspond to external discounts. This can - only be used by Functions with network access. + An operation that selects which entered discount codes to accept. Use this to + validate discount codes from external systems. """ - addDiscountCodeValidations: ValidDiscountCodes + enteredDiscountCodesAccept: EnteredDiscountCodesAcceptOperation """ - A group of order discounts that share a selection strategy. + An operation that applies order discounts to a cart that share a selection strategy. """ - addOrderDiscounts: OrderDiscounts + orderDiscountsAdd: OrderDiscountsAddOperation """ - A group of product discounts that share a selection strategy. + An operation that applies product discounts to a cart that share a selection strategy. """ - addProductDiscounts: ProductDiscounts + productDiscountsAdd: ProductDiscountsAddOperation } """ @@ -2805,9 +2847,9 @@ enum DeliveryDiscountSelectionStrategy { } """ -A group of delivery discounts that share a selection strategy. +An operation that applies delivery discounts to a cart that share a selection strategy. """ -input DeliveryDiscounts { +input DeliveryDiscountsAddOperation { """ The list of delivery discount candidates to be applied. """ @@ -2869,15 +2911,15 @@ The operations that can be performed to apply discounts to the delivery lines. """ input DeliveryOperation @oneOf { """ - A group of delivery discounts that share a selection strategy. + An operation that applies delivery discounts to a cart that share a selection strategy. """ - addDeliveryDiscounts: DeliveryDiscounts + deliveryDiscountsAdd: DeliveryDiscountsAddOperation """ - A list of valid discount codes that correspond to external discounts. This can - only be used by Functions with network access. + An operation that selects which entered discount codes to accept. Use this to + validate discount codes from external systems. """ - addDiscountCodeValidations: ValidDiscountCodes + enteredDiscountCodesAccept: EnteredDiscountCodesAcceptOperation } """ @@ -2943,57 +2985,35 @@ enum DiscountClass { } """ -A fixed amount value. -""" -input FixedAmount { - """ - The fixed amount value of the discount, in the currency of the cart. - - The amount must be greater than or equal to 0. - """ - amount: Decimal! -} - -""" -The cart.fetch target result. Refer to [network access] -(https://shopify.dev/apps/build/functions/input-output/network-access/graphql) for Shopify Functions. +A discount code used by the buyer to add a discount to the cart. """ -input FunctionCartFetchResult { +input DiscountCode { """ - The http request. + The discount code. """ - request: HttpRequest + code: String! } """ -The cart.run target result. +An operation that selects which entered discount codes to accept. Use this to validate discount codes from external systems. """ -input FunctionCartRunResult { +input EnteredDiscountCodesAcceptOperation { """ - The list of operations to apply discounts to the cart. + The list of discount codes to accept. """ - operations: [CartOperation!]! + codes: [DiscountCode!]! } """ -The delivery.fetch target result. Refer to -[network access](https://shopify.dev/apps/build/functions/input-output/network-access/graphql) for Shopify Functions. +A fixed amount value. """ -input FunctionDeliveryFetchResult { - """ - The http request. +input FixedAmount { """ - request: HttpRequest -} + The fixed amount value of the discount, in the currency of the cart. -""" -The delivery.run target result. -""" -input FunctionDeliveryRunResult { - """ - The list of operations to apply discounts to the delivery lines. + The amount must be greater than or equal to 0. """ - operations: [DeliveryOperation!]! + amount: Decimal! } """ @@ -3216,9 +3236,9 @@ type HttpResponse { headers: [HttpResponseHeader!]! @deprecated(reason: "Use `header` instead.") """ - The HTTP response body parsed as JSON. - If the body is valid JSON, it will be parsed and returned as a JSON object. - If parsing fails, then raw body is returned as a string. + The HTTP response body parsed as JSON. + If the body is valid JSON, it will be parsed and returned as a JSON object. + If parsing fails, then raw body is returned as a string. Use this field when you expect the response to be JSON, or when you're dealing with mixed response types, meaning both JSON and non-JSON. Using this field reduces function instruction consumption and ensures that the data is formatted in logs. @@ -4552,7 +4572,7 @@ type MutationRoot { """ The result of the Function. """ - result: FunctionDeliveryFetchResult! + result: CartDeliveryOptionsDiscountsGenerateFetchResult! ): Void! """ @@ -4562,7 +4582,7 @@ type MutationRoot { """ The result of the Function. """ - result: FunctionDeliveryRunResult! + result: CartDeliveryOptionsDiscountsGenerateRunResult! ): Void! """ @@ -4572,7 +4592,7 @@ type MutationRoot { """ The result of the Function. """ - result: FunctionCartFetchResult! + result: CartLinesDiscountsGenerateFetchResult! ): Void! """ @@ -4582,7 +4602,7 @@ type MutationRoot { """ The result of the Function. """ - result: FunctionCartRunResult! + result: CartLinesDiscountsGenerateRunResult! ): Void! } @@ -4657,9 +4677,9 @@ enum OrderDiscountSelectionStrategy { } """ -A group of order discounts that share a selection strategy. +An operation that applies order discounts to a cart that share a selection strategy. """ -input OrderDiscounts { +input OrderDiscountsAddOperation { """ The list of order discount candidates to be applied. """ @@ -4860,7 +4880,7 @@ A target of a product discount candidate, which determines which cart line(s) th Multiple targets with the same type and ID are the same as a single target of that type and ID with their quantities added together, or `null` if any of those targets have a quantity of `null`. -See the [Discounts API reference](https://shopify.dev/docs/api/functions/reference/product-discounts/graphql#functionrunresult) for examples. +See the [Discounts API reference](https://shopify.dev/docs/api/functions/reference/discount/graphql/functioncartrunresult) for examples. """ input ProductDiscountCandidateTarget @oneOf { """ @@ -4906,9 +4926,9 @@ enum ProductDiscountSelectionStrategy { } """ -A group of product discounts that share a selection strategy. +An operation that applies product discounts to a cart that share a selection strategy. """ -input ProductDiscounts { +input ProductDiscountsAddOperation { """ The list of product discount candidates to be applied. """ @@ -5119,28 +5139,6 @@ For example, `"https://example.myshopify.com"` is a valid URL. It includes a sch """ scalar URL -""" -A discount code that corresponds to a valid external discount. -This can only be used by Functions with network access. -""" -input ValidDiscountCode { - """ - The discount code. - """ - code: String! -} - -""" -A list of valid discount codes that correspond to external discounts. This can -only be used by Functions with network access. -""" -input ValidDiscountCodes { - """ - The list of valid discount codes. - """ - codes: [ValidDiscountCode!]! -} - """ A void type that can be used to return a null value from a mutation. """ diff --git a/discounts/rust/network/default/shopify.extension.toml.liquid b/discounts/rust/network/default/shopify.extension.toml.liquid index 952d7117..3a657001 100644 --- a/discounts/rust/network/default/shopify.extension.toml.liquid +++ b/discounts/rust/network/default/shopify.extension.toml.liquid @@ -29,5 +29,5 @@ description = "t:description" [extensions.build] command = "cargo build --target=wasm32-wasip1 --release" - path = "{{handle | replace: " ", "-" | downcase}}.wasm" + path = "target/wasm32-wasip1/release/{{handle | replace: " ", "-" | downcase}}.wasm" watch = [ "src/**/*.rs" ] diff --git a/discounts/rust/network/default/src/generate_cart_fetch.rs b/discounts/rust/network/default/src/generate_cart_fetch.rs index 82548256..b1ce3ca5 100644 --- a/discounts/rust/network/default/src/generate_cart_fetch.rs +++ b/discounts/rust/network/default/src/generate_cart_fetch.rs @@ -4,7 +4,7 @@ use shopify_function::prelude::*; use cart_lines_discounts_generate_fetch::input::ResponseData as CartFetchResponseData; use cart_lines_discounts_generate_fetch::output::{ - FunctionCartFetchResult, HttpRequest as CartFetchHttpRequest, + CartLinesDiscountsGenerateFetchResult, HttpRequest as CartFetchHttpRequest, HttpRequestHeader as CartFetchHttpRequestHeader, HttpRequestMethod as CartFetchHttpRequestMethod, HttpRequestPolicy as CartFetchHttpRequestPolicy, @@ -17,7 +17,7 @@ use cart_lines_discounts_generate_fetch::output::{ )] fn generate_cart_fetch( input: CartFetchResponseData, -) -> shopify_function::Result { +) -> shopify_function::Result { let entered_discount_codes = &input.entered_discount_codes; let json_body = json!({ "enteredDiscountCodes": entered_discount_codes }); @@ -41,7 +41,7 @@ fn generate_cart_fetch( json_body: Some(json_body.clone()), }; - Ok(FunctionCartFetchResult { + Ok(CartLinesDiscountsGenerateFetchResult { request: Some(request), }) } @@ -50,7 +50,7 @@ fn generate_cart_fetch( mod tests { use super::*; use cart_lines_discounts_generate_fetch::output::{ - FunctionCartFetchResult, HttpRequest as CartFetchHttpRequest, + CartLinesDiscountsGenerateFetchResult, HttpRequest as CartFetchHttpRequest, HttpRequestHeader as CartFetchHttpRequestHeader, HttpRequestMethod as CartFetchHttpRequestMethod, HttpRequestPolicy as CartFetchHttpRequestPolicy, @@ -63,7 +63,7 @@ mod tests { let result = run_function_with_input(generate_cart_fetch, &input)?; let json_body = json!({ "enteredDiscountCodes": [] }); - let expected = FunctionCartFetchResult { + let expected = CartLinesDiscountsGenerateFetchResult { request: Some(CartFetchHttpRequest { headers: vec![ CartFetchHttpRequestHeader { diff --git a/discounts/rust/network/default/src/generate_cart_run.rs b/discounts/rust/network/default/src/generate_cart_run.rs index 5d28447a..1852446d 100644 --- a/discounts/rust/network/default/src/generate_cart_run.rs +++ b/discounts/rust/network/default/src/generate_cart_run.rs @@ -3,7 +3,8 @@ use shopify_function::prelude::*; use shopify_function::Result; use cart_lines_discounts_generate_run::output::{ - CartOperation, FunctionCartRunResult, OrderDiscounts, ProductDiscounts, ValidDiscountCodes, + CartLinesDiscountsGenerateRunResult, CartOperation, EnteredDiscountCodesAcceptOperation, + OrderDiscountsAddOperation, ProductDiscountsAddOperation, }; use cart_lines_discounts_generate_run::input::ResponseData; @@ -12,11 +13,11 @@ use cart_lines_discounts_generate_run::input::ResponseData; #[serde(rename_all = "camelCase")] struct OperationItem { #[serde(default)] - add_product_discounts: Option, + product_discounts_add: Option, #[serde(default)] - add_order_discounts: Option, + order_discounts_add: Option, #[serde(default)] - add_discount_code_validations: Option, + entered_discount_codes_accept: Option, // Ignore other operation types that might be in the response but we don't use in cart context #[serde(flatten)] _other: std::collections::HashMap, @@ -27,7 +28,7 @@ struct OperationItem { query_path = "src/generate_cart_run.graphql", schema_path = "schema.graphql" )] -fn generate_cart_run(input: ResponseData) -> Result { +fn generate_cart_run(input: ResponseData) -> Result { let fetch_result = input.fetch_result.ok_or("Missing fetch result")?; // Use jsonBody which is the only available property @@ -44,19 +45,23 @@ fn generate_cart_run(input: ResponseData) -> Result { // Process each operation item for item in operation_items { - if let Some(validations) = item.add_discount_code_validations { - operations.push(CartOperation::AddDiscountCodeValidations(validations)); + if let Some(validations) = item.entered_discount_codes_accept { + operations.push(CartOperation::EnteredDiscountCodesAccept(validations)); } - if let Some(product_discounts) = item.add_product_discounts { - operations.push(CartOperation::AddProductDiscounts(product_discounts)); + if let Some(product_discounts_add_operation) = item.product_discounts_add { + operations.push(CartOperation::ProductDiscountsAdd( + product_discounts_add_operation, + )); } - if let Some(order_discounts) = item.add_order_discounts { - operations.push(CartOperation::AddOrderDiscounts(order_discounts)); + if let Some(order_discounts_add_operation) = item.order_discounts_add { + operations.push(CartOperation::OrderDiscountsAdd( + order_discounts_add_operation, + )); } // Ignore delivery discounts for cart operations } - Ok(FunctionCartRunResult { operations }) + Ok(CartLinesDiscountsGenerateRunResult { operations }) } diff --git a/discounts/rust/network/default/src/generate_delivery_fetch.rs b/discounts/rust/network/default/src/generate_delivery_fetch.rs index 11735ab5..741c723f 100644 --- a/discounts/rust/network/default/src/generate_delivery_fetch.rs +++ b/discounts/rust/network/default/src/generate_delivery_fetch.rs @@ -4,7 +4,7 @@ use shopify_function::prelude::*; use cart_delivery_options_discounts_generate_fetch::input::ResponseData as DeliveryFetchResponseData; use cart_delivery_options_discounts_generate_fetch::output::{ - FunctionDeliveryFetchResult, HttpRequest as DeliveryFetchHttpRequest, + CartDeliveryOptionsDiscountsGenerateFetchResult, HttpRequest as DeliveryFetchHttpRequest, HttpRequestHeader as DeliveryFetchHttpRequestHeader, HttpRequestMethod as DeliveryFetchHttpRequestMethod, HttpRequestPolicy as DeliveryFetchHttpRequestPolicy, @@ -17,7 +17,7 @@ use cart_delivery_options_discounts_generate_fetch::output::{ )] fn generate_delivery_fetch( input: DeliveryFetchResponseData, -) -> shopify_function::Result { +) -> shopify_function::Result { let entered_discount_codes = &input.entered_discount_codes; let json_body = json!({ "enteredDiscountCodes": entered_discount_codes }); @@ -41,7 +41,7 @@ fn generate_delivery_fetch( json_body: Some(json_body.clone()), }; - Ok(FunctionDeliveryFetchResult { + Ok(CartDeliveryOptionsDiscountsGenerateFetchResult { request: Some(request), }) } @@ -50,7 +50,7 @@ fn generate_delivery_fetch( mod tests { use super::*; use cart_delivery_options_discounts_generate_fetch::output::{ - FunctionDeliveryFetchResult, HttpRequest as DeliveryFetchHttpRequest, + CartDeliveryOptionsDiscountsGenerateFetchResult, HttpRequest as DeliveryFetchHttpRequest, HttpRequestHeader as DeliveryFetchHttpRequestHeader, HttpRequestMethod as DeliveryFetchHttpRequestMethod, HttpRequestPolicy as DeliveryFetchHttpRequestPolicy, @@ -63,7 +63,7 @@ mod tests { let result = run_function_with_input(generate_delivery_fetch, &input)?; let json_body = json!({ "enteredDiscountCodes": ["ABC"] }); - let expected = FunctionDeliveryFetchResult { + let expected = CartDeliveryOptionsDiscountsGenerateFetchResult { request: Some(DeliveryFetchHttpRequest { headers: vec![ DeliveryFetchHttpRequestHeader { diff --git a/discounts/rust/network/default/src/generate_delivery_run.rs b/discounts/rust/network/default/src/generate_delivery_run.rs index f590da3e..c7415e57 100644 --- a/discounts/rust/network/default/src/generate_delivery_run.rs +++ b/discounts/rust/network/default/src/generate_delivery_run.rs @@ -3,7 +3,8 @@ use shopify_function::prelude::*; use shopify_function::Result; use cart_delivery_options_discounts_generate_run::output::{ - DeliveryDiscounts, DeliveryOperation, FunctionDeliveryRunResult, ValidDiscountCodes, + CartDeliveryOptionsDiscountsGenerateRunResult, DeliveryDiscountsAddOperation, + DeliveryOperation, EnteredDiscountCodesAcceptOperation, }; use cart_delivery_options_discounts_generate_run::input::ResponseData; @@ -12,9 +13,9 @@ use cart_delivery_options_discounts_generate_run::input::ResponseData; #[serde(rename_all = "camelCase")] struct OperationItem { #[serde(default)] - add_delivery_discounts: Option, + delivery_discounts_add: Option, #[serde(default)] - add_discount_code_validations: Option, + entered_discount_codes_accept: Option, // Ignore any other fields we don't need #[serde(flatten)] _other: std::collections::HashMap, @@ -25,7 +26,9 @@ struct OperationItem { query_path = "src/generate_delivery_run.graphql", schema_path = "schema.graphql" )] -fn generate_delivery_run(input: ResponseData) -> Result { +fn generate_delivery_run( + input: ResponseData, +) -> Result { let fetch_result = input.fetch_result.ok_or("Missing fetch result")?; // Use jsonBody which is the only available property @@ -42,15 +45,17 @@ fn generate_delivery_run(input: ResponseData) -> Result