Skip to content

Update location rules templates to new target #622

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: update-function-templates-2025-07
Choose a base branch
from
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
846 changes: 633 additions & 213 deletions order-routing/javascript/location-rules/default/schema.graphql

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
api_version = "2025-01"
api_version = "2025-07"

[[extensions]]
name = "t:name"
Expand All @@ -8,7 +8,7 @@ type = "function"
description = "t:description"

[[extensions.targeting]]
target = "purchase.order-routing-location-rule.run"
target = "cart.fulfillment-groups.location-rankings.generate.run"
input_query = "src/run.graphql"
export = "run"

Expand Down
12 changes: 6 additions & 6 deletions order-routing/javascript/location-rules/default/src/run.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@

/**
* @typedef {import("../generated/api").RunInput} RunInput
* @typedef {import("../generated/api").FunctionRunResult} FunctionRunResult
* @typedef {import("../generated/api").CartFulfillmentGroupsLocationRankingsGenerateRunResult} CartFulfillmentGroupsLocationRankingsGenerateRunResult
*/

/**
* @param {RunInput} input
* @returns {FunctionRunResult}
* @returns {CartFulfillmentGroupsLocationRankingsGenerateRunResult}
*/
export function run(input) {
const operations = input.fulfillmentGroups.map((group) => {
Expand All @@ -18,7 +18,7 @@ export function run(input) {
})) || [];

return {
rank: {
fulfillment_group_location_ranking_add {
fulfillmentGroupHandle: group.handle,
rankings,
},
Expand All @@ -30,12 +30,12 @@ export function run(input) {
{%- elsif flavor contains "typescript" -%}
import type {
RunInput,
FunctionRunResult,
CartFulfillmentGroupsLocationRankingsGenerateRunResult,
Operation,
RankedLocation,
} from "../generated/api";

export function run(input: RunInput): FunctionRunResult {
export function run(input: RunInput): CartFulfillmentGroupsLocationRankingsGenerateRunResult {
const operations: Operation[] = input.fulfillmentGroups.map((group) => {
const rankings: RankedLocation[] = group.inventoryLocationHandles?.map(
(inventoryLocationHandle) => ({
Expand All @@ -45,7 +45,7 @@ export function run(input: RunInput): FunctionRunResult {
) || [];

return {
rank: {
fulfillment_group_location_ranking_add {
fulfillmentGroupHandle: group.handle,
rankings,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { describe, it, expect } from 'vitest';
import { run } from './run';

/**
* @typedef {import("../generated/api").FunctionRunResult} FunctionRunResult
* @typedef {import("../generated/api").CartFulfillmentGroupsLocationRankingsGenerateRunResult} CartFulfillmentGroupsLocationRankingsGenerateRunResult
*/

describe('order routing location rule function', () => {
Expand All @@ -14,9 +14,9 @@ describe('order routing location rule function', () => {
"inventoryLocationHandles": ["456"]
}]
});
const expected = /** @type {FunctionRunResult} */ ({
const expected = /** @type {CartFulfillmentGroupsLocationRankingsGenerateRunResult} */ ({
operations: [{
rank: {
fulfillment_group_location_ranking_add {
fulfillmentGroupHandle: "123",
rankings: [{
locationHandle: "456",
Expand All @@ -32,7 +32,7 @@ describe('order routing location rule function', () => {
{%- elsif flavor contains "typescript" -%}
import { describe, it, expect } from 'vitest';
import { run } from './run';
import { FunctionRunResult } from '../generated/api';
import { CartFulfillmentGroupsLocationRankingsGenerateRunResult } from '../generated/api';

describe('order routing location rule function', () => {
it('returns rank operations with all locations rank 0', () => {
Expand All @@ -42,9 +42,9 @@ describe('order routing location rule function', () => {
inventoryLocationHandles: ["456"]
}]
});
const expected: FunctionRunResult = {
const expected: CartFulfillmentGroupsLocationRankingsGenerateRunResult = {
operations: [{
rank: {
fulfillment_group_location_ranking_add {
fulfillmentGroupHandle: "123",
rankings: [{
locationHandle: "456",
Expand Down
Loading