0.0.93 • Published 3 months ago

droplr-client-ts v0.0.93

Weekly downloads
-
License
MIT
Repository
github
Last release
3 months ago

droplr-client-ts client-badge npm version brain-power

Logo The TypeScript variant of Droplr's API Client

Installation

$ npm install --save droplr-client-ts

Table of contents

API

Client

Client(ClientConfig): Class

The primary access point for the API Client.

Constructor

ClientConfig: Interface

new Client(config as ClientConfig)

ClientConfig Props
NameTypeDescription
baseUrlstringThe URL the requests are sent to Default: https://api.droplr.com
authJwtAuthBasicAuthAnonymousAuthThe Auth method Default: new AnonymousAuth()
onResponseFunctionThe callback for successful requests
onErrorFunctionThe callback for requests gone wrong

Attributes

NameTypeDescription
DropsDropsThe Drops accessor
BoardsBoardsThe Boards accessor
UsersUsersThe Users accessor
TeamsTeamsThe Teams accessor

Example

// JWTAuth
const API = new Client({
  baseUrl: "https://api.droplr.com",
  auth: new JwtAuth(TOKEN),
  onError: (e) => console.log(e) 
} as ClientConfig);

// BasicAuth
API = new Client({
  baseUrl: "https://api.droplr.com",
  auth: new BasicAuth(USERNAME, PASSWORD),
  onError: (e) => console.log(e) 
} as ClientConfig);

API.Users.Current().then(...)

Drops

Drops: Class

Provides access to the endpoints related to a user's Drops

Methods

CallReturnsDescription
Get(id: string, params?: GetDropsOptions)DropReturns a Drop object with the matching ID Optional Can take {drop_password, content_disposition} as additional GetDropsOptions parameter
GetLastTen()ArrayReturns the last 10 drops the user made
GetMultiple(options: GetMultipleDropsOptions)DropsListReturns multiple drops queried with additional parameters GetMultipleDropsOptions
GetSharedDrops(options: GetSharedDropsOptions)DropsListReturns multiple shared drops queried with additional parameters GetSharedDropsOptions
GetAllDropsInBoard(boardId: string, boardPassword?: string)ArrayReturns all the drops in the specified board Optional Takes boardPassword as a parameter if the board is private
Create(data: CreateDropMetadata)DropCreates a new Drop and returns it. Optionally, pass a onProgressUpdated(percentage, uploadedBytes, isCompleted) callback to track upload progress (from Chromium 105 and after).CreateDropMetadata
Update(id: string, dropData: Drop)DropUpdates the drop's properties
DuplicateDrop(id: string)DropCreates a duplicate of the Drop
AnnotateDrop(data: DataAnnotationProps)DropAdds an annotation to the drop
RemoveAnnotation(dropId: string)OK or ErrorDeletes the annotation from the Drop
AddReaction(data: DropReaction)DropReactionAdds an reaction to the drop
RemoveReaction(reactionId: string)OK or ErrorDeletes the reaction from the Drop
RemoveAllReactions(dropId: string)OK or ErrorDeletes all reactions from the Drop
ListHits(id: string)DropsListReturns the views on the Drop DropsList
GetStats(options: StatsConfig)ObjectReturns the basic Drop stats, lastAccess, start, end, granularityStatsConfig
GetActivity(id: string, afterId?: string)ArrayFetches the Drop's activity list
TriggerTrackingEvent(id: string, type: DropTrackingEvents, options?: DropViewEventProps)DropFires off a tracking event for the Drop
GetReferrers(id: string)ArrayFetches the Drop's referrers
Delete(id: string)OK or ErrorDeletes the Drop
DeleteMultiple(ids: Array<string>)OK or ErrorDeletes the Drops provided

Interfaces

▸ CreateDropMetadata: Interface

interface CreateDropMetadata {
  title: string;
  type: "FILE" | "LINK" | "NOTE" | "FOLDER";
  variant: string; // ie. image/png
  content: any; // Blob
  board?: string;
  pixelDensity?: number;
  folder?: string;
  onProgressUpdated?: (
    progress: number,
    uploaded: number,
    completed: boolean
  ) => void;
}

▸ DropsList: Interface

interface DropsList {
  count: number;
  hasMore: boolean;
  results: Array<HitData>;
}

▸ GetDropFilters: Interface

