@devtion/actions 0.0.0-bfc9ee4 → 0.0.0-c1f4cbe
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 +1 -1
- package/dist/index.mjs +331 -298
- package/dist/index.node.js +331 -297
- package/dist/types/src/helpers/constants.d.ts +8 -0
- package/dist/types/src/helpers/constants.d.ts.map +1 -1
- package/dist/types/src/helpers/contracts.d.ts.map +1 -1
- package/dist/types/src/helpers/crypto.d.ts +1 -0
- package/dist/types/src/helpers/crypto.d.ts.map +1 -1
- package/dist/types/src/helpers/database.d.ts +8 -0
- package/dist/types/src/helpers/database.d.ts.map +1 -1
- package/dist/types/src/helpers/security.d.ts +2 -2
- package/dist/types/src/helpers/security.d.ts.map +1 -1
- package/dist/types/src/helpers/storage.d.ts +5 -2
- package/dist/types/src/helpers/storage.d.ts.map +1 -1
- package/dist/types/src/helpers/utils.d.ts +34 -20
- package/dist/types/src/helpers/utils.d.ts.map +1 -1
- package/dist/types/src/helpers/verification.d.ts +3 -2
- package/dist/types/src/helpers/verification.d.ts.map +1 -1
- package/dist/types/src/helpers/vm.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +1 -1
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/types/index.d.ts +9 -3
- package/dist/types/src/types/index.d.ts.map +1 -1
- package/package.json +3 -8
- package/src/helpers/constants.ts +8 -0
- package/src/helpers/contracts.ts +3 -3
- package/src/helpers/database.ts +13 -0
- package/src/helpers/functions.ts +1 -1
- package/src/helpers/security.ts +33 -52
- package/src/helpers/services.ts +3 -3
- package/src/helpers/storage.ts +15 -3
- package/src/helpers/utils.ts +316 -277
- package/src/helpers/verification.ts +6 -6
- package/src/helpers/vm.ts +14 -7
- package/src/index.ts +3 -2
- package/src/types/index.ts +32 -8
package/src/helpers/services.ts
CHANGED
|
@@ -22,7 +22,7 @@ export const getFirestoreDatabase = (app: FirebaseApp): Firestore => getFirestor
|
|
|
22
22
|
* @param app <FirebaseApp> - the Firebase application.
|
|
23
23
|
* @returns <Functions> - the Cloud Functions associated to the application.
|
|
24
24
|
*/
|
|
25
|
-
export const getFirebaseFunctions = (app: FirebaseApp): Functions => getFunctions(app,
|
|
25
|
+
export const getFirebaseFunctions = (app: FirebaseApp): Functions => getFunctions(app, "europe-west1")
|
|
26
26
|
|
|
27
27
|
/**
|
|
28
28
|
* Retrieve the configuration variables for the AWS services (S3, EC2).
|
|
@@ -33,7 +33,7 @@ export const getAWSVariables = (): AWSVariables => {
|
|
|
33
33
|
!process.env.AWS_ACCESS_KEY_ID ||
|
|
34
34
|
!process.env.AWS_SECRET_ACCESS_KEY ||
|
|
35
35
|
!process.env.AWS_REGION ||
|
|
36
|
-
!process.env.
|
|
36
|
+
!process.env.AWS_INSTANCE_PROFILE_ARN ||
|
|
37
37
|
!process.env.AWS_AMI_ID
|
|
38
38
|
)
|
|
39
39
|
throw new Error(
|
|
@@ -44,7 +44,7 @@ export const getAWSVariables = (): AWSVariables => {
|
|
|
44
44
|
accessKeyId: process.env.AWS_ACCESS_KEY_ID!,
|
|
45
45
|
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY!,
|
|
46
46
|
region: process.env.AWS_REGION || "us-east-1",
|
|
47
|
-
|
|
47
|
+
instanceProfileArn: process.env.AWS_INSTANCE_PROFILE_ARN!,
|
|
48
48
|
amiId: process.env.AWS_AMI_ID!
|
|
49
49
|
}
|
|
50
50
|
}
|
package/src/helpers/storage.ts
CHANGED
|
@@ -3,6 +3,7 @@ import mime from "mime-types"
|
|
|
3
3
|
import fs, { createWriteStream } from "fs"
|
|
4
4
|
import fetch from "@adobe/node-fetch-retry"
|
|
5
5
|
import https from "https"
|
|
6
|
+
import { GenericBar } from "cli-progress"
|
|
6
7
|
import { ETagWithPartNumber, ChunkWithUrl, TemporaryParticipantContributionData } from "../types/index"
|
|
7
8
|
import { commonTerms } from "./constants"
|
|
8
9
|
import {
|
|
@@ -80,6 +81,7 @@ export const getChunksAndPreSignedUrls = async (
|
|
|
80
81
|
* @param cloudFunctions <Functions> - the Firebase Cloud Functions service instance.
|
|
81
82
|
* @param ceremonyId <string> - the unique identifier of the ceremony.
|
|
82
83
|
* @param alreadyUploadedChunks Array<ETagWithPartNumber> - the temporary information about the already uploaded chunks.
|
|
84
|
+
* @param logger <GenericBar> - an optional logger to show progress.
|
|
83
85
|
* @returns <Promise<Array<ETagWithPartNumber>>> - the completed (uploaded) chunks information.
|
|
84
86
|
*/
|
|
85
87
|
export const uploadParts = async (
|
|
@@ -87,11 +89,15 @@ export const uploadParts = async (
|
|
|
87
89
|
contentType: string | false,
|
|
88
90
|
cloudFunctions?: Functions,
|
|
89
91
|
ceremonyId?: string,
|
|
90
|
-
alreadyUploadedChunks?: Array<ETagWithPartNumber
|
|
92
|
+
alreadyUploadedChunks?: Array<ETagWithPartNumber>,
|
|
93
|
+
logger?: GenericBar
|
|
91
94
|
): Promise<Array<ETagWithPartNumber>> => {
|
|
92
95
|
// Keep track of uploaded chunks.
|
|
93
96
|
const uploadedChunks: Array<ETagWithPartNumber> = alreadyUploadedChunks || []
|
|
94
97
|
|
|
98
|
+
// if we were passed a logger, start it
|
|
99
|
+
if (logger) logger.start(chunksWithUrls.length, 0)
|
|
100
|
+
|
|
95
101
|
// Loop through remaining chunks.
|
|
96
102
|
for (let i = alreadyUploadedChunks ? alreadyUploadedChunks.length : 0; i < chunksWithUrls.length; i += 1) {
|
|
97
103
|
// Consume the pre-signed url to upload the chunk.
|
|
@@ -128,6 +134,9 @@ export const uploadParts = async (
|
|
|
128
134
|
// nb. this must be done only when contributing (not finalizing).
|
|
129
135
|
if (!!ceremonyId && !!cloudFunctions)
|
|
130
136
|
await temporaryStoreCurrentContributionUploadedChunkData(cloudFunctions, ceremonyId, chunk)
|
|
137
|
+
|
|
138
|
+
// increment the count on the logger
|
|
139
|
+
if (logger) logger.increment()
|
|
131
140
|
}
|
|
132
141
|
|
|
133
142
|
return uploadedChunks
|
|
@@ -150,6 +159,7 @@ export const uploadParts = async (
|
|
|
150
159
|
* @param configStreamChunkSize <number> - size of each chunk into which the artifact is going to be splitted (nb. will be converted in MB).
|
|
151
160
|
* @param [ceremonyId] <string> - the unique identifier of the ceremony (used as a double-edge sword - as identifier and as a check if current contributor is the coordinator finalizing the ceremony).
|
|
152
161
|
* @param [temporaryDataToResumeMultiPartUpload] <TemporaryParticipantContributionData> - the temporary information necessary to resume an already started multi-part upload.
|
|
162
|
+
* @param logger <GenericBar> - an optional logger to show progress.
|
|
153
163
|
*/
|
|
154
164
|
export const multiPartUpload = async (
|
|
155
165
|
cloudFunctions: Functions,
|
|
@@ -158,7 +168,8 @@ export const multiPartUpload = async (
|
|
|
158
168
|
localFilePath: string,
|
|
159
169
|
configStreamChunkSize: number,
|
|
160
170
|
ceremonyId?: string,
|
|
161
|
-
temporaryDataToResumeMultiPartUpload?: TemporaryParticipantContributionData
|
|
171
|
+
temporaryDataToResumeMultiPartUpload?: TemporaryParticipantContributionData,
|
|
172
|
+
logger?: GenericBar
|
|
162
173
|
) => {
|
|
163
174
|
// The unique identifier of the multi-part upload.
|
|
164
175
|
let multiPartUploadId: string = ""
|
|
@@ -198,7 +209,8 @@ export const multiPartUpload = async (
|
|
|
198
209
|
mime.lookup(localFilePath), // content-type.
|
|
199
210
|
cloudFunctions,
|
|
200
211
|
ceremonyId,
|
|
201
|
-
alreadyUploadedChunks
|
|
212
|
+
alreadyUploadedChunks,
|
|
213
|
+
logger
|
|
202
214
|
)
|
|
203
215
|
|
|
204
216
|
// Step (3).
|