@signiant/media-shuttle-sdk
Version:
The SDK for supporting file transfer to and from Media Shuttle
234 lines (232 loc) • 14.1 kB
JavaScript
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
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 __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
import { keyBy, sortBy, groupBy } from 'lodash';
import { RoleTypes, } from '../../external/navigation/Explorer';
var PlatformExplorer = /** @class */ (function () {
function PlatformExplorer(options) {
this._platformService = options.platformService;
}
PlatformExplorer.prototype.validMediaShuttleServices = function (showExpired) {
var nowMillis = new Date().getTime();
var isExpired = function (_a) {
var effectiveContractDetails = _a.effectiveContractDetails, expiresOn = _a.expiresOn;
if (effectiveContractDetails) {
return effectiveContractDetails.isExpired;
}
return expiresOn && nowMillis >= new Date(expiresOn).getTime();
};
return function (service) {
return service.serviceType === 'MEDIASHUTTLE' && (showExpired || !isExpired(service));
};
};
/**
* Lists all accounts a user has access to including the serviceId
* @param {boolean} showExpired | allows the user to retrieve information about expired accounts
* @returns {Promise<AccountListResponse>}
*/
PlatformExplorer.prototype.listAccounts = function (showExpired) {
if (showExpired === void 0) { showExpired = false; }
return __awaiter(this, void 0, void 0, function () {
var _a, accounts, services, roles, accountMap, msRolesByAccountId, msAccountsAndServices;
return __generator(this, function (_b) {
switch (_b.label) {
case 0: return [4 /*yield*/, this._platformService.getProfile()];
case 1:
_a = _b.sent(), accounts = _a.accounts, services = _a.services, roles = _a.roles;
accountMap = keyBy(accounts.items, 'accountId');
msRolesByAccountId = groupBy(roles.items.filter(function (_a) {
var role = _a.role;
return role.startsWith('MEDIA_SHUTTLE_');
}), 'accountId');
msAccountsAndServices = sortBy(services.items
.filter(this.validMediaShuttleServices(showExpired))
.map(function (_a) {
var _b;
var serviceId = _a.serviceId, serviceInfo = _a.serviceInfo, accountId = _a.accountId;
return ({
serviceId: serviceId,
accountId: accountId,
msAccountId: serviceInfo,
name: accountMap[accountId].accountName,
mfaEnabled: accountMap[accountId].authenticationConfig.mfaEnabled,
roles: (_b = msRolesByAccountId[accountId]) === null || _b === void 0 ? void 0 : _b.map(function (_a) {
var role = _a.role;
return RoleTypes[role];
}),
});
}), function (_a) {
var name = _a.name;
return name.toLowerCase();
});
return [2 /*return*/, {
mediaShuttleAccounts: msAccountsAndServices,
}];
}
});
});
};
/**
* This function returns a list of portals for a given account and service
* @param {PortalListRequest} requestObject | request object
* @param {string} requestObject.accountId | account identifier
* @param {string} requestObject.serviceId | service identifier
* @param {string} requestObject.showExpired | flag to include expired portals in the response
* @param {string} requestObject.limitPortalsToMemberRole | get all portals the user making the request is MEMBER of.
* @returns A list of portals
*/
PlatformExplorer.prototype.listPortals = function (_a) {
var accountId = _a.accountId, serviceId = _a.serviceId, _b = _a.showExpired, showExpired = _b === void 0 ? false : _b, _c = _a.limitPortalsToMemberRole, limitPortalsToMemberRole = _c === void 0 ? true : _c;
return __awaiter(this, void 0, void 0, function () {
var portals, cursor, _d, items, nextCursor;
return __generator(this, function (_e) {
switch (_e.label) {
case 0:
portals = [];
cursor = null;
_e.label = 1;
case 1: return [4 /*yield*/, this._platformService.getPortals(__assign(__assign({ accountId: accountId, serviceId: serviceId, pageSize: 100 }, (cursor && { cursor: cursor })), (limitPortalsToMemberRole && { limitPortalsToMemberRole: limitPortalsToMemberRole })))];
case 2:
_d = _e.sent(), items = _d.items, nextCursor = _d.nextCursor;
portals.push.apply(portals, items);
cursor = nextCursor;
_e.label = 3;
case 3:
if (cursor) return [3 /*break*/, 1];
_e.label = 4;
case 4: return [2 /*return*/, sortBy(portals
.map(function (_a) {
var portalId = _a.portalId, name = _a.name, url = _a.url, createdOn = _a.createdOn, expiresOn = _a.expiresOn, lastModifiedOn = _a.lastModifiedOn, accountId = _a.accountId, type = _a.type;
return (__assign(__assign({ portalId: portalId, name: name, url: url, createdOn: new Date(createdOn) }, (expiresOn && { expiresOn: new Date(expiresOn) })), { lastModifiedOn: new Date(lastModifiedOn), accountId: accountId, type: type }));
})
.filter(function (_a) {
var expiresOn = _a.expiresOn;
return showExpired || !expiresOn || new Date().getTime() < expiresOn.getTime();
}), function (_a) {
var name = _a.name;
return name.toLowerCase();
})];
}
});
});
};
/**
* @ignore
* It gets the contents of a portal folder.
* @param {GetFolderContentRequest} - Request Object | Includes all the required parameters in order to perform the getFolderContent request
* @param {GetFolderContentRequest} GetFolderContentRequest.accountId - **accountId**: The ID of the Account Containing the Media Shuttle Service.
* @param {GetFolderContentRequest} GetFolderContentRequest.portalId - **portalId**: The ID of portal.
* @param {GetFolderContentRequest} GetFolderContentRequest.serviceId - **serviceId**: The ID of the Media Shuttle Service.
* @param {GetFolderContentRequest} GetFolderContentRequest.folderId - **folderId**: Folder Identifier (optional) if not send the home folder is assumed.
* @param {GetFolderContentRequest} GetFolderContentRequest.browsePath - **browsePath**: path of the subfolder to look for relative to the provided folderId
* @returns A list of files/folders in the folder.
*/
PlatformExplorer.prototype.getFolderContent = function (_a) {
var accountId = _a.accountId, serviceId = _a.serviceId, portalId = _a.portalId, folderId = _a.folderId, browsePath = _a.browsePath;
return __awaiter(this, void 0, void 0, function () {
var items;
return __generator(this, function (_b) {
switch (_b.label) {
case 0: return [4 /*yield*/, this._platformService.getFolderContent({
accountId: accountId,
portalId: portalId,
serviceId: serviceId,
folderId: folderId,
browsePath: browsePath,
})];
case 1:
items = (_b.sent()).items;
return [2 /*return*/, items];
}
});
});
};
/**
* It gets the permissions for a member of a portal.
* @param {PortalBasicRequest} requestObject - Request Object | Includes all the required parameters in order to perform te getPortalMemberPermissions request
* @param {string} requestObject.accountId - **accountId**: The ID of the Account Containing the Media Shuttle Service.
* @param {string} requestObject.serviceId - **serviceId**: The ID of the Media Shuttle Service.
* @param {string} requestObject.portalId - **portalId**: The ID of portal.
* @returns The permissions for the portal member.
*/
PlatformExplorer.prototype.getPortalMemberPermissions = function (_a) {
var accountId = _a.accountId, serviceId = _a.serviceId, portalId = _a.portalId;
return this._platformService.getPortalMemberPermissions({ accountId: accountId, portalId: portalId, serviceId: serviceId });
};
/**
* Fetches the metadata form definitions configured for the specified portal.
*
* Delegates to the underlying platform service to retrieve the portal's metadata forms.
*
* @param accountId - The identifier of the account that owns the portal.
* @param serviceId - The identifier of the service under the account.
* @param portalId - The unique identifier of the portal.
* @returns A promise that resolves to the metadata form definition(s) associated with the portal.
* @throws {Error} If the request fails, the portal is not found, or access is denied.
*/
PlatformExplorer.prototype.getPortalMetadataForms = function (_a) {
var accountId = _a.accountId, serviceId = _a.serviceId, portalId = _a.portalId;
return this._platformService.getPortalMetadataForms({ accountId: accountId, serviceId: serviceId, portalId: portalId });
};
/**
* Retrieves a form definition by its identifier for the specified account and service.
*
* This method delegates to the underlying platform service to fetch a single form definition resource.
*
* @param accountId - The unique identifier of the account that owns the service.
* @param serviceId - The unique identifier of the service within the account.
* @param formDefinitionId - The unique identifier of the form definition to retrieve.
* @returns A promise that resolves to the requested form definition object.
* @throws {Error} If the request fails due to network issues, authorization problems, or if the form definition cannot be found.
*/
PlatformExplorer.prototype.getFormDefinitionById = function (_a) {
var accountId = _a.accountId, serviceId = _a.serviceId, formDefinitionId = _a.formDefinitionId;
return this._platformService.getFormDefinitionById({ accountId: accountId, serviceId: serviceId, formDefinitionId: formDefinitionId });
};
return PlatformExplorer;
}());
export default PlatformExplorer;