@devtion/actions 0.0.0-7e983e3 → 0.0.0-9c50f66

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.
package/dist/index.mjs CHANGED
@@ -244,6 +244,12 @@ const commonTerms = {
244
244
  verificationStartedAt: "verificationStartedAt"
245
245
  }
246
246
  },
247
+ avatars: {
248
+ name: "avatars",
249
+ fields: {
250
+ avatarUrl: "avatarUrl"
251
+ }
252
+ },
247
253
  ceremonies: {
248
254
  name: "ceremonies",
249
255
  fields: {
@@ -2079,55 +2085,27 @@ const verifyCeremony = async (functions, firestore, ceremonyPrefix, outputDirect
2079
2085
  };
2080
2086
 
2081
2087
  /**
2082
- * This function will return the number of public repos of a user
2083
- * @param user <string> The username of the user
2084
- * @returns <number> The number of public repos
2088
+ * This function queries the GitHub API to fetch users statistics
2089
+ * @param user {string} the user uid
2090
+ * @returns {any} the stats from the GitHub API
2085
2091
  */
2086
- const getNumberOfPublicReposGitHub = async (user) => {
2087
- const response = await fetch(`https://api.github.com/user/${user}/repos`, {
2092
+ const getGitHubStats = async (user) => {
2093
+ const response = await fetch(`https://api.github.com/user/${user}`, {
2088
2094
  method: "GET",
2089
2095
  headers: {
2090
2096
  Authorization: `token ${process.env.GITHUB_ACCESS_TOKEN}`
2091
2097
  }
2092
2098
  });
2093
2099
  if (response.status !== 200)
2094
- throw new Error("It was not possible to retrieve the number of public repositories. Please try again.");
2100
+ throw new Error("It was not possible to retrieve the user's statistic. Please try again.");
2095
2101
  const jsonData = await response.json();
2096
- return jsonData.length;
2097
- };
2098
- /**
2099
- * This function will return the number of followers of a user
2100
- * @param user <string> The username of the user
2101
- * @returns <number> The number of followers
2102
- */
2103
- const getNumberOfFollowersGitHub = async (user) => {
2104
- const response = await fetch(`https://api.github.com/user/${user}/followers`, {
2105
- method: "GET",
2106
- headers: {
2107
- Authorization: `token ${process.env.GITHUB_ACCESS_TOKEN}`
2108
- }
2109
- });
2110
- if (response.status !== 200)
2111
- throw new Error("It was not possible to retrieve the number of followers. Please try again.");
2112
- const jsonData = await response.json();
2113
- return jsonData.length;
2114
- };
2115
- /**
2116
- * This function will return the number of following of a user
2117
- * @param user <string> The username of the user
2118
- * @returns <number> The number of following users
2119
- */
2120
- const getNumberOfFollowingGitHub = async (user) => {
2121
- const response = await fetch(`https://api.github.com/user/${user}/following`, {
2122
- method: "GET",
2123
- headers: {
2124
- Authorization: `token ${process.env.GITHUB_ACCESS_TOKEN}`
2125
- }
2126
- });
2127
- if (response.status !== 200)
2128
- throw new Error("It was not possible to retrieve the number of following. Please try again.");
2129
- const jsonData = await response.json();
2130
- return jsonData.length;
2102
+ const data = {
2103
+ following: jsonData.following,
2104
+ followers: jsonData.followers,
2105
+ publicRepos: jsonData.public_repos,
2106
+ avatarUrl: jsonData.avatar_url
2107
+ };
2108
+ return data;
2131
2109
  };
2132
2110
  /**
2133
2111
  * This function will check if the user is reputable enough to be able to use the app
@@ -2135,19 +2113,23 @@ const getNumberOfFollowingGitHub = async (user) => {
2135
2113
  * @param minimumAmountOfFollowing <number> The minimum amount of following the user should have
2136
2114
  * @param minimumAmountOfFollowers <number> The minimum amount of followers the user should have
2137
2115
  * @param minimumAmountOfPublicRepos <number> The minimum amount of public repos the user should have
2138
- * @returns <boolean> True if the user is reputable enough, false otherwise
2116
+ * @returns <any> Return the avatar URL of the user if the user is reputable, false otherwise
2139
2117
  */
2140
2118
  const githubReputation = async (userLogin, minimumAmountOfFollowing, minimumAmountOfFollowers, minimumAmountOfPublicRepos) => {
2141
2119
  if (!process.env.GITHUB_ACCESS_TOKEN)
2142
2120
  throw new Error("The GitHub access token is missing. Please insert a valid token to be used for anti-sybil checks on user registation, and then try again.");
2143
- const following = await getNumberOfFollowingGitHub(userLogin);
2144
- const repos = await getNumberOfPublicReposGitHub(userLogin);
2145
- const followers = await getNumberOfFollowersGitHub(userLogin);
2121
+ const { following, followers, publicRepos, avatarUrl } = await getGitHubStats(userLogin);
2146
2122
  if (following < minimumAmountOfFollowing ||
2147
- repos < minimumAmountOfPublicRepos ||
2123
+ publicRepos < minimumAmountOfPublicRepos ||
2148
2124
  followers < minimumAmountOfFollowers)
2149
- return false;
2150
- return true;
2125
+ return {
2126
+ reputable: false,
2127
+ avatarUrl: ""
2128
+ };
2129
+ return {
2130
+ reputable: true,
2131
+ avatarUrl: avatarUrl
2132
+ };
2151
2133
  };
2152
2134
 
2153
2135
  /**
@@ -246,6 +246,12 @@ const commonTerms = {
246
246
  verificationStartedAt: "verificationStartedAt"
247
247
  }
248
248
  },
249
+ avatars: {
250
+ name: "avatars",
251
+ fields: {
252
+ avatarUrl: "avatarUrl"
253
+ }
254
+ },
249
255
  ceremonies: {
250
256
  name: "ceremonies",
251
257
  fields: {
@@ -2081,55 +2087,27 @@ const verifyCeremony = async (functions, firestore$1, ceremonyPrefix, outputDire
2081
2087
  };
2082
2088
 
2083
2089
  /**
2084
- * This function will return the number of public repos of a user
2085
- * @param user <string> The username of the user
2086
- * @returns <number> The number of public repos
2090
+ * This function queries the GitHub API to fetch users statistics
2091
+ * @param user {string} the user uid
2092
+ * @returns {any} the stats from the GitHub API
2087
2093
  */
2088
- const getNumberOfPublicReposGitHub = async (user) => {
2089
- const response = await fetch(`https://api.github.com/user/${user}/repos`, {
2094
+ const getGitHubStats = async (user) => {
2095
+ const response = await fetch(`https://api.github.com/user/${user}`, {
2090
2096
  method: "GET",
2091
2097
  headers: {
2092
2098
  Authorization: `token ${process.env.GITHUB_ACCESS_TOKEN}`
2093
2099
  }
2094
2100
  });
2095
2101
  if (response.status !== 200)
2096
- throw new Error("It was not possible to retrieve the number of public repositories. Please try again.");
2102
+ throw new Error("It was not possible to retrieve the user's statistic. Please try again.");
2097
2103
  const jsonData = await response.json();
2098
- return jsonData.length;
2099
- };
2100
- /**
2101
- * This function will return the number of followers of a user
2102
- * @param user <string> The username of the user
2103
- * @returns <number> The number of followers
2104
- */
2105
- const getNumberOfFollowersGitHub = async (user) => {
2106
- const response = await fetch(`https://api.github.com/user/${user}/followers`, {
2107
- method: "GET",
2108
- headers: {
2109
- Authorization: `token ${process.env.GITHUB_ACCESS_TOKEN}`
2110
- }
2111
- });
2112
- if (response.status !== 200)
2113
- throw new Error("It was not possible to retrieve the number of followers. Please try again.");
2114
- const jsonData = await response.json();
2115
- return jsonData.length;
2116
- };
2117
- /**
2118
- * This function will return the number of following of a user
2119
- * @param user <string> The username of the user
2120
- * @returns <number> The number of following users
2121
- */
2122
- const getNumberOfFollowingGitHub = async (user) => {
2123
- const response = await fetch(`https://api.github.com/user/${user}/following`, {
2124
- method: "GET",
2125
- headers: {
2126
- Authorization: `token ${process.env.GITHUB_ACCESS_TOKEN}`
2127
- }
2128
- });
2129
- if (response.status !== 200)
2130
- throw new Error("It was not possible to retrieve the number of following. Please try again.");
2131
- const jsonData = await response.json();
2132
- return jsonData.length;
2104
+ const data = {
2105
+ following: jsonData.following,
2106
+ followers: jsonData.followers,
2107
+ publicRepos: jsonData.public_repos,
2108
+ avatarUrl: jsonData.avatar_url
2109
+ };
2110
+ return data;
2133
2111
  };
2134
2112
  /**
2135
2113
  * This function will check if the user is reputable enough to be able to use the app
@@ -2137,19 +2115,23 @@ const getNumberOfFollowingGitHub = async (user) => {
2137
2115
  * @param minimumAmountOfFollowing <number> The minimum amount of following the user should have
2138
2116
  * @param minimumAmountOfFollowers <number> The minimum amount of followers the user should have
2139
2117
  * @param minimumAmountOfPublicRepos <number> The minimum amount of public repos the user should have
2140
- * @returns <boolean> True if the user is reputable enough, false otherwise
2118
+ * @returns <any> Return the avatar URL of the user if the user is reputable, false otherwise
2141
2119
  */
2142
2120
  const githubReputation = async (userLogin, minimumAmountOfFollowing, minimumAmountOfFollowers, minimumAmountOfPublicRepos) => {
2143
2121
  if (!process.env.GITHUB_ACCESS_TOKEN)
2144
2122
  throw new Error("The GitHub access token is missing. Please insert a valid token to be used for anti-sybil checks on user registation, and then try again.");
2145
- const following = await getNumberOfFollowingGitHub(userLogin);
2146
- const repos = await getNumberOfPublicReposGitHub(userLogin);
2147
- const followers = await getNumberOfFollowersGitHub(userLogin);
2123
+ const { following, followers, publicRepos, avatarUrl } = await getGitHubStats(userLogin);
2148
2124
  if (following < minimumAmountOfFollowing ||
2149
- repos < minimumAmountOfPublicRepos ||
2125
+ publicRepos < minimumAmountOfPublicRepos ||
2150
2126
  followers < minimumAmountOfFollowers)
2151
- return false;
2152
- return true;
2127
+ return {
2128
+ reputable: false,
2129
+ avatarUrl: ""
2130
+ };
2131
+ return {
2132
+ reputable: true,
2133
+ avatarUrl: avatarUrl
2134
+ };
2153
2135
  };
2154
2136
 
2155
2137
  /**
@@ -98,6 +98,12 @@ export declare const commonTerms: {
98
98
  verificationStartedAt: string;
99
99
  };
100
100
  };
101
+ avatars: {
102
+ name: string;
103
+ fields: {
104
+ avatarUrl: string;
105
+ };
106
+ };
101
107
  ceremonies: {
102
108
  name: string;
103
109
  fields: {
@@ -1 +1 @@
1
- {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../../src/helpers/constants.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,sBAAsB,+CAA+C,CAAA;AAElF,eAAO,MAAM,mBAAmB,6BAA6B,CAAA;AAE7D,eAAO,MAAM,gBAAgB,UAAU,CAAA;AAEvC,eAAO,MAAM,gBAAgB,KAAK,CAAA;AAElC,eAAO,MAAM,eAAe,UAAU,CAAA;AAEtC,eAAO,MAAM,sBAAsB,UAAU,CAAA;AAE7C,eAAO,MAAM,sBAAsB,SAAS,CAAA;AAE5C,eAAO,MAAM,4BAA4B,aAAa,CAAA;AAEtD,eAAO,MAAM,cAAc,sBAAsB,CAAA;AAEjD,eAAO,MAAM,yBAAyB,iBAAiB,CAAA;AAEvD;;;;;;GAMG;AACH,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA2ChC,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,gBAAgB;;;GA6G5B,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAuHvB,CAAA"}
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../../src/helpers/constants.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,sBAAsB,+CAA+C,CAAA;AAElF,eAAO,MAAM,mBAAmB,6BAA6B,CAAA;AAE7D,eAAO,MAAM,gBAAgB,UAAU,CAAA;AAEvC,eAAO,MAAM,gBAAgB,KAAK,CAAA;AAElC,eAAO,MAAM,eAAe,UAAU,CAAA;AAEtC,eAAO,MAAM,sBAAsB,UAAU,CAAA;AAE7C,eAAO,MAAM,sBAAsB,SAAS,CAAA;AAE5C,eAAO,MAAM,4BAA4B,aAAa,CAAA;AAEtD,eAAO,MAAM,cAAc,sBAAsB,CAAA;AAEjD,eAAO,MAAM,yBAAyB,iBAAiB,CAAA;AAEvD;;;;;;GAMG;AACH,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA2ChC,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,gBAAgB;;;GA6G5B,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA6HvB,CAAA"}
@@ -4,7 +4,7 @@
4
4
  * @param minimumAmountOfFollowing <number> The minimum amount of following the user should have
5
5
  * @param minimumAmountOfFollowers <number> The minimum amount of followers the user should have
6
6
  * @param minimumAmountOfPublicRepos <number> The minimum amount of public repos the user should have
7
- * @returns <boolean> True if the user is reputable enough, false otherwise
7
+ * @returns <any> Return the avatar URL of the user if the user is reputable, false otherwise
8
8
  */
9
- export declare const githubReputation: (userLogin: string, minimumAmountOfFollowing: number, minimumAmountOfFollowers: number, minimumAmountOfPublicRepos: number) => Promise<boolean>;
9
+ export declare const githubReputation: (userLogin: string, minimumAmountOfFollowing: number, minimumAmountOfFollowers: number, minimumAmountOfPublicRepos: number) => Promise<any>;
10
10
  //# sourceMappingURL=security.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"security.d.ts","sourceRoot":"","sources":["../../../../src/helpers/security.ts"],"names":[],"mappings":"AAwDA;;;;;;;GAOG;AACH,eAAO,MAAM,gBAAgB,cACd,MAAM,4BACS,MAAM,4BACN,MAAM,8BACJ,MAAM,KACnC,QAAQ,OAAO,CAgBjB,CAAA"}
1
+ {"version":3,"file":"security.d.ts","sourceRoot":"","sources":["../../../../src/helpers/security.ts"],"names":[],"mappings":"AA8BA;;;;;;;GAOG;AACH,eAAO,MAAM,gBAAgB,cACd,MAAM,4BACS,MAAM,4BACN,MAAM,8BACJ,MAAM,KACnC,QAAQ,GAAG,CAsBb,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@devtion/actions",
3
- "version": "0.0.0-7e983e3",
3
+ "version": "0.0.0-9c50f66",
4
4
  "description": "A set of actions and helpers for CLI commands",
5
5
  "repository": "git@github.com:privacy-scaling-explorations/p0tion.git",
6
6
  "homepage": "https://github.com/privacy-scaling-explorations/p0tion",
@@ -83,5 +83,5 @@
83
83
  "publishConfig": {
84
84
  "access": "public"
85
85
  },
86
- "gitHead": "afae72061a3b366b05508de53fe91e9b254cc3d5"
86
+ "gitHead": "1285984f567fe9c2456c6033fad3159d0b4c9393"
87
87
  }
@@ -217,6 +217,12 @@ export const commonTerms = {
217
217
  verificationStartedAt: "verificationStartedAt"
218
218
  }
219
219
  },
220
+ avatars: {
221
+ name: "avatars",
222
+ fields: {
223
+ avatarUrl: "avatarUrl"
224
+ }
225
+ },
220
226
  ceremonies: {
221
227
  name: "ceremonies",
222
228
  fields: {
@@ -1,45 +1,12 @@
1
1
  import fetch from "@adobe/node-fetch-retry"
2
+
2
3
  /**
3
- * This function will return the number of public repos of a user
4
- * @param user <string> The username of the user
5
- * @returns <number> The number of public repos
6
- */
7
- const getNumberOfPublicReposGitHub = async (user: string): Promise<number> => {
8
- const response = await fetch(`https://api.github.com/user/${user}/repos`, {
9
- method: "GET",
10
- headers: {
11
- Authorization: `token ${process.env.GITHUB_ACCESS_TOKEN!}`
12
- }
13
- })
14
- if (response.status !== 200)
15
- throw new Error("It was not possible to retrieve the number of public repositories. Please try again.")
16
- const jsonData: any = await response.json()
17
- return jsonData.length
18
- }
19
- /**
20
- * This function will return the number of followers of a user
21
- * @param user <string> The username of the user
22
- * @returns <number> The number of followers
23
- */
24
- const getNumberOfFollowersGitHub = async (user: string): Promise<number> => {
25
- const response = await fetch(`https://api.github.com/user/${user}/followers`, {
26
- method: "GET",
27
- headers: {
28
- Authorization: `token ${process.env.GITHUB_ACCESS_TOKEN!}`
29
- }
30
- })
31
- if (response.status !== 200)
32
- throw new Error("It was not possible to retrieve the number of followers. Please try again.")
33
- const jsonData: any = await response.json()
34
- return jsonData.length
35
- }
36
- /**
37
- * This function will return the number of following of a user
38
- * @param user <string> The username of the user
39
- * @returns <number> The number of following users
4
+ * This function queries the GitHub API to fetch users statistics
5
+ * @param user {string} the user uid
6
+ * @returns {any} the stats from the GitHub API
40
7
  */
41
- const getNumberOfFollowingGitHub = async (user: string): Promise<number> => {
42
- const response = await fetch(`https://api.github.com/user/${user}/following`, {
8
+ const getGitHubStats = async (user: string): Promise<any> => {
9
+ const response = await fetch(`https://api.github.com/user/${user}`, {
43
10
  method: "GET",
44
11
  headers: {
45
12
  Authorization: `token ${process.env.GITHUB_ACCESS_TOKEN!}`
@@ -47,11 +14,18 @@ const getNumberOfFollowingGitHub = async (user: string): Promise<number> => {
47
14
  })
48
15
 
49
16
  if (response.status !== 200)
50
- throw new Error("It was not possible to retrieve the number of following. Please try again.")
17
+ throw new Error("It was not possible to retrieve the user's statistic. Please try again.")
51
18
 
52
19
  const jsonData: any = await response.json()
53
20
 
54
- return jsonData.length
21
+ const data = {
22
+ following: jsonData.following,
23
+ followers: jsonData.followers,
24
+ publicRepos: jsonData.public_repos,
25
+ avatarUrl: jsonData.avatar_url
26
+ }
27
+
28
+ return data
55
29
  }
56
30
 
57
31
  /**
@@ -60,27 +34,33 @@ const getNumberOfFollowingGitHub = async (user: string): Promise<number> => {
60
34
  * @param minimumAmountOfFollowing <number> The minimum amount of following the user should have
61
35
  * @param minimumAmountOfFollowers <number> The minimum amount of followers the user should have
62
36
  * @param minimumAmountOfPublicRepos <number> The minimum amount of public repos the user should have
63
- * @returns <boolean> True if the user is reputable enough, false otherwise
37
+ * @returns <any> Return the avatar URL of the user if the user is reputable, false otherwise
64
38
  */
65
39
  export const githubReputation = async (
66
40
  userLogin: string,
67
41
  minimumAmountOfFollowing: number,
68
42
  minimumAmountOfFollowers: number,
69
43
  minimumAmountOfPublicRepos: number
70
- ): Promise<boolean> => {
44
+ ): Promise<any> => {
71
45
  if (!process.env.GITHUB_ACCESS_TOKEN)
72
46
  throw new Error(
73
47
  "The GitHub access token is missing. Please insert a valid token to be used for anti-sybil checks on user registation, and then try again."
74
48
  )
75
- const following = await getNumberOfFollowingGitHub(userLogin)
76
- const repos = await getNumberOfPublicReposGitHub(userLogin)
77
- const followers = await getNumberOfFollowersGitHub(userLogin)
49
+
50
+ const { following, followers, publicRepos, avatarUrl } = await getGitHubStats(userLogin)
78
51
 
79
52
  if (
80
53
  following < minimumAmountOfFollowing ||
81
- repos < minimumAmountOfPublicRepos ||
54
+ publicRepos < minimumAmountOfPublicRepos ||
82
55
  followers < minimumAmountOfFollowers
83
56
  )
84
- return false
85
- return true
57
+ return {
58
+ reputable: false,
59
+ avatarUrl: ""
60
+ }
61
+
62
+ return {
63
+ reputable: true,
64
+ avatarUrl: avatarUrl
65
+ }
86
66
  }