interface GetDropFilters {
  /** Drop Type, ie. FILE/VIDEO/IMAGE */
  type?: string;
  /** Drop Variant, ie. image/png */
  variant?: string;
  /** Title-based search */
  search?: string;
  /** Filter since timestamp, ie. 1705483733454 */
  since?: string;
  /** Filter until timestamp, ie. 1705483733454 */
  until?: string;
  /** Ordering, ASC/DESC */
  order?: "ASC" | "DESC";
  /** Sort by, ie. TITLE/CREATED_AT/VIEWS/SIZE/ACTIVITY */
  sort?: "TITLE" | "CREATED_AT" | "VIEWS" | "SIZE" | "ACTIVITY" | "VIEWS";
  /** Filters drops containing the provided tags */
  tags: string[];
  /** Filters drops based on starred property */
  favorite?: boolean;
  folder?: string;
}

▸ GetMultipleDropsOptions: Interface

interface GetMultipleDropsOptions {
  owner?: string;
  amount?: number;
  board?: string;
  offset?: number;
  filter?: 
}

▸ GetSharedDropsOptions: Interface

interface GetMultipleDropsOptions {
  amount?: number;
  offset?: number;
}

▸ DropAnnotationProps: Interface

interface DropAnnotationProps {
  id?: string;
  dropId: string;
  title: string;
  ctaType: string;
  linkData?: string;
  position: string;
  startTime?: number;
  endTime?: number;
  startTimeText?: string;
  endTimeText?: string;
  shape?: string;
  color?: string;
  fontWeight?: string;
  fontColor?: string;
}

▸ DropReaction: Interface

interface DropReaction {
  id: string;
  dropId: string;
  userId: string;
  type: string;
  timestamp: number;
  content: string;
  createdAt: number;
  user?: {
    name: string;
    email: string;
  }
}

▸ StatsConfig: Interface

interface StatsConfig {
  id: string;
  slice:
    | "HOURLY_LAST_24H"
    | "HOURLY_LAST_TWO_DAYS"
    | "DAILY_LAST_WEEK"
    | "DAILY_LAST_TWO_WEEKS"
    | "DAILY_LAST_MONTH"
    | "DAILY_LAST_TWO_MONTHS"
    | "WEEKLY_LAST_SIX_MONTHS";
  format?: "DATETIME" | "DEFAULT";
  timezoneOffset?: number;
}

▸ DropTrackingEvents: enum

enum DropTrackingEvents {
  DOWNLOAD = "DOWNLOAD",
  VIEW = "VIEW",
}

▸ DropViewEventProps: Interface

interface DropViewEventProps {
  referrer?: string;
  displayClass?: string;
  userAgent?: string;
  host?: string;
  password?: string;
}

Examples

// Initialize the Client
const API = new Client({
  baseUrl: "https://api.droplr.com",
  auth: new JwtAuth(TOKEN),
  onError: (e) => console.log(e) 
} as ClientConfig);

// Fetch a Drop
API.Drops.Get('TEST_ID').then(
    (res) => {
        res.json().then(
            (drop: Drop) => {
                handleDrop(drop)
            }
        )
    }
)

// Create a new Drop
API.Drops.Create({
        title: "MyImage",
        type: "FILE",
        variant: "image/png",
        content: imageBlob,
      }).then(
    (res) => {
        res.json().then(
            (drop: Drop) => {
                handleDrop(drop)
            }
        )
    }
)


// Create a new Drop and track its progress
API.Drops.Create({
        title: "MyImage",
        type: "FILE",
        variant: "image/png",
        content: imageBlob,
        onProgressUpdated(progress, uploaded, completed) {
        console.log(`Current progress: ${progress}%, total uploaded bytes: ${uploaded}`);
        if(completed) {
            handleUploadComplete();
            }
        }
      }).then(
    (res) => {
        res.json().then(
            (drop: Drop) => {
                handleDrop(drop)
            }
        )
    }
)

** IMPORTANT **
Since the StreamAPI is a relatively new feature, feature detection using the below snippet is advised: 

const supportsRequestStreams = (() => {
  let duplexAccessed = false;

  const hasContentType = new Request('', {
    body: new ReadableStream(),
    method: 'POST',
    get duplex() {
      duplexAccessed = true;
      return 'half';
    },
  }).headers.has('Content-Type');

  return duplexAccessed && !hasContentType;
})();

if (supportsRequestStreams) {
  // …
} else {
  // …
}

// Update a Drop
API.Drops.Update("TEST_ID", {
        title: "RenamedImage",
        privacy: "TEAM"
    });

Boards

Boards: Class

Provides access to the endpoints related to a user's Boards

Methods

