1.0.4 • Published 8 months ago

arena-typed v1.0.4

Weekly downloads
-
License
MIT
Repository
-
Last release
8 months ago

cover

Arena-typed

Unofficial are.na API wrapper for TypeScript

Installation

npm install arena-typed

Quick start

To get started, create a new Arena instance and use its methods.

Note: Some actions require authentication. To obtain an access token:

  • Create a new application on are.na
  • Copy the value named Personal access token
  • Pass it to the Arena constructor ex. new Arena('your-access-token')
import { Arena } from 'arena-typed';

const arena = new Arena();

const channel = await arena.channels.get('arena-influences');
console.log(channel.title);

// or using promises
arena.channels.get('arena-influences').then((channel) => {
  console.log(channel.title);
});

Usage

The Arena class has four properties which are instances of subclasses with their own methods:

  • users
  • search
  • blocks
  • channels

Params

Some methods support pagination (optional), specified by pagination. Pass as an object like so: { page: 2, per: 15 }

Users

MethodReturnsDescription
get(username: string)Promise<FollowingType>Get a specific user
channels(username: string)Promise<Channel[]>Get a list of the specified user's channels
followers(username: string)Promise<User[]Get a list of users following the specified user
following(username: string)Promise<User[]>Get a list of the specified user's followed channels and users

Examples

arena.users.get('testing-arena').then((users) => console.log('result', users));

arena.users.channels('testing-arena').then((channels) => console.log('result', channels));

arena.users.followers('testing-arena').then((followers) => console.log('result', followers));

arena.users.following('testing-arena').then((following) => console.log('result', following));

Search

MethodReturnsDescription
all(query: string, pagination?: PaginationParams)Promise<SearchResponse>Perform a search
users(username: string)Promise<User[]>Search for users
channels(channel: string)Promise<Channel[]Search for channels
blocks(blocks: string)Promise<Block[]>Search for blocks

Examples

arena.search.all('testing').then((search) => console.log('result', search));

arena.search.users('testing-arena').then((search) => console.log('result', search));

arena.search.channels('arena-influences').then((search) => console.log('result', search));

arena.search.blocks('testing').then((search) => console.log('result', search));

Blocks

MethodReturnsDescription
get(id: number)Promise<Block>Get a block
channels(id: number)Promise<Channel[]Get a list of channels the block is in
create(channel: string, data: BlockCreationData)Promise<Block>Create a new block in the specified channel
update(id: number, data: BlockUpdateData)Promise<void>Update a block that exists in the specified channel
delete(channel: string, id: number)Promise<void>Delete a block that exists in the specified channel

Examples

arena.blocks.channels(1234).then((channels) => console.log('channels', channels));

arena.blocks.create('new-channel-name', { source: 'new title' }).then((blocks) => console.log('result', blocks));

arena.blocks
  .update(123456, { title: 'updated title', description: 'updated description' })
  .catch((error) => console.log(error.message));

arena.blocks.delete('channel-name', 12345).catch((error) => console.log(error.message));

Channels

MethodReturnsDescription
get (channel: string, pagination?: PaginationParams)Promise<Channel>Get a channel
thumb(channel: string)Promise<ChannelGet basic information about a channel
connections(channel: string, pagination?: PaginationParams)Promise<Connection>Get all the connections within a channel
contents(channel: string, pagination?: PaginationParams)Promise<(Channel \| Block)[]>Get only the contents of a channel (ex. no collaborators)
create(data: ChannelCreationData)Promise<Channel>Create a channel
update(channel: string, data: ChannelCreationData)Promise<Channel>Update a channel
delete(channel: string)Promise<void>Delete a channel
createBlock(channel: string, data: BlockCreationData)Promise<Block>Create a block in the specified channel
collaborators(channel: string)Promise<User[]>Get all users that are part of the specified channel, excluding the owner
addCollaborators(channel: string, users: CollaboratorData)Promise<User[]>Add collaborators to the specified channel
removeCollaborators(channel: string, users: CollaboratorData)Promise<User[]>Delete specified collaborators from the specified channel. Note: On the official documentaion, this request is supposed to remove users that are not specified in users. However, it currently works the other way around

Examples

arena.channels.get('channel-name').then((channel) => console.log('channel', channel));

arena.channels.thumb('channel-name').then((channel) => console.log('channel', channel));

arena.channels.connections('channel-name', { per, 20, page: 2 }).then((channels) => console.log('channel', channels));

arena.channels.contents('channel-name', { per: 3 }).then((contents) => console.log('contents', contents));

arena.channels
  .create({ title: 'new channel name', status: 'public' })
  .then((channel) => console.log('result', channel));

arena.channels
  .update('current-channel-name', { title: 'updated channel name' })
  .then((channel) => console.log('result', channel));

