UNPKG

livelists-node-js

Version:
70 lines 3.11 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()); }); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.ParticipantClient = void 0; const TwirpRPC_1 = require("../common/TwirpRPC"); const RPCPackages_1 = require("../common/const/RPCPackages"); const participant_1 = require("../proto/participant"); const BaseService_1 = __importDefault(require("./BaseService")); const ParticipantErrors_1 = require("./errors/ParticipantErrors"); const svc = 'ParticipantService'; class ParticipantClient extends BaseService_1.default { constructor({ apiHost, apiKey, secretKey, }) { super(apiKey, secretKey); this.rpc = new TwirpRPC_1.TwirpRpc({ host: apiHost, pkg: RPCPackages_1.RPCPackages.Participant, }); } addParticipantToChannel({ identifier, channelId, grants, customData, }) { return __awaiter(this, void 0, void 0, function* () { const req = participant_1.AddParticipantToChannelReq.toJSON({ channelId, identifier, grants, customData: customData ? { data: Object.assign({}, customData) } : undefined, }); const data = yield this.rpc.request({ service: svc, method: 'AddParticipantToChannel', data: req, headers: this.rootAuthHeader(), }); if (data.errors.length > 0) { throw new ParticipantErrors_1.AddParticipantToChannelError(data); } return data; }); } getAccessToken({ identifier, channelId, }) { return __awaiter(this, void 0, void 0, function* () { const req = participant_1.GetParticipantAccessTokenReq.toJSON({ identifier, channelId, }); const data = yield this.rpc.request({ service: svc, method: 'GetParticipantAccessToken', data: req, headers: this.rootAuthHeader(), }); if (data.errors.length > 0) { throw new ParticipantErrors_1.GetAccessTokenError(data); } return data; }); } } exports.ParticipantClient = ParticipantClient; //# sourceMappingURL=ParticipantClient.js.map