UNPKG

@hubs101/js-api-skd-client

Version:
264 lines (263 loc) 16.2 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 }); exports._deleteFeed = exports._updateFeed = exports._createFeed = exports._fetchFeed = exports._fetchFeeds = exports._updateSessionTypes = exports._fetchSessionTypes = exports._updatePackages = exports._deleteColocatedEvents = exports._editColocatedEvents = exports._createColocatedEvents = exports._fetchColocatedEventDetails = exports._fetchColocatedEvents = exports._updateAccountGroup = exports._createAccountGroup = exports._fetchAccountGroups = exports._fetchEventsByAccount = exports._fetchAccountEvents = exports._deletePaymentAccount = exports._deleteSalesManager = exports._deleteFinanceManager = exports._inviteSalesManager = exports._inviteFinanceManager = exports._confirmManagerNative = exports._confirmManager = exports._registerManagerNative = exports._registerManager = exports._deleteContentManager = exports._inviteContentManager = exports._updatePaymentAccount = exports._createPaymentAccount = exports._fetchPaymentAccounts = exports._fetchPaymentAccount = exports._sendNewPassword = exports._resetPassword = exports._logout = exports._login = void 0; const api_1 = require("../../utils/api"); const base_1 = require("../../utils/base"); const _login = (basePath, email, password) => __awaiter(void 0, void 0, void 0, function* () { if (!email) { return null; } const base = (0, base_1.getBasePath)(basePath); return (0, api_1.postRequest)(base.AUTH.LOGIN, { email, password, }); }); exports._login = _login; const _logout = (basePath, token) => __awaiter(void 0, void 0, void 0, function* () { if (!token) { return null; } const base = (0, base_1.getBasePath)(basePath); return yield (0, api_1.getRequest)(base.AUTH.LOGOUT, token); }); exports._logout = _logout; const _resetPassword = (basePath, body) => __awaiter(void 0, void 0, void 0, function* () { if (!basePath) { return null; } return (0, api_1.postRequest)(`${basePath}/v1/auth/password-reset-request`, body); }); exports._resetPassword = _resetPassword; const _sendNewPassword = (basePath, userId, body) => __awaiter(void 0, void 0, void 0, function* () { if (!basePath) { return null; } return (0, api_1.postRequest)(`${basePath}/v1/users/${userId}/reset-password`, body); }); exports._sendNewPassword = _sendNewPassword; const _fetchPaymentAccount = (basePath, token, paymentAccountId) => __awaiter(void 0, void 0, void 0, function* () { const base = (0, base_1.getBasePath)(basePath); const { data: paymentAccount } = yield (0, api_1.getRequest)(`${base.PAYMENT_ACCOUNTS}/${paymentAccountId}/`, token); return paymentAccount; }); exports._fetchPaymentAccount = _fetchPaymentAccount; const _fetchPaymentAccounts = (basePath, token, accountId) => __awaiter(void 0, void 0, void 0, function* () { const base = (0, base_1.getBasePath)(basePath); const { data: paymentAccounts } = yield (0, api_1.getRequest)(`${base.ACCOUNTS}/${accountId}/payment-accounts`, token); return paymentAccounts; }); exports._fetchPaymentAccounts = _fetchPaymentAccounts; const _createPaymentAccount = (basePath, token, data) => __awaiter(void 0, void 0, void 0, function* () { const base = (0, base_1.getBasePath)(basePath); const response = yield (0, api_1.postRequestWE)(base.PAYMENT_ACCOUNTS, data, token); return response; }); exports._createPaymentAccount = _createPaymentAccount; const _updatePaymentAccount = (basePath, token, paymentAccountId, data) => __awaiter(void 0, void 0, void 0, function* () { const base = (0, base_1.getBasePath)(basePath); const response = yield (0, api_1.putRequest)(`${base.PAYMENT_ACCOUNTS}/${paymentAccountId}`, token, data); return response; }); exports._updatePaymentAccount = _updatePaymentAccount; const _inviteContentManager = (basePath, token, accountId, data) => __awaiter(void 0, void 0, void 0, function* () { const base = (0, base_1.getBasePath)(basePath); const response = yield (0, api_1.postRequestWE)(`${base.ACCOUNTS}/${accountId}/managers/content-managers`, data, token); return response; }); exports._inviteContentManager = _inviteContentManager; const _deleteContentManager = (basePath, token, accountId, profileId) => __awaiter(void 0, void 0, void 0, function* () { const base = (0, base_1.getBasePath)(basePath); const response = yield (0, api_1.deleteRequestWE)(`${base.ACCOUNTS}/${accountId}/managers/content-managers/${profileId}`, token); return response; }); exports._deleteContentManager = _deleteContentManager; const _registerManager = (basePath, accountId, data) => __awaiter(void 0, void 0, void 0, function* () { const base = (0, base_1.getBasePath)(basePath); const response = yield (0, api_1.postRequestWE)(`${base.PUBLIC_INVITATIONS}/accounts/${accountId}/managers/register`, data); return response; }); exports._registerManager = _registerManager; const _registerManagerNative = (basePath, accountId, data) => __awaiter(void 0, void 0, void 0, function* () { const base = (0, base_1.getBasePath)(basePath); const response = yield (0, api_1.postRequestSimple)(`${base.PUBLIC_INVITATIONS}/accounts/${accountId}/managers/register`, data); return response; }); exports._registerManagerNative = _registerManagerNative; const _confirmManager = (basePath, accountId, data) => __awaiter(void 0, void 0, void 0, function* () { const base = (0, base_1.getBasePath)(basePath); const response = yield (0, api_1.postRequestWE)(`${base.PUBLIC_INVITATIONS}/accounts/${accountId}/managers/confirm`, data); return response; }); exports._confirmManager = _confirmManager; const _confirmManagerNative = (basePath, accountId, data) => __awaiter(void 0, void 0, void 0, function* () { const base = (0, base_1.getBasePath)(basePath); const response = yield (0, api_1.postRequestSimple)(`${base.PUBLIC_INVITATIONS}/accounts/${accountId}/managers/confirm`, data); return response; }); exports._confirmManagerNative = _confirmManagerNative; const _inviteFinanceManager = (basePath, token, accountId, data) => __awaiter(void 0, void 0, void 0, function* () { const base = (0, base_1.getBasePath)(basePath); const response = yield (0, api_1.postRequestWE)(`${base.ACCOUNTS}/${accountId}/managers/finances`, data, token); return response; }); exports._inviteFinanceManager = _inviteFinanceManager; const _inviteSalesManager = (basePath, token, accountId, data) => __awaiter(void 0, void 0, void 0, function* () { const base = (0, base_1.getBasePath)(basePath); const response = yield (0, api_1.postRequestWE)(`${base.ACCOUNTS}/${accountId}/managers/sales-managers`, data, token); return response; }); exports._inviteSalesManager = _inviteSalesManager; const _deleteFinanceManager = (basePath, token, accountId, profileId) => __awaiter(void 0, void 0, void 0, function* () { const base = (0, base_1.getBasePath)(basePath); const response = yield (0, api_1.deleteRequestWE)(`${base.ACCOUNTS}/${accountId}/managers/finances/${profileId}`, token); return response; }); exports._deleteFinanceManager = _deleteFinanceManager; const _deleteSalesManager = (basePath, token, accountId, profileId) => __awaiter(void 0, void 0, void 0, function* () { const base = (0, base_1.getBasePath)(basePath); const response = yield (0, api_1.deleteRequestWE)(`${base.ACCOUNTS}/${accountId}/managers/sales-managers/${profileId}`, token); return response; }); exports._deleteSalesManager = _deleteSalesManager; const _deletePaymentAccount = (basePath, token, paymentAccountId) => __awaiter(void 0, void 0, void 0, function* () { const base = (0, base_1.getBasePath)(basePath); const response = yield (0, api_1.deleteRequestWE)(`${base.PAYMENT_ACCOUNTS}/${paymentAccountId}`, token); return response; }); exports._deletePaymentAccount = _deletePaymentAccount; const _fetchAccountEvents = (basePath, token, url) => __awaiter(void 0, void 0, void 0, function* () { const response = yield (0, api_1.getRequest)(url, token); return response; }); exports._fetchAccountEvents = _fetchAccountEvents; const _fetchEventsByAccount = (basePath, token, accountId, params) => __awaiter(void 0, void 0, void 0, function* () { const base = (0, base_1.getBasePath)(basePath); const url = params ? `${base.ACCOUNTS}/${accountId}/events?${params}` : `${base.ACCOUNTS}/${accountId}/events`; const response = yield (0, api_1.getRequest)(url, token); return response; }); exports._fetchEventsByAccount = _fetchEventsByAccount; const _fetchAccountGroups = (basePath, token, accountId, type) => __awaiter(void 0, void 0, void 0, function* () { const base = (0, base_1.getBasePath)(basePath); const groups = yield (0, api_1.getRequest)(`${base.ACCOUNTS}/${accountId}/groups?type=${type}`, token); return groups; }); exports._fetchAccountGroups = _fetchAccountGroups; const _createAccountGroup = (basePath, token, accountId, data) => __awaiter(void 0, void 0, void 0, function* () { const base = (0, base_1.getBasePath)(basePath); return (0, api_1.postRequestWE)(`${base.ACCOUNTS}/${accountId}/groups`, data, token); }); exports._createAccountGroup = _createAccountGroup; const _updateAccountGroup = (basePath, token, accountId, groupId, data) => __awaiter(void 0, void 0, void 0, function* () { const base = (0, base_1.getBasePath)(basePath); const groups = yield (0, api_1.putRequest)(`${base.ACCOUNTS}/${accountId}/groups/${groupId}`, token, data); return groups; }); exports._updateAccountGroup = _updateAccountGroup; const _fetchColocatedEvents = (basePath, token, accountId) => __awaiter(void 0, void 0, void 0, function* () { const base = (0, base_1.getBasePath)(basePath); const groups = yield (0, api_1.getRequest)(`${base.ACCOUNTS}/${accountId}/colocated-events`, token); return groups; }); exports._fetchColocatedEvents = _fetchColocatedEvents; const _fetchColocatedEventDetails = (basePath, token, accountId, eventId) => __awaiter(void 0, void 0, void 0, function* () { const base = (0, base_1.getBasePath)(basePath); const eventDetails = yield (0, api_1.getRequest)(`${base.ACCOUNTS}/${accountId}/colocated-events/${eventId}`, token); return (eventDetails === null || eventDetails === void 0 ? void 0 : eventDetails.data) || eventDetails; }); exports._fetchColocatedEventDetails = _fetchColocatedEventDetails; const _createColocatedEvents = (basePath, token, accountId, data) => __awaiter(void 0, void 0, void 0, function* () { const base = (0, base_1.getBasePath)(basePath); const groups = yield (0, api_1.postRequestWE)(`${base.ACCOUNTS}/${accountId}/colocated-events`, data, token); return groups; }); exports._createColocatedEvents = _createColocatedEvents; const _editColocatedEvents = (basePath, token, id, data) => __awaiter(void 0, void 0, void 0, function* () { const base = (0, base_1.getBasePath)(basePath); const groups = yield (0, api_1.putRequest)(`${base.ACCOUNTS}/colocated-events/${id}`, token, data); return groups; }); exports._editColocatedEvents = _editColocatedEvents; const _deleteColocatedEvents = (basePath, token, id) => __awaiter(void 0, void 0, void 0, function* () { const base = (0, base_1.getBasePath)(basePath); const response = yield (0, api_1.deleteRequestWE)(`${base.ACCOUNTS}/colocated-events/${id}`, token); return response; }); exports._deleteColocatedEvents = _deleteColocatedEvents; const _updatePackages = (basePath, token, accountId, data) => __awaiter(void 0, void 0, void 0, function* () { const base = (0, base_1.getBasePath)(basePath); const res = yield (0, api_1.putRequest)(`${base.ACCOUNTS}/${accountId}/packages`, token, data); return res; }); exports._updatePackages = _updatePackages; const _fetchSessionTypes = (basePath, token, accountId) => __awaiter(void 0, void 0, void 0, function* () { var _a; const base = (0, base_1.getBasePath)(basePath); const res = yield (0, api_1.getRequest)(`${base.ACCOUNTS}/${accountId}/session-types`, token); return ((_a = res === null || res === void 0 ? void 0 : res.data) === null || _a === void 0 ? void 0 : _a.data) || (res === null || res === void 0 ? void 0 : res.data) || res; }); exports._fetchSessionTypes = _fetchSessionTypes; const _updateSessionTypes = (basePath, token, accountId, data) => __awaiter(void 0, void 0, void 0, function* () { var _a; const base = (0, base_1.getBasePath)(basePath); const res = yield (0, api_1.putRequest)(`${base.ACCOUNTS}/${accountId}/session-types`, token, data); return ((_a = res === null || res === void 0 ? void 0 : res.data) === null || _a === void 0 ? void 0 : _a.data) || (res === null || res === void 0 ? void 0 : res.data) || res; }); exports._updateSessionTypes = _updateSessionTypes; const _fetchFeeds = (basePath, token, accountId, params) => __awaiter(void 0, void 0, void 0, function* () { const base = (0, base_1.getBasePath)(basePath); const url = params ? `${base.ACCOUNTS}/${accountId}/feeds?${params}` : `${base.ACCOUNTS}/${accountId}/feeds`; const feeds = yield (0, api_1.getRequest)(url, token); return feeds; }); exports._fetchFeeds = _fetchFeeds; const _fetchFeed = (basePath, token, accountId, feedId) => __awaiter(void 0, void 0, void 0, function* () { const base = (0, base_1.getBasePath)(basePath); const feed = yield (0, api_1.getRequest)(`${base.ACCOUNTS}/${accountId}/feeds/${feedId}`, token); return (feed === null || feed === void 0 ? void 0 : feed.data) || feed; }); exports._fetchFeed = _fetchFeed; const _createFeed = (basePath, token, accountId, data, files) => __awaiter(void 0, void 0, void 0, function* () { const base = (0, base_1.getBasePath)(basePath); const feed = yield (0, api_1.postFilesAndDataRequest)(`${base.ACCOUNTS}/${accountId}/feeds`, data, files, token); return feed; }); exports._createFeed = _createFeed; const _updateFeed = (basePath, token, accountId, feedId, data, files) => __awaiter(void 0, void 0, void 0, function* () { const base = (0, base_1.getBasePath)(basePath); const requestUrl = `${base.ACCOUNTS}/${accountId}/feeds/${feedId}`; const normalizedFiles = files !== null && files !== void 0 ? files : []; const hasBinaryFile = normalizedFiles.some((file) => (file === null || file === void 0 ? void 0 : file.value) && typeof file.value !== "string"); if ((data === null || data === void 0 ? void 0 : data.webinar_id) === null && !hasBinaryFile) { return (0, api_1.putRequestDirect)(requestUrl, token, data); } if ((data === null || data === void 0 ? void 0 : data.webinar_id) === null && hasBinaryFile) { yield (0, api_1.putRequestDirect)(requestUrl, token, data); const payloadWithoutWebinarId = Object.assign({}, data); delete payloadWithoutWebinarId.webinar_id; return (0, api_1.postFilesAndDataRequest)(requestUrl, payloadWithoutWebinarId, normalizedFiles, token, "put"); } const response = yield (0, api_1.postFilesAndDataRequest)(requestUrl, data, normalizedFiles, token, "put"); return response; }); exports._updateFeed = _updateFeed; const _deleteFeed = (basePath, token, accountId, feedId) => __awaiter(void 0, void 0, void 0, function* () { const base = (0, base_1.getBasePath)(basePath); const response = yield (0, api_1.deleteRequestWE)(`${base.ACCOUNTS}/${accountId}/feeds/${feedId}`, token); return response; }); exports._deleteFeed = _deleteFeed;