CallReturnsDescription
Get(id: string)BoardReturns the Board specified by the ID
GetAll()ArrayFetches all of the user's Boards
GetSharedWithTeam()ArrayFetches all of the Boards the user has shared with his team
Create(data: CreateBoardData)BoardCreates a new Board CreateBoardData
Update(id: string, data: UpdateBoardData)BoardUpdates a Board UpdateBoardData
Watch(id: string, password?: string)OK or ErrorSets a Board to be watched
StopWatching(id: string, password?: string)OK or ErrorStops watching a Board
Delete(id: string)OK or ErrorDeletes a Board

Interfaces

▸ CreateBoardData: Interface

interface CreateBoardData {
  name: string;
  privacy?: "PRIVATE" | "PUBLIC";
  uploadPrivacy?: "PRIVATE" | "PUBLIC";
  password?: string;
  isPublic?: boolean;
  groupsAccessList?: [];
  accessList?: [];
}

▸ UpdateBoardData: Interface

interface UpdateBoardData {
  name?: string;
  privacy?: "PRIVATE" | "PUBLIC";
  uploadPrivacy?: "PRIVATE" | "PUBLIC";
  password?: string;
  isPublic?: boolean;
  groupsAccessList?: [];
  accessList?: [];
  poweredBy?: boolean;
}

Examples

// Initialize the Client
const API = new Client({
  baseUrl: "https://api.droplr.com",
  auth: new JwtAuth(TOKEN),
  onError: (e) => console.log(e) 
} as ClientConfig);

// Fetch a Board
API.Boards.Get('TEST_ID').then(
    (res) => {
        res.json().then(
            (board: Board) => {
                handleBoard(board)
            }
        )
    }
)

// Create a new Board
API.Boards.Create({ 
    name: "NewBoard", 
    password: "Secret", 
    privacy: "PRIVATE" 
    }).then(
        (res) => {
            res.json().then(
                (board: Board) => {
                    handleBoard(board)
                }
            )
        }
)

// Update a Board
API.Boards.Update("TEST_ID", {
        name: "RenamedBoard",
        privacy: "PUBLIC", 
        password: ""
    });

Users

Users: Class

Provides access to the endpoints related to the User who's token initialized the Client

Methods

CallReturnsDescription
Current()UserReturns the User who's token initialized the Client
Create(data: CreateUserData)UserCreates a new User CreateUserData
Update(id: string, data: UpdateUserData)UserUpdates a User UpdateUserData
Delete(id: string)OK or ErrorDeletes a User
Tags(id: string)ArrayFetches a Users Tags
Boards(id: string)ArrayFetches a Users Boards

Interfaces

▸ CreateUserData: Interface

interface CreateUserData {
    email: string;
    password: string;
}

▸ UpdateUserData: Interface

interface UpdateUserData {
    email?: string;
    username?: string;
    dropPrivacy?: "PUBLIC" | "PRIVATE" | "TEAM";
    theme?: "STANDARD" | "DARK" | "LIGHT";
}

Examples

// Initialize the Client
const API = new Client({
  baseUrl: "https://api.droplr.com",
  auth: new JwtAuth(TOKEN),
  onError: (e) => console.log(e) 
} as ClientConfig);

// Fetch the current user
API.Users.Current.then(
    (res) => {
        res.json().then(
            (user: User) => {
                handleBoard(user.id)
            }
        )
    }
)

// Update a User
API.Users.Update("TEST_ID", {
    theme: "DARK"
});

// Fetch a User's Boards
API.Users.Boards().then(
    (res) => {
        res.json().then(
            (boards: Array<Board>) => {
                boards.forEach(
                    b => handleBoard(b)
                )
            }
        )
    }
)

Teams

Teams: Class

Provides access to the endpoints related to the user's Teams

Methods

CallReturnsDescription
Get(id: string)TeamReturns the specified Team
GetAccountsInTeam(id: string)ArrayFetches a list of Users in a specific Team
Update(id: string, data: UpdateTeamData)TeamUpdates the specified Team

Interfaces

▸ UpdateTeamData: Interface

interface UpdateTeamData {
  billing?: "NONE" | "MONTHLY" | "ANNUAL" | "LIFETIME",
  payment_type?: "NONE" | "CREDIT_CARD" | "INVOICE_CREDIT_CARD" | "INVOICE_PO" | "APPSUMO" | "STACK_SOCIAL",
  selfDestructType?: "NONE" | "VIEWS" | "TIME",
  selfDestructValue?: number,
  selfDestructReminderType?: "NONE" | "VIEWS" | "TIME",
  selfDestructReminderValue?: number,
  name?: string,
  dropPrivacy?: "PUBLIC" | "PRIVATE" | "TEAM" | "OBSCURE",
  theme?: "STANDARD" | "DARK" | "LIGHT",
  domainType?: "DEFAULT" | "SUB_DOMAIN" | "DOMAIN",
  domain?: string,
  rootRedirect?: string,
  useRootRedirect?: boolean,
  subdomain?: string,
  useLogo?: boolean,
  visionRedaction?: "ON" | "OFF",
  useUserSettings?: boolean,
  useUserSelfDestructSettings?: boolean,
  useUserPrivacySettings?: boolean,
  sslEnabledOnCustomDomain?: boolean,
  poweredBy?: boolean,
  useEmailDomain?: boolean,
  invitePrivilege?: "ALL" | "ADMIN_ONLY",
  storageProvider?: "AMAZON" | "AZURE" | "GOOGLE_DRIVE" | "AMAZON_S3" | "DROPBOX",
  useUserStorageProvider?: boolean,
  redaction?: "ALL" | "TEAM" | "NONE",
  useUserRedaction?: boolean,
  excludeRedactionGroupsList?: any,
}

