@secure-redact/javascript-sdk
TypeScript icon, indicating that this package has built-in type declarations

1.0.4 • Public • Published

Secure Redact Javascript SDK

NPM version

Built and maintained by the Pimloc team.

This repo provides a Javascript SDK wrapper for talking to the Secure Redact API. For more information see the API Reference

Table of Contents

Installation

Install via NPM

npm i @secure-redact/javascript-sdk

Usage

The package needs to be configured with your account's clientId and clientSecret, which is available in the Secure Redact App

import { SecureRedactSDK } from '@secure-redact/javascript-sdk';

const secureRedact = new SecureRedact({
  clientId: 'YOUR_CLIENT_ID',
  clientSecret: 'YOUR_CLIENT_SECRET'
});

const data = await secureRedact.uploadMedia({
  mediaPath: 'PRESIGNED_URL'
});

console.log(data.mediaId);

Usage with Typescript

import { SecureRedactSDK } from '@secure-redact/javascript-sdk';
import type {
  SecureRedactUploadMediaParams,
  SecureRedactUploadMediaResponse
} from '@secure-redact/javascript-sdk';

const secureRedact = new SecureRedact({
  clientId: 'YOUR_CLIENT_ID',
  clientSecret: 'YOUR_CLIENT_SECRET'
});

const params: SecureRedactUploadMediaParams = {
  mediaPath: 'PRESIGNED_URL'
};
const data: SecureRedactUploadMediaResponse = await secureRedact.uploadMedia(
  params
);

console.log(data.mediaId);

Upload Media

Function that adds a media to the Secure Redact system. The mediaPath must be a presigned URL that the Secure Redact system can download the file from. To upload a file directly use the File parameter to pass in a File object and pass in an empty string for the mediaPath.

You can monitor progress in two ways. Either by polling our /info route (see Fetch Media Status) or by setting up the stateCallback URL. This must be a URL where the Secure Redact system can POST updates to. For more information see the API reference

const data = await secureRedact.uploadMedia({
  mediaPath: 'PRESIGNED_URL'
});

Parameters:

interface SecureRedactUploadMediaParams {
  mediaPath: string;
  videoTag?: string;
  increasedDetectionAccuracy?: boolean;
  stateCallback?: string;
  exportCallback?: string;
  exportToken?: string;
  detectLicensePlates?: boolean;
  detectFaces?: boolean;
  file?: File;
}

Response:

interface SecureRedactUploadResponse {
  fileInfo: {
    name: string;
    mimetype: string;
    size: number;
  };
  mediaId: SecureRedactMediaId;
  message?: string;
  error: string | null;
}

Fetch Media Status

Function that responds with the current media status. For information on the potential status' see the API reference

const data = await secureRedact.fetchMediaStatus({
  mediaId: 'MEDIA_ID'
});

Parameters:

interface SecureRedactFetchMediaStatusParams {
  mediaId: SecureRedactMediaId;
  username?: SecureRedactUsername;
}

Response:

interface SecureRedactMediaInfo {
  mediaId: SecureRedactMediaId;
  username: SecureRedactUsername;
  error: string | null;
  status: string;
}

Redact Media

Function that starts the Redact Media process, for more information see API reference

const data = await secureRedact.redactMedia({
  mediaId: 'MEDIA_ID'
});

Parameters:

interface SecureRedactRedactMediaParams {
  mediaId: SecureRedactMediaId;
  enlargeBoxes?: number;
  redactAudio?: boolean;
  blur?: 'pixelated' | 'smooth';
  username?: SecureRedactUsername;
}

Response:

interface SecureRedactRedactResponse {
  error: string | null;
}

Download Media

Function that responds with the redacted media, for more information see API reference

const blob = await secureRedact.downloadMedia({
  mediaId: 'MEDIA_ID'
});

// simulate downloading file to user's machine
const blobURL = URL.createObjectURL(blob);
const a = document.createElement('a');
a.setAttribute('href', blobURL);
document.body.appendChild(a);
a.click();
URL.revokeObjectURL(blobURL);

Parameters:

interface SecureRedactDownloadMediaParams {
  username?: SecureRedactUsername;
  mediaId: SecureRedactMediaId;
}

Response:

interface SecureRedactDownloadMediaResponse {
  blob: Blob;
}

Delete Media

Function that deletes the media, for more information see API reference

const blob = await secureRedact.deleteMedia({
  mediaId: 'MEDIA_ID'
});

Parameters:

interface SecureRedactDeleteMediaParams {
  mediaId: SecureRedactMediaId;
}

Response:

interface SecureRedactDeleteMediaResponse {
  error: string | null;
  message: string;
  mediaId: SecureRedactMediaId;
}

Create User

Enterprise Accounts ONLY

Function that creates a new user that belongs to your enterprise account, for more information see API reference

const blob = await secureRedact.createUser({
  username: 'DUMMY_USERNAME'
});

Parameters:

interface SecureRedactCreateUserParams {
  username: SecureRedactUsername;
}

Response:

interface SecureRedactUserInfo {
  username: SecureRedactUsername;
  error: string | null;
  msg?: string;
}

Login User

Enterprise Accounts ONLY

Function that returns a URL to log the user in to the Secure Redact UI, for more information see API reference

const blob = await secureRedact.loginUser({
  username: 'DUMMY_USERNAME'
});

Parameters:

interface SecureRedactLoginUserParams {
  username: SecureRedactUsername;
  mediaId: SecureRedactMediaId;
}

Response:

interface SecureRedactLoginResponse {
  redirectUrl: string;
  success: boolean;
}

Generic Types

type SecureRedactUsername = string;
type SecureRedactMediaId = string;

Readme

Keywords

none

Package Sidebar

Install

npm i @secure-redact/javascript-sdk

Weekly Downloads

17

Version

1.0.4

License

ISC

Unpacked Size

117 kB

Total Files

46

Last publish

Collaborators

  • james-pimloc
  • will-pimloc