UNPKG

@devtion/backend

Version:
141 lines 7.59 kB
import { DocumentData, QuerySnapshot, DocumentSnapshot, QueryDocumentSnapshot, WhereFilterOp } from "firebase-admin/firestore"; import admin from "firebase-admin"; import { CircuitDocument } from "@devtion/actions"; import { SSMClient } from "@aws-sdk/client-ssm"; import { EC2Client } from "@aws-sdk/client-ec2"; /** * Get a specific document from database. * @dev this method differs from the one in the `actions` package because we need to use * the admin SDK here; therefore the Firestore instances are not interchangeable between admin * and user instance. * @param collection <string> - the name of the collection. * @param documentId <string> - the unique identifier of the document in the collection. * @returns <Promise<DocumentSnapshot<DocumentData>>> - the requested document w/ relative data. */ export declare const getDocumentById: (collection: string, documentId: string) => Promise<DocumentSnapshot<DocumentData>>; /** * Get the current server timestamp. * @dev the value is in milliseconds. * @returns <number> - the timestamp of the server (ms). */ export declare const getCurrentServerTimestampInMillis: () => number; /** * Interrupt the current execution for a specified amount of time. * @param ms <number> - the amount of time expressed in milliseconds. */ export declare const sleep: (ms: number) => Promise<void>; /** * Query for ceremony circuits. * @notice the order by sequence position is fundamental to maintain parallelism among contributions for different circuits. * @param ceremonyId <string> - the unique identifier of the ceremony. * @returns Promise<Array<FirebaseDocumentInfo>> - the ceremony' circuits documents ordered by sequence position. */ export declare const getCeremonyCircuits: (ceremonyId: string) => Promise<Array<QueryDocumentSnapshot<DocumentData>>>; /** * Query for ceremony circuit contributions. * @param ceremonyId <string> - the unique identifier of the ceremony. * @param circuitId <string> - the unique identifier of the circuitId. * @returns Promise<Array<FirebaseDocumentInfo>> - the contributions of the ceremony circuit. */ export declare const getCeremonyCircuitContributions: (ceremonyId: string, circuitId: string) => Promise<Array<QueryDocumentSnapshot<DocumentData>>>; /** * Query not expired timeouts. * @notice a timeout is considered valid (aka not expired) if and only if the timeout end date * value is less than current timestamp. * @param ceremonyId <string> - the unique identifier of the ceremony. * @param participantId <string> - the unique identifier of the participant. * @returns <Promise<QuerySnapshot<DocumentData>>> */ export declare const queryNotExpiredTimeouts: (ceremonyId: string, participantId: string) => Promise<QuerySnapshot<DocumentData>>; /** * Query for opened ceremonies. * @param firestoreDatabase <Firestore> - the Firestore service instance associated to the current Firebase application. * @returns <Promise<Array<FirebaseDocumentInfo>>> */ export declare const queryOpenedCeremonies: () => Promise<Array<QueryDocumentSnapshot<DocumentData>>>; /** * Get ceremony circuit document by sequence position. * @param ceremonyId <string> - the unique identifier of the ceremony. * @param sequencePosition <number> - the sequence position of the circuit. * @returns Promise<QueryDocumentSnapshot<DocumentData>> */ export declare const getCircuitDocumentByPosition: (ceremonyId: string, sequencePosition: number) => Promise<QueryDocumentSnapshot<DocumentData>>; /** * Create a temporary file path in the virtual memory of the cloud function. * @dev useful when downloading files from AWS S3 buckets for processing within cloud functions. * @param completeFilename <string> - the complete file name (name + ext). * @returns <string> - the path to the local temporary location. */ export declare const createTemporaryLocalPath: (completeFilename: string) => string; /** * Download an artifact from the AWS S3 bucket. * @dev this method uses streams. * @param bucketName <string> - the name of the bucket. * @param objectKey <string> - the unique key to identify the object inside the given AWS S3 bucket. * @param localFilePath <string> - the local path where the file will be stored. */ export declare const downloadArtifactFromS3Bucket: (bucketName: string, objectKey: string, localFilePath: string) => Promise<void>; /** * Upload a new artifact to the AWS S3 bucket. * @dev this method uses streams. * @param bucketName <string> - the name of the bucket. * @param objectKey <string> - the unique key to identify the object inside the given AWS S3 bucket. * @param localFilePath <string> - the local path where the file to be uploaded is stored. */ export declare const uploadFileToBucket: (bucketName: string, objectKey: string, localFilePath: string, isPublic?: boolean) => Promise<void>; export declare const uploadFileToBucketNoFile: (bucketName: string, objectKey: string, data: string, isPublic?: boolean) => Promise<void>; /** * Upload an artifact from the AWS S3 bucket. * @param bucketName <string> - the name of the bucket. * @param objectKey <string> - the unique key to identify the object inside the given AWS S3 bucket. */ export declare const deleteObject: (bucketName: string, objectKey: string) => Promise<void>; /** * Query ceremonies by state and (start/end) date value. * @param state <string> - the state of the ceremony. * @param needToCheckStartDate <boolean> - flag to discriminate when to check startDate (true) or endDate (false). * @param check <WhereFilerOp> - the type of filter (query check - e.g., '<' or '>'). * @returns <Promise<admin.firestore.QuerySnapshot<admin.firestore.DocumentData>>> - the queried ceremonies after filtering operation. */ export declare const queryCeremoniesByStateAndDate: (state: string, needToCheckStartDate: boolean, check: WhereFilterOp) => Promise<admin.firestore.QuerySnapshot<admin.firestore.DocumentData>>; /** * Return the document associated with the final contribution for a ceremony circuit. * @dev this method is useful during ceremony finalization. * @param ceremonyId <string> - * @param circuitId <string> - * @returns Promise<QueryDocumentSnapshot<DocumentData>> - the final contribution for the ceremony circuit. */ export declare const getFinalContribution: (ceremonyId: string, circuitId: string) => Promise<QueryDocumentSnapshot<DocumentData>>; /** * Helper function to HTML encode circuit data. * @param circuitDocument <CircuitDocument> - the circuit document to be encoded. * @returns <CircuitDocument> - the circuit document encoded. */ export declare const htmlEncodeCircuitData: (circuitDocument: CircuitDocument) => CircuitDocument; /** * Fetch the variables related to GitHub anti-sybil checks * @returns <any> - the GitHub variables. */ export declare const getGitHubVariables: () => any; /** * Fetch the variables related to EC2 verification * @returns <any> - the AWS EC2 variables. */ export declare const getAWSVariables: () => any; /** * Create an EC2 client object * @returns <Promise<EC2Client>> an EC2 client */ export declare const createEC2Client: () => Promise<EC2Client>; /** * Create an SSM client object * @returns <Promise<SSMClient>> an SSM client */ export declare const createSSMClient: () => Promise<SSMClient>; /** * Get the instance id of the EC2 instance associated with the circuit * @param circuitId <string> - the circuit id * @returns <Promise<string>> - the EC2 instance id */ export declare const getEC2InstanceId: (circuitId: string) => Promise<string>; //# sourceMappingURL=utils.d.ts.map