npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@mailvideo/backend

v0.1.4

Published

This package is used to handle MailVideo in the backend.

Downloads

83

Readme

@mailvideo/backend

npm (@mailvideo/backend)

This package is designed for server-side integration of MailVideo, facilitating actions like handling webhook events, creating JWT and processing custom videos for MailVideo users.

Install

pnpm i @mailvideo/backend

Features

  • Handle MailVideo webhook events.
  • Create JWT for white label SDK users.
  • Process videos and upload to S3.

Prerequisites

To use this package, a secret key from MailVideo is required. Please contact MailVideo to obtain your secret key.

Example

Usage

Creating a JWT

import { MailVideo } from '@mailvideo/backend';

const mailvideo = new MailVideo({
	secret: process.env.MAILVIDEO_SECRET,
	verbose: process.env.NODE_ENV === 'development',
});

// create a jwt with info about the current user and tenant
const jwt = await mailvideo.createJWT({
	account: {
		id: 'account-id',
		firstName: 'John',
		lastName: 'Doe',
		email: '[email protected]',
	},
	tenant: {
		id: tenantId,
		name: 'Tenant Name',
	},
});

// send JWT to client

Handling Webhooks

import { constructAndHandleMailVideoEvent } from '@mailvideo/backend';

const signature = request.headers['mailvideo-signature'];
if (!signature) {
	throw new Error('Missing signature');
}

await constructAndHandleMailVideoEvent({
	payload: request.body,
	signature,
	secret: process.env.MAILVIDEO_WEBHOOK_SECRET,
	actions: {
		'video-processed-success': (payload) => {
			// Handle successful video processing
		},
		'video-processed-failed': (payload) => {
			// Handle failed video processing
		},
		'video-viewed': (payload) => {
			// Handle video viewed event
		},
	},
});

API

Methods

  • createJWT(options: CreateJWTOptions): Promise<CreateJWTResponse>
  • processVideo(options: StartVideoProcessOptions): Promise<StartVideoProcessResponse>
  • constructEvent(options: MailVideoConstructEventOptions): MailVideoEvent
  • handleEvent(event: MailVideoEvent, actions: EventHandlerActions): Promise<void>
  • constructAndHandleEvent(options: MailVideoConstructEventOptions & { actions: EventHandlerActions }): Promise<void>

Webhook Handling

When handling webhooks, use the constructAndHandleMailVideoEvent method to validate the event and process it with defined actions.

Interfaces

ViewerData

Metadata about the viewer that watches the video.

You can force strong typing by adding a d.ts file to your project.

Example:

declare namespace MailVideo {
	interface ViewerData {
		name: string;
		email: string;
	}
}

Configuring a Custom S3 Bucket for MailVideo

If you want to host the videos in your own Amazon S3 bucket. This setup is crucial to ensure that MailVideo can store and stream videos effectively.

Steps

  1. Access Your S3 Bucket Go to the AWS Management Console and navigate to the S3 service. Select the bucket you intend to use with MailVideo.

  2. Set Permissions Navigate to the Permissions tab of your selected S3 bucket.

  3. Add a Bucket Policy Under the Bucket Policy section, you need to add the following policy:

{
	"Version": "2012-10-17",
	"Statement": [
		{
			"Effect": "Allow",
			"Principal": {
				"AWS": "arn:aws:iam::102512246328:root"
			},
			"Action": ["s3:GetObject", "s3:PutObject"],
			"Resource": "arn:aws:s3:::your-bucket-name/*"
		}
	]
}

Replace your-bucket-name with the actual name of your S3 bucket.

  1. Configure CORS Navigate to the CORS configuration section in the S3 bucket settings. Add the following configuration:
[
	{
		"AllowedHeaders": ["Content-Type"],
		"AllowedMethods": ["PUT"],
		"AllowedOrigins": [
			"https://app.mailvideo.dev",
			"https://app.stage.mailvideo.com",
			"https://app.mailvideo.com"
		],
		"ExposeHeaders": ["ETag"],
		"MaxAgeSeconds": 3000
	}
]