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": [], diff --git a/run.ts b/run.ts index a5fadd6..1bc3c50 100644 --- a/run.ts +++ b/run.ts @@ -1,23 +1,28 @@ -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 +) { + try { + ShopifyFunction; + } catch (e) { + 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); }