UNPKG

@mentaport/certificates-projects

Version:

Mentaport certificate-projects SDK, for certificate admins.

310 lines (299 loc) 10.9 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var common = require('@mentaport/common'); const developer = "https://public.api.mentaport.xyz/admin/dev/projects"; const staging = "https://public.api.mentaport.xyz/admin/staging/projects"; const production = "https://public.api.mentaport.xyz/admin/prod/v1/projects"; function GetProjectsBaseURL(environment) { let baseIp = developer; if (environment === common.Environment.STAGING) { baseIp = staging; } else if (environment === common.Environment.PRODUCTION) { baseIp = production; } return baseIp; } /****************************************************************************** Copyright (c) Microsoft Corporation. Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ***************************************************************************** */ function __awaiter(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()); }); } class ProjectsSDK extends common.Base { /** * Function to create a new project for certificates for a user * * @param {project.contractId} ContractId of contract where adding projcect * @param {project.projectName} Name of project * @param {project.ownerName} Name of project user * @param {project.email} Email of project user (optional) * @param {project.ownerWallet} Owner wallet of user (optional) * @param {project.projectBaseURI} projectBaseURI of contract (optional) * @param {customerId} CustomerId (optional if have more than one customer) * * @returns {IResults<ICertificateProject>} Returns if succeded the contract created */ createNewCertificateProject(newProject) { const _super = Object.create(null, { request: { get: () => super.request } }); return __awaiter(this, void 0, void 0, function* () { try { return yield _super.request.call(this, { url: `/new`, method: "POST", data: JSON.stringify(newProject), }); } catch (error) { return Promise.reject(error); } }); } /** * Function to activate a project in a contract * * @param {contractId} ContractId * @param {projectId} ProjectId * * @returns {IResults<boolean>} Returns contract activated status */ activateProject(contractId, projectId) { const _super = Object.create(null, { request: { get: () => super.request } }); return __awaiter(this, void 0, void 0, function* () { try { const activate = { projectId, contractId, }; return yield _super.request.call(this, { url: `/activate`, method: "POST", data: JSON.stringify(activate), }); } catch (error) { return Promise.reject(error); } }); } /** * Function to retrieve projects from customer in contracts * - most of users only have one contract with multiple projects * @param {contractId} ContractId (optional to get project just from one contract) * @param {customerId} CustomerId (optional if have more than one customer) * * @returns {IResults<T>} Returns all contract */ getProjects(contractId, customerId) { const _super = Object.create(null, { request: { get: () => super.request } }); return __awaiter(this, void 0, void 0, function* () { try { const params = { contractId, customerId }; return yield _super.request.call(this, { url: `/`, method: "GET", params: params }); } catch (error) { return Promise.reject(error); } }); } /** * Function to retrieve project by its Id * @param {contractId} ContractId * @param {projectId} ProjectId * @param {customerId} CustomerId (optional if have more than one customer) * * @returns {IResults<ICertificateProject>} Returns contract */ getProjectById(contractId, projectId, customerId) { const _super = Object.create(null, { request: { get: () => super.request } }); return __awaiter(this, void 0, void 0, function* () { try { const params = { contractId, projectId, customerId }; return yield _super.request.call(this, { url: `/`, method: "GET", params: params }); } catch (error) { return Promise.reject(error); } }); } /** * Function to update project before it is activated. * * @param {updateProject} Information to update * @param {customerId} CustomerId (optional if have more than one customer) * * @returns {IResults<ICertificateProject>} Returns updated contract */ updateProjectById(updateProject) { const _super = Object.create(null, { request: { get: () => super.request } }); return __awaiter(this, void 0, void 0, function* () { try { return yield _super.request.call(this, { url: `/update`, method: "PUT", data: JSON.stringify(updateProject) }); } catch (error) { return Promise.reject(error); } }); } /** * Function to update project status after being activated * * @param {updateProjectStatus} Status to update * @param {customerId} CustomerId (optional if have more than one customer) * * @returns {IResults<ICertificateProject>} Returns updated contract */ updateProjectStatusById(updateProjectStatus) { const _super = Object.create(null, { request: { get: () => super.request } }); return __awaiter(this, void 0, void 0, function* () { try { return yield _super.request.call(this, { url: `/update/status`, method: "PUT", data: JSON.stringify(updateProjectStatus) }); } catch (error) { return Promise.reject(error); } }); } /** * Function to retrieve contracts from customer * All contracts will be return if all is true (active and non active) * @param {allContracts} Boolean to get all contracts, not just active * * @returns {IResults<T>} Returns contract */ getContracts(allContracts) { const _super = Object.create(null, { request: { get: () => super.request } }); return __awaiter(this, void 0, void 0, function* () { try { return yield _super.request.call(this, { url: `/contracts`, method: "GET", params: { allContracts } }); } catch (error) { return Promise.reject(error); } }); } } class CertificateProjectsSDK extends common.Base { /** * Constructor for Supplement SDK * * @param {apiKey} APIKey * * @returns {} */ constructor(apiKey) { super(apiKey); } //-------------------------------------------------------------------- //------------------- PUBLIC FUNCTION ------------------------------- //-------------------------------------------------------------------- /** * Function to set the client with default env Production * All users have to call this function * * @param {url} urlPath (optional) * * @returns {void} */ setClient() { const _url = GetProjectsBaseURL(common.Environment.PRODUCTION); super.setClientSide(_url); } /** * Function to set the client environment. * All users have to call this function * * @param {environment} Environment to run sdk in * @param {url} urlPath (optional-only for testing) * * @returns {void} */ setClientEnv(environment, url) { const _url = GetProjectsBaseURL(environment); if (url) { super.setClientSide(url); } else { super.setClientSide(_url); } } } common.applyCombination(CertificateProjectsSDK, [ProjectsSDK]); Object.defineProperty(exports, 'BlockchainTypes', { enumerable: true, get: function () { return common.BlockchainTypes; } }); Object.defineProperty(exports, 'ContractEnvironment', { enumerable: true, get: function () { return common.ContractEnvironment; } }); Object.defineProperty(exports, 'ContractStatus', { enumerable: true, get: function () { return common.ContractStatus; } }); Object.defineProperty(exports, 'Environment', { enumerable: true, get: function () { return common.Environment; } }); Object.defineProperty(exports, 'MentaportUtils', { enumerable: true, get: function () { return common.MentaportUtils; } }); exports.CertificateProjectsSDK = CertificateProjectsSDK; //# sourceMappingURL=index.js.map