@shopify/shopify_function 0.0.3 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,22 @@
1
+ name: Contributor License Agreement (CLA)
2
+
3
+ on:
4
+ pull_request_target:
5
+ types: [opened, synchronize]
6
+ issue_comment:
7
+ types: [created]
8
+
9
+ jobs:
10
+ cla:
11
+ runs-on: ubuntu-latest
12
+ if: |
13
+ (github.event.issue.pull_request
14
+ && !github.event.issue.pull_request.merged_at
15
+ && contains(github.event.comment.body, 'signed')
16
+ )
17
+ || (github.event.pull_request && !github.event.pull_request.merged)
18
+ steps:
19
+ - uses: Shopify/shopify-cla-action@v1
20
+ with:
21
+ github-token: ${{ secrets.GITHUB_TOKEN }}
22
+ cla-token: ${{ secrets.CLA_TOKEN }}
package/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  # Shopify Function JavaScript
2
2
 
3
- This repository contains the source code for the [`@shopify/shopify-function`][package] npm package.
3
+ This repository contains the source code for the [`@shopify/shopify_function`][package] npm package.
4
4
 
5
- [package]: https://npm.im/@shopify/shopify-function
5
+ [package]: https://npm.im/@shopify/shopify_function
package/index.ts CHANGED
@@ -1,16 +1,5 @@
1
- import * as fs from "javy/fs";
2
-
3
1
  // This package name will be aliased to the file provided by the user.
4
2
  import * as userFunction from "user-function";
3
+ import run from "./run";
5
4
 
6
- export type ShopifyFunction<Input extends {}, Output extends {}> = (
7
- input: Input
8
- ) => Output;
9
-
10
- const input_data = fs.readFileSync(fs.STDIO.Stdin);
11
- const input_str = new TextDecoder("utf-8").decode(input_data);
12
- const input_obj = JSON.parse(input_str);
13
- const output_obj = userFunction?.default(input_obj);
14
- const output_str = JSON.stringify(output_obj);
15
- const output_data = new TextEncoder().encode(output_str);
16
- fs.writeFileSync(fs.STDIO.Stdout, output_data);
5
+ run(userFunction?.default)
package/package.json CHANGED
@@ -4,18 +4,20 @@
4
4
  "access": "public",
5
5
  "@shopify:registry": "https://registry.npmjs.org/"
6
6
  },
7
- "version": "0.0.3",
7
+ "version": "0.1.0",
8
8
  "description": "",
9
9
  "main": "index.ts",
10
10
  "keywords": [],
11
- "author": "Surma <surma@surma.dev>",
11
+ "author": "Surma <surma@shopify.com>",
12
12
  "license": "Apache-2.0",
13
13
  "dependencies": {
14
14
  "@graphql-codegen/cli": "^2.13.7",
15
15
  "@graphql-codegen/typescript": "^2.8.0",
16
16
  "@graphql-codegen/typescript-operations": "^2.5.5",
17
17
  "graphql": "^16.6.0",
18
- "javy": "^0.0.3",
19
18
  "typescript": "^4.8.4"
19
+ },
20
+ "peerDependencies": {
21
+ "javy": "^0.1.0"
20
22
  }
21
23
  }
package/run.ts ADDED
@@ -0,0 +1,15 @@
1
+ import * as fs from "javy/fs";
2
+
3
+ export type ShopifyFunction<Input extends {}, Output extends {}> = (
4
+ input: Input
5
+ ) => Output;
6
+
7
+ export default function <I extends {}, O extends {}>(userfunction: ShopifyFunction<I, O>) {
8
+ const input_data = fs.readFileSync(fs.STDIO.Stdin);
9
+ const input_str = new TextDecoder("utf-8").decode(input_data);
10
+ const input_obj = JSON.parse(input_str);
11
+ const output_obj = userfunction(input_obj);
12
+ const output_str = JSON.stringify(output_obj);
13
+ const output_data = new TextEncoder().encode(output_str);
14
+ fs.writeFileSync(fs.STDIO.Stdout, output_data);
15
+ }