@devtion/backend 0.0.0-5d170d3 → 0.0.0-7cfaa5d
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/README.md +26 -0
- package/dist/src/functions/index.js +127 -153
- package/dist/src/functions/index.mjs +127 -153
- package/dist/types/functions/ceremony.d.ts.map +1 -1
- package/dist/types/functions/circuit.d.ts.map +1 -1
- package/dist/types/functions/storage.d.ts.map +1 -1
- package/dist/types/functions/timeout.d.ts.map +1 -1
- package/dist/types/functions/user.d.ts.map +1 -1
- package/dist/types/lib/errors.d.ts +1 -0
- package/dist/types/lib/errors.d.ts.map +1 -1
- package/dist/types/lib/utils.d.ts +1 -1
- package/dist/types/lib/utils.d.ts.map +1 -1
- package/dist/types/types/index.d.ts +1 -1
- package/dist/types/types/index.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/functions/ceremony.ts +8 -3
- package/src/functions/circuit.ts +117 -181
- package/src/functions/participant.ts +8 -8
- package/src/functions/storage.ts +5 -3
- package/src/functions/timeout.ts +4 -3
- package/src/functions/user.ts +31 -7
- package/src/lib/errors.ts +5 -0
- package/src/lib/utils.ts +3 -3
- package/src/types/index.ts +1 -1
package/src/functions/user.ts
CHANGED
|
@@ -2,7 +2,7 @@ import * as functions from "firebase-functions"
|
|
|
2
2
|
import { UserRecord } from "firebase-functions/v1/auth"
|
|
3
3
|
import admin from "firebase-admin"
|
|
4
4
|
import dotenv from "dotenv"
|
|
5
|
-
import { commonTerms, githubReputation } from "@
|
|
5
|
+
import { commonTerms, githubReputation } from "@devtion/actions"
|
|
6
6
|
import { encode } from "html-entities"
|
|
7
7
|
import { getGitHubVariables, getCurrentServerTimestampInMillis } from "../lib/utils"
|
|
8
8
|
import { logAndThrowError, makeError, printLog, SPECIFIC_ERRORS } from "../lib/errors"
|
|
@@ -40,8 +40,12 @@ export const registerAuthUser = functions
|
|
|
40
40
|
const { uid } = user
|
|
41
41
|
// Reference to a document using uid.
|
|
42
42
|
const userRef = firestore.collection(commonTerms.collections.users.name).doc(uid)
|
|
43
|
-
// html encode the display name
|
|
44
|
-
const encodedDisplayName =
|
|
43
|
+
// html encode the display name (or put the ID if the name is not displayed)
|
|
44
|
+
const encodedDisplayName =
|
|
45
|
+
user.displayName === "Null" || user.displayName === null ? user.uid : encode(displayName)
|
|
46
|
+
|
|
47
|
+
// store the avatar URL of a contributor
|
|
48
|
+
let avatarUrl: string = ""
|
|
45
49
|
// we only do reputation check if the user is not a coordinator
|
|
46
50
|
if (
|
|
47
51
|
!(
|
|
@@ -56,13 +60,13 @@ export const registerAuthUser = functions
|
|
|
56
60
|
|
|
57
61
|
// this return true or false
|
|
58
62
|
try {
|
|
59
|
-
const
|
|
63
|
+
const { reputable, avatarUrl: avatarURL } = await githubReputation(
|
|
60
64
|
user.providerData[0].uid,
|
|
61
65
|
vars.minimumFollowing,
|
|
62
66
|
vars.minimumFollowers,
|
|
63
67
|
vars.minimumPublicRepos
|
|
64
68
|
)
|
|
65
|
-
if (!
|
|
69
|
+
if (!reputable) {
|
|
66
70
|
// Delete user
|
|
67
71
|
await auth.deleteUser(user.uid)
|
|
68
72
|
// Throw error
|
|
@@ -70,11 +74,22 @@ export const registerAuthUser = functions
|
|
|
70
74
|
makeError(
|
|
71
75
|
"permission-denied",
|
|
72
76
|
"The user is not allowed to sign up because their Github reputation is not high enough.",
|
|
73
|
-
`The user ${
|
|
77
|
+
`The user ${
|
|
78
|
+
user.displayName === "Null" || user.displayName === null
|
|
79
|
+
? user.uid
|
|
80
|
+
: user.displayName
|
|
81
|
+
} is not allowed to sign up because their Github reputation is not high enough. Please contact the administrator if you think this is a mistake.`
|
|
74
82
|
)
|
|
75
83
|
)
|
|
76
84
|
}
|
|
77
|
-
|
|
85
|
+
// store locally
|
|
86
|
+
avatarUrl = avatarURL
|
|
87
|
+
printLog(
|
|
88
|
+
`Github reputation check passed for user ${
|
|
89
|
+
user.displayName === "Null" || user.displayName === null ? user.uid : user.displayName
|
|
90
|
+
}`,
|
|
91
|
+
LogLevel.DEBUG
|
|
92
|
+
)
|
|
78
93
|
} catch (error: any) {
|
|
79
94
|
// Delete user
|
|
80
95
|
await auth.deleteUser(user.uid)
|
|
@@ -89,6 +104,8 @@ export const registerAuthUser = functions
|
|
|
89
104
|
}
|
|
90
105
|
}
|
|
91
106
|
// Set document (nb. we refer to providerData[0] because we use Github OAuth provider only).
|
|
107
|
+
// In future releases we might want to loop through the providerData array as we support
|
|
108
|
+
// more providers.
|
|
92
109
|
await userRef.set({
|
|
93
110
|
name: encodedDisplayName,
|
|
94
111
|
encodedDisplayName,
|
|
@@ -101,7 +118,14 @@ export const registerAuthUser = functions
|
|
|
101
118
|
photoURL: photoURL || "",
|
|
102
119
|
lastUpdated: getCurrentServerTimestampInMillis()
|
|
103
120
|
})
|
|
121
|
+
|
|
122
|
+
// we want to create a new collection for the users to store the avatars
|
|
123
|
+
const avatarRef = firestore.collection(commonTerms.collections.avatars.name).doc(uid)
|
|
124
|
+
await avatarRef.set({
|
|
125
|
+
avatarUrl: avatarUrl || ""
|
|
126
|
+
})
|
|
104
127
|
printLog(`Authenticated user document with identifier ${uid} has been correctly stored`, LogLevel.DEBUG)
|
|
128
|
+
printLog(`Authenticated user avatar with identifier ${uid} has been correctly stored`, LogLevel.DEBUG)
|
|
105
129
|
})
|
|
106
130
|
/**
|
|
107
131
|
* Set custom claims for role-based access control on the newly created user.
|
package/src/lib/errors.ts
CHANGED
|
@@ -184,6 +184,11 @@ export const SPECIFIC_ERRORS = {
|
|
|
184
184
|
"unavailable",
|
|
185
185
|
"VM command execution has been delayed since there were no available instance at the moment",
|
|
186
186
|
"Please, contact the coordinator if this error persists."
|
|
187
|
+
),
|
|
188
|
+
SE_VM_UNKNOWN_COMMAND_STATUS: makeError(
|
|
189
|
+
"unavailable",
|
|
190
|
+
"VM command execution has failed due to an unknown status code",
|
|
191
|
+
"Please, contact the coordinator if this error persists."
|
|
187
192
|
)
|
|
188
193
|
}
|
|
189
194
|
|
package/src/lib/utils.ts
CHANGED
|
@@ -25,7 +25,7 @@ import {
|
|
|
25
25
|
CeremonyState,
|
|
26
26
|
finalContributionIndex,
|
|
27
27
|
CircuitDocument
|
|
28
|
-
} from "@
|
|
28
|
+
} from "@devtion/actions"
|
|
29
29
|
import fetch from "@adobe/node-fetch-retry"
|
|
30
30
|
import path from "path"
|
|
31
31
|
import os from "os"
|
|
@@ -217,7 +217,7 @@ export const downloadArtifactFromS3Bucket = async (bucketName: string, objectKey
|
|
|
217
217
|
const streamPipeline = promisify(pipeline)
|
|
218
218
|
await streamPipeline(response.body, writeStream)
|
|
219
219
|
|
|
220
|
-
writeStream.on(
|
|
220
|
+
writeStream.on("finish", () => {
|
|
221
221
|
writeStream.end()
|
|
222
222
|
})
|
|
223
223
|
}
|
|
@@ -305,7 +305,7 @@ export const deleteObject = async (bucketName: string, objectKey: string) => {
|
|
|
305
305
|
|
|
306
306
|
// Prepare command.
|
|
307
307
|
const command = new DeleteObjectCommand({ Bucket: bucketName, Key: objectKey })
|
|
308
|
-
|
|
308
|
+
|
|
309
309
|
// Execute command.
|
|
310
310
|
const data = await client.send(command)
|
|
311
311
|
|
package/src/types/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CeremonyInputData, CircuitDocument, ETagWithPartNumber } from "@
|
|
1
|
+
import { CeremonyInputData, CircuitDocument, ETagWithPartNumber } from "@devtion/actions"
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Group all the necessary data needed for running the `setupCeremony` cloud function.
|