@cfxlabsinc/b2b-services
    Preparing search index...

    This class provides two mechanisms for uploading files:

    1. Direct Upload: Use createWithFileUpload to directly upload a file stream. This method handles the upload to S3 and creates the corresponding database record.

    const result = await transactionMetadataFileService.createWithFileUpload({
    customerId: 'customer123',
    transactionId: 'transaction456',
    fileName: 'my_file.pdf',
    fileStream: readableStream,
    fileType: 'application/pdf',
    fileSize: 12345,
    });

    2. Pre-signed URL Upload: Use getSignedUrlForUpload to generate a pre-signed URL. This URL can then be used by a client (e.g., a browser) to upload the file directly to S3. After the client uploads the file, use createWithS3ObjectKey to create the corresponding database record. Make sure to validate that the upload was successful.

    const { url, s3ObjectKey } = await transactionMetadataFileService.getSignedUrlForUpload({
    customerId: 'customer123',
    transactionId: 'transaction456',
    fileName: 'my_file.pdf',
    fileType: 'application/pdf',
    fileSize: 12345,
    });

    // After client uploads file using the pre-signed URL

    const createResult = await transactionMetadataFileService.createWithS3ObjectKey({
    customerId: 'customer123',
    transactionId: 'transaction456',
    fileName: 'my_file.pdf',
    s3ObjectKey,
    });
    Index

    Constructors

    Properties

    dbHelper: DbHelper
    s3Bucket: string
    s3Client: S3Client
    s3StagingBucket: string

    Methods

    • Uploads a given file to S3 and creates a transaction metadata file record for it.

      Parameters

      • customerId: {
            customerId: string;
            fileName: string;
            fileSize: number;
            fileStream: Readable;
            fileType: string;
            transactionId: string;
        }

        The ID of the customer.

      Returns Promise<
          | { ok: true; value: TransactionMetadataFile }
          | { error: ServiceError; ok: false },
      >

      A promise that resolves to the created transaction metadata file record.

      If an error occurs during the upload to S3.

      ServiceError if the file type is not accepted or the file size exceeds the limit.

    • Create a new transaction metadata file record in the database linked to an S3 object. This method first checks if the S3 object exists before creating the record. If the S3 object does not exist, an error is thrown.

      Parameters

      • customerId: {
            customerId: string;
            fileName: string;
            s3ObjectKey: string;
            transactionId: string;
        }

        The ID of the logged in customer.

      Returns Promise<{ ok: true; value: TransactionMetadataFile }>

      A promise that resolves to the created transaction metadata file record.

      Error if the S3 object does not exist.

    • Copy file object from Staging S3 bucket to Transaction files S3 bucket. Create a new transaction metadata file record in the database linked to the S3 file object. This method first checks if the S3 object exists before creating the record. If the S3 object does not exist, an error is thrown.

      Parameters

      • customerId: {
            customerId: string;
            fileName: string;
            stagingS3ObjectKey: string;
            transactionId: string;
        }

        The ID of the logged in customer.

      Returns Promise<{ ok: true; value: TransactionMetadataFile }>

      A promise that resolves to the created transaction metadata file record.

      Error if the S3 object does not exist.

    • Parameters

      • __namedParameters: { customerId: string; id: string }

      Returns Promise<
          {
              ok: true;
              value: | Omit<
                  {
                      createdAt: Date;
                      customerId: number;
                      data: { awsS3Path: string; fileName: string };
                      externalId: string;
                      id: number;
                      status: "ACTIVE" | "DELETED";
                      transactionId: string;
                      updatedAt: Date;
                  },
                  "id"
                  | "data"
                  | "externalId"
                  | "customerId",
              > & { awsS3Path: string; fileName: string } & { id: string } & {
                  url: string;
              }
              | null;
          },
      >

    • Parameters

      • __namedParameters: {
            customerId: string;
            fileName: string;
            fileSize: number;
            fileType: string;
            quoteId: string;
        }

      Returns Promise<
          | { error: ServiceError; ok: false }
          | { ok: true; value: { s3ObjectKey: string; url: string } },
      >

    • Get a pre-signed URL that can be used to upload a file to S3. The URL is short-lived (2mins) and can be used to upload a file with the specified file name, type, and size.

      Parameters

      • customerId: {
            customerId: string;
            fileName: string;
            fileSize: number;
            fileType: string;
            transactionId: string;
        }

        The ID of the logged in customer.

      Returns Promise<
          | { error: ServiceError; ok: false }
          | { ok: true; value: { s3ObjectKey: string; url: string } },
      >

      A promise that resolves to an object containing the signed URL and S3 Object key.

      ServiceError if the file type is not accepted or the file size exceeds the limit.