UNPKG

@signiant/media-shuttle-sdk

Version:

The SDK for supporting file transfer to and from Media Shuttle

170 lines (169 loc) 8.49 kB
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 { signiant_private } from '@signiant/media-shuttle-sdk-base'; import LoginCredentials from './common/LoginCredentials'; import PlatformService from '../internal/services/PlatformService'; import PlatformExplorer from '../internal/navigation/PlatformExplorer'; import PlatformDownload from '../internal/transfer/PlatformDownload'; import PlatformUpload from '../internal/transfer/PlatformUpload'; import urlConstants from '../internal/constants/urlConstants'; /** * A factory class for generating resources to perform Media Shuttle actions. * * Create a factory instance as follows: * * @example * ``` * import { MediaShuttleResourceFactory, LoginCredentials, Explorer } from '@signiant/media-shuttle-sdk'; * const loginCredentials:LoginCredentials = new LoginCredentials({ * username: 'sample.user@signiant.com', * password: 'replace_with_real_password' * }); * const resourceFactory:MediaShuttleResourceFactory = new MediaShuttleResourceFactory(loginCredentials, {}); * ``` */ var MediaShuttleResourceFactory = /** @class */ (function () { /** * @param credentials The credentials wrapper to allow for the creation and update of transfers. * Typically {@link LoginCredentials} would be used * @param sdkOptions See {@link SDKOptions} for more details. */ function MediaShuttleResourceFactory(credentials, options) { if (options === void 0) { options = {}; } var _a = options, _b = _a.platformApiEndpoint, platformApiEndpoint = _b === void 0 ? urlConstants.PROD_PLATFORM_API_ENDPOINT : _b, _c = _a.messagingServiceUrl, messagingServiceUrl = _c === void 0 ? urlConstants.PROD_MESSAGING_SERVICE_URL : _c, _d = _a.transferClient, transferClient = _d === void 0 ? new signiant_private.AppClient({ messageServiceUrl: messagingServiceUrl, }) : _d; if (credentials instanceof LoginCredentials) { credentials.baseUrl = platformApiEndpoint; } this._platformService = new PlatformService({ baseUrl: platformApiEndpoint, credentials: credentials, }); this._transferClient = transferClient; } /** * See the {@link Explorer} documentation on how to make calls to find the necessary input (portalId, files, serviceId, accountId) for * Download generation. * * @example * ``` * import { MediaShuttleResourceFactory, Download, DownloadOptions } from '@signiant/media-shuttle-sdk' * createDownload (resourceFactory: MediaShuttleResourceFactory, portalId: string, files: RemoteFile[], serviceId: string, accountId: string): Promise<Download> { * const downloadOptions: DownloadOptions = { * portalId, * files, * serviceId, * accountId, * } * return resourceFactory.generateDownload(downloadOptions); * } * ``` * * @param options The {@link PlatformDownloadOptions} to control how the {@link Download} will operate * @returns The {@link Download} transfer object. */ MediaShuttleResourceFactory.prototype.generateDownload = function (options) { return __awaiter(this, void 0, void 0, function () { var download; return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, this._transferClient.initialize({ force: options.force })]; case 1: _a.sent(); download = new PlatformDownload(__assign(__assign({}, options), { transferClient: this._transferClient, platformService: this._platformService })); return [2 /*return*/, download]; } }); }); }; /** * See the {@link Explorer} documentation on how to make calls to find the necessary input (portalId, accountId and serviceId) for * Upload generation. * * @example * ``` * import { MediaShuttleResourceFactory, Upload, PlatformTransferOptions } from '@signiant/media-shuttle-sdk' * createUpload (resourceFactory: MediaShuttleResourceFactory, portalId: string, serviceId: string, accountId: string): Promise<Upload> { * const uploadOptions: PlatformTransferOptions = { * portalId, * serviceId, * accountId, * } * return resourceFactory.generateUpload(uploadOptions); * } * ``` * * @param options The {@link PlatformUploadOptions} to control how the {@link Upload} will operate * @returns The {@link Upload} transfer object. */ MediaShuttleResourceFactory.prototype.generateUpload = function (options) { return __awaiter(this, void 0, void 0, function () { var upload; return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, this._transferClient.initialize({ force: options.force })]; case 1: _a.sent(); upload = new PlatformUpload(__assign({ transferClient: this._transferClient, platformService: this._platformService }, options)); return [2 /*return*/, upload]; } }); }); }; /** * @returns The {@link Explorer} instance */ MediaShuttleResourceFactory.prototype.getExplorer = function () { return new PlatformExplorer({ platformService: this._platformService, }); }; return MediaShuttleResourceFactory; }()); export default MediaShuttleResourceFactory;