interface TeamSettings {
  domainType: string;
  logo: string;
  name: string;
  rootRedirect: string;
  subdomain: string;
  theme: "STANDARD" | "DARK" | "LIGHT";
  useLogo: boolean;
  useRootRedirect: boolean;
  type: "FREE" | "PRO" | "ENTERPRISE";
}

Examples

// Initialize the Client
const API = new Client({
  baseUrl: "https://api.droplr.com",
  auth: new JwtAuth(TOKEN),
  onError: (e) => console.log(e) 
} as ClientConfig);

// Fetch a Teams data
API.Teams.Get("TEST_ID").then(
    (res) => {
        res.json().then(
            (team: Team) => {
                handleTeam(team.settings.name)
            }
        )
    }
)

// Fetch the Users in a Team
API.Teams.GetAccountsInTeam("TEST_ID").then(
    (res) => {
        res.json().then(
            (users: Array<User>) => {
                users.forEach(
                    u => removeUser(u.id)
                )
            }
        )
    }
);

Additional request configuration

Some request support additional fetch() configuration

Interfaces

▸ ClientError: Interface

interface OptionalRequestConfig {
  abortSignal?: AbortSignal;
}

Examples

/** Prematurely aborting a request */
const abortController = new AbortController();
const abortSignal = abortController.signal;

API.Drops.Create(
    {
        title: "TestImg2",
        type: "FILE",
        variant: "image.png",
        content: b,
    },
    { signal: abortSignal }
    )
    .then((_response) => {});

setTimeout( () => abortController.abort(), 50);

Errors

Errors are thrown and contain both the HTTP response and the error object.

Interfaces

▸ ClientError: Interface

interface ClientError {
    code: number;
    statusCode: number;
    message: string;
    response: Response;
    errors: any[];

}

Examples

API.Teams.GetAccountsInTeam("TEST_ID")
  .then((res) => {
    res.json().then((team) => {
      console.log(team);
    });
  })
  .catch((e: ClientError) => {
    console.log(e.code, e.message);
    e.response.json().then((r) => console.log(r));
  });
0.0.93

3 months ago

0.0.92

8 months ago

0.0.90

11 months ago

0.0.91

11 months ago

0.0.89

11 months ago

0.0.84

11 months ago

0.0.85

11 months ago

0.0.86

11 months ago

0.0.87

11 months ago

0.0.88

11 months ago

0.0.80

1 year ago

0.0.81

1 year ago

0.0.82

1 year ago

0.0.83

12 months ago

0.0.78

1 year ago

0.0.79

1 year ago

0.0.77

1 year ago

0.0.76

1 year ago

0.0.74

1 year ago

0.0.75

1 year ago

0.0.73

1 year ago

0.0.71

1 year ago

0.0.72

1 year ago

0.0.67

1 year ago

0.0.68

1 year ago

0.0.70

1 year ago

0.0.66

1 year ago

0.0.65

1 year ago

0.0.64

1 year ago

0.0.63

1 year ago

0.0.62

1 year ago

0.0.60

1 year ago

0.0.61

1 year ago

0.0.59

1 year ago

0.0.58

1 year ago

0.0.57

1 year ago

0.0.56

1 year ago

0.0.55-beta

1 year ago

0.0.54

1 year ago

0.0.53

1 year ago

0.0.52

1 year ago

0.0.51

1 year ago

0.0.5

1 year ago

0.0.42

1 year ago

0.0.41

1 year ago

0.0.40

1 year ago

0.0.38

2 years ago

0.0.39

2 years ago

0.0.35

2 years ago

0.0.36

2 years ago

0.0.37

2 years ago

0.0.34

2 years ago

0.0.33

2 years ago

0.0.32

2 years ago

0.0.31

2 years ago

0.0.3

2 years ago

0.0.1

2 years ago