arena.channels
  .delete('channel-name')
  .then(() => console.log('success'))
  .catch((error) => console.log(error.message));

arena.channels
  .createBlock('channel-name', { source: 'new title' })
  .then((channels) => console.log('result', channels));

arena.channels.collaborators('channel-name').then((users) => console.log('collaborators', users));

arena.channels
  .addCollaborators('channel-name', { ids: [12345] })
  .then((channels) => console.log('result', channels));

arena.channels
  .removeCollaborators('updated-channel-name', { ids: [12345] })
  .then((channels) => console.log('result', channels));

Types

Users

PropertyType
idnumber
slugstring
usernamestring
first_namestring
last_namestring
avatarstring
avatar_imageAvatarImage | null
channel_countnumber
following_countnumber
profile_idnumber
follower_countnumber
class"User"
initialsstring
AvatarImage
PropertyType
thumbstring
displaystring
Following
PropertyType
FollowingUser[] | Channel[] | Block[]
UserResponse
PropertyType
base_class"User"
channel_titlestring | null
class"User"
current_pagenumber
lengthnumber
pernumber
total_pagesnumber
FollowerResponse
PropertyType
usersUser[]
base_class"User"
channel_titlestring | null
class"User"
current_pagenumber
lengthnumber
pernumber
total_pagesnumber
FollowingResponse
PropertyType
followingFollowingType
base_class"User"
channel_titlestring | null
class"User"
current_pagenumber
lengthnumber
pernumber
total_pagesnumber
UserChannelsResponse
PropertyType
channelsChannel[]
base_class"User"
channel_titlestring | null
class"User"
current_pagenumber
lengthnumber
pernumber
total_pagesnumber

Search

SearchResponse
PropertyType
termstring
usersUser[]
channelsChannel[]
blocksBlock[]
total_pagesnumber
current_pagenumber
pernumber
lengthnumber

Blocks

Block
PropertyType
idnumber
titlestring | null
updated_atDate
created_atDate
state"Available" | "Failure" | "Procesed" | "Processing"
comment_countnumber
generated_titlestring
class"Image" | "Text" | "Link" | "Media" | "Attachment"
base_class"Block"
contentstring | null
content_htmlstring | null
descriptionstring | null
description_htmlstring | null
sourcenull | { title?: string; url: string; provider: { name: string; url: string; } | null; }
imagenull | { content_type: string; display: { url: string }; filename: string; lage: { url: string }l original: { file_size: number; file_size_display: string; url: string; }; square: { url: string }; thumb: { url: string }; updated_at: Date; }
userUser
connections?Channel[] | undefined
Connection
PropertyType
lengthnumber
total_pagesnumber
current_pagenumber
pernumber
channel_titlestring | null
base_class"Channels"
class"Channel"
channelsChannel[]
BlocksResponse
PropertyType
lengthnumber
total_pagesnumber
current_pagenumber
pernumber
channel_titlestring | null
base_class"Block"
class"Text"
channelsChannel[]
ChannelsResponse
PropertyType
base_class"Block"
channel_titlestring | null
channelsChannel[]
class"Image" | "Text" | "Link" | "Media" | "Attachment"
current_pagenumber
lengthnumber
pernumber
total_pagesnumber
BlockCreationData

Note: Either source or content is required, but not both.

PropertyType
sourcestring | undefined
contentstring | undefined
BlockUpdateData
PropertyType
title?string | undefined
description?string | undefined
content?string | undefined

Channels

Contents
PropertyType
contentsArray<Block | Channel>
Channel
PropertyType
idnumber
titlestring
created_atDate
updated_atDate
publishedboolean
openboolean
collaborationboolean
slugstring
lengthnumber
kindstring
statusstring
user_idnumber
classstring
base_classstring
userUser
total_pagesnumber
current_pagenumber
pernumber
follower_countnumber
contents(Block | Channel)[]
collaboratorsUser[]
BlockAttributes
PropertyType
positionnumber
selectedboolean
connected_atDate
connected_by_user_idnumber
PaginationParams
PropertyType
page?number
per?number
ChannelCreationData
PropertyType
titlestring
status?'public' | 'closed' | 'private'
CollaboratorData
PropertyType
idsnumber[]
CollaboratorResponse
PropertyType
channel_titlestring | null
current_pagenumber
lengthnumber
pernumber
total_pagesnumber
GetOrDeleteCollaboratorsResponse
PropertyType
channel_titlestring | null
current_pagenumber
lengthnumber
pernumber
total_pagesnumber
usersUser[]
AddCollaboratorsResponse
PropertyType
channel_titlestring | null
current_pagenumber
lengthnumber
pernumber
total_pagesnumber
collaboratorsUser[]
1.0.4

8 months ago

1.0.3

10 months ago

1.0.2

10 months ago

1.0.1

10 months ago

1.0.0

10 months ago