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

rfwrapper

v1.5.5

Published

Пакет для работы с API RedForester

Downloads

24

Readme

rfwrapper

npm version

Попытка написать свой модуль для работы с api RF.

Установка

Yarn:

yarn add rfwrapper

NPM:

npm i rfwrapper

Пример использования

Больше примеров можно найти в папке example или в папке с тестами

Пример плагина для RF который слушает события на подключеных картах и добавляет команду somename на корень карты.

import { Extention } from 'rfwrapper';
import { NotifyReply } from 'rfwrapper/Extension/reply';

const ext = new Extention({
  name: 'somename', // уникальное название плагина
  email: '[email protected]', // емаил автора
  baseUrl: 'https://86c220d7.ngrok.io:443', // аддрес по которому доступен плагин
});

// создаем команду которая будет доступна только на корне карты
ext.command(
  {
    id: 'uuid', // уникальное название команды внутри плагина
    name: 'somename', // название которое будет видеть пользователь
    showRules: [{ root: true }] // правила по которым команда отображается в клиенте RF
  },
  async () => new NotifyReply() // показываем пользователю уведомление
    .setContent('some value') // с текстом some value
    .setDuration(5 * 1000); // 5 секунд
)

// подписываемся на все события которые происходят на подключеных картах
ext.subscribe('*', async (conn, ctx) => {
  console.log(ctx)
})

// запускаем плагин на 1233 порту
ext.start(1233, async () => {
  // после успешного запуска регистрируем плагин используя свой аккаунт
  ext.register('[email protected]', 'md5fromverystrongpassword')
    .then(_ => console.log('Плагин успешно зарегистрирован и подключен'))
    .catch(_ => process.exit(1));
});

Пример плагина для слежения за статусом задач с использованием декораторов. Только с TypeScript и включеным experimentalDecorators.

import { Wrapper, Extention, EventContext } from 'rfwrapper';
import { IExtCommandCtx } from 'rfwrapper/Extension/interface';
import { ICommandReply, NotifyReply, NotifyStyle } from 'rfwrapper/Extension/reply';
import { Command } from 'rfwrapper/Extension/command';
import { Event } from 'rfwrapper/Extension/event';
import { Id, Name, Description, ShowRules, On, RequiredType } from 'rfwrapper/Extension/decorators';

@Id('unique-id')
@Name('Название команды')
@Description('Описание команды')
@ShowRules({ allNodes: true })
@RequiredType('Задача')
@RequiredType('Постановка', [])
class SimpleCommand extends Command {
  public async run(conn: Wrapper, ctx: IExtCommandCtx): Promise<ICommandReply> {
    const user = await conn.user.get(ctx.userId);

    return new NotifyReply()
      .setContent(`Привет ${user.name} ${user.surname}!`)
      .setStyle(NotifyStyle.SUCCESS);
  }
}

// данный код сработает только если пришло событие о обновлении узла
@On('node_updated')
class TaskStatusWatcher extends Event {
  public async run(self: Wrapper, ctx: EventContext): Promise<void> {
    // проверяем что это тип узла - задача и обновилось типовое поле
    if (!ctx.data.node_type || ctx.data.node_type.name !== 'Задача') return;
    if (!('properties' in ctx.data) || !ctx.data.properties.byType) return;

    const field = ctx.data.properties.byType.updated.find(f => f.key === 'Статус');
    if (!field) return;

    const username =
      ctx.who.name && ctx.who.surname
        ? ctx.who.name + ' ' + ctx.who.surname
        : ctx.who.username;

    const reply =
      `🔔 Пользователь [${username}](${ext.rfBaseUrl}user?userid=${ctx.who.id}) `
      + `поменял(а) статус "${field.old_value}" -> "${field.value}".`;

    // добавляем новый комментарий о том что поле изменилось
    await self.node.addComment(ctx.what, reply);
  }
}

const ext = new Extention({
  name: 'somename', // уникальное название плагина
  email: '[email protected]', // емаил автора
  baseUrl: 'https://86c220d7.ngrok.io:443', // аддрес по которому доступен плагин
});

// добавляем нового слушателя событий
ext.subscribe(new TaskStatusWatcher());
// добавляем новую команду
ext.command(new SimpleCommand());

// запускаем плагин на 1233 порту
ext.start(1233, async () => {
  // после успешного запуска регистрируем плагин используя свой аккаунт
  ext.register('[email protected]', 'md5fromverystrongpassword')
    .then(_ => console.log('Плагин успешно зарегистрирован и подключен'))
    .catch(_ => process.exit(1));
});

Wrapper

const wrapper = new rf.wrapper({
  username: '[email protected]',
  password: '123123'
})

// Информация об узле по uuid
wrapper.Node('c84d974f-44e3-4e54-9f26-03a493c33586')
  .then((node) => console.log(node)
  .catch((err) => console.log(err));

// подписка на события карты сразу после того как будут получены данные карты
wrapper.Map('c060bcb4-4c21-4a40-86ca-b4319252d073', { enablePolling: true }).then((map) => {  
  // пример события
  map.on('*', (ctx) => {
    console.log(ctx)
  })

})

Api

const wrapper = new rf.wrapper({
  username: '[email protected]',
  password: '123123'
})

// Получить информацию о карте по uuid
wrapper.map.get('b64578f3-2db6-40a3-954e-9d97c3d86794')
  .then(d => console.log(d))
  .catch(e => console.log(e));

// Получить текущего пользователя
wrapper.user.get()
  .then(u => console.log(d))
  .catch(e => console.log(e));

// Получить список узлов в радиусе 3 узлов
wrapper.map.getRadius('b64578f3-2db6-40a3-954e-9d97c3d86794', 3)
  .then(u => console.log(d))
  .catch(e => console.log(e));

// Удаление всех карт у пользователя
wrapper.global.getMaps()
  .then(d => {
    console.log(d)
    return d;
  })
  .then(async(result) => {
    for await (let map of result) {
      await wrapper.map.delete(map.id);
    }
  })
  .catch(e => console.log(e));