Skip to content
Merged
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [],
Expand Down
29 changes: 17 additions & 12 deletions run.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,28 @@
export type ShopifyFunction<Input extends {}, Output extends {}> = (
export type UserFunction<Input extends {}, Output extends {}> = (
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 <I extends {}, O extends {}>(userfunction: ShopifyFunction<I, O>) {
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 <I extends {}, O extends {}>(
userfunction: UserFunction<I, O>
) {
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);
}