From 5c7f072e817c3e369d6b40f35551f191bea5a95d Mon Sep 17 00:00:00 2001 From: Alex Bradley Date: Wed, 23 Apr 2025 16:10:10 -0400 Subject: [PATCH 1/3] use ShopifyFunction global --- run.ts | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/run.ts b/run.ts index a5fadd6..6e437d3 100644 --- a/run.ts +++ b/run.ts @@ -1,23 +1,26 @@ -export type ShopifyFunction = ( +export type UserFunction = ( input: Input ) => Output; -interface Javy { - JSON: { - fromStdin(): any; - toStdout(val: any); - } +interface ShopifyFunction { + readInput(): any; + writeOutput(val: any); } declare global { - const Javy: Javy; + const ShopifyFunction: ShopifyFunction; } -export default function (userfunction: ShopifyFunction) { - if (!Javy.JSON) { - throw new Error('Javy.JSON is not defined. Please rebuild your function using the latest version of Shopify CLI.'); +export default function ( + userfunction: UserFunction +) { + if (!ShopifyFunction) { + throw new Error( + "ShopifyFunction is not defined. Please rebuild your function using the latest version of Shopify CLI." + ); } - const input_obj = Javy.JSON.fromStdin(); + + const input_obj = ShopifyFunction.readInput(); const output_obj = userfunction(input_obj); - Javy.JSON.toStdout(output_obj) + ShopifyFunction.writeOutput(output_obj); } From ee909d619b5d764fd27c41b807620e9ca1d8d50b Mon Sep 17 00:00:00 2001 From: Alex Bradley Date: Fri, 25 Apr 2025 13:08:19 -0400 Subject: [PATCH 2/3] use try/catch to handle undefined global --- run.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/run.ts b/run.ts index 6e437d3..1bc3c50 100644 --- a/run.ts +++ b/run.ts @@ -14,7 +14,9 @@ declare global { export default function ( userfunction: UserFunction ) { - if (!ShopifyFunction) { + try { + ShopifyFunction; + } catch (e) { throw new Error( "ShopifyFunction is not defined. Please rebuild your function using the latest version of Shopify CLI." ); From 1f06878957e2a94d4428c0ca331517f908ead285 Mon Sep 17 00:00:00 2001 From: Alex Bradley Date: Fri, 25 Apr 2025 13:18:30 -0400 Subject: [PATCH 3/3] bump version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 85ea977..c8d2805 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "access": "public", "@shopify:registry": "https://registry.npmjs.org/" }, - "version": "1.0.6", + "version": "2.0.0", "description": "", "main": "index.ts", "keywords": [],