UNPKG

textiot

Version:

A framework for building web and native (IoT) Dapps on the IPFS network

87 lines (86 loc) 3.16 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); const api_1 = require("../core/api"); /** * Cafes is an API module for managing Cafe access, messages, and services * * Cafes are other peers on the network who offer pinning, backup, and inbox services. * * @extends API */ class Cafes extends api_1.API { /** * Registers with a cafe and saves an expiring service session token * * An access token is required to register, and should be obtained separately from the target * Cafe. * * @param cafe The host Cafe address * @param token An access token supplied by the target Cafe * @see Tokens#create * @returns A new Cafe session JWT */ add(cafe, token) { return __awaiter(this, void 0, void 0, function* () { const response = yield this.sendPost(`cafes`, [cafe], { token }); return response.json(); }); } /** * Retrieves information about a cafe session * * @param id ID of the target Cafe * @returns A Cafe session JWT */ get(id) { return __awaiter(this, void 0, void 0, function* () { const response = yield this.sendGet(`cafes/${id}`); return response.json(); }); } /** * Retrieves information about all active cafe sessions * @returns An array of Cafe session JWTs */ list() { return __awaiter(this, void 0, void 0, function* () { const response = yield this.sendGet('cafes'); return response.json(); }); } /** * Checkes for messages at all cafes. * * New messages are downloaded and processed opportunistically. * @returns Whether the operation was successfull */ messages() { return __awaiter(this, void 0, void 0, function* () { const response = yield this.sendPost('cafes/messages'); return response.status === 200; }); } /** * Deregisters with a cafe and removes local session data * * Note: pinned content will expire based on the Cafe’s service rules. * @param id ID of the target Cafe * @returns Whether the deregistration was successfull */ remove(id) { return __awaiter(this, void 0, void 0, function* () { const response = yield this.sendDelete(`cafes/${id}`); return response.status === 204; }); } } exports.default = Cafes;