UNPKG

@devopness/sdk-js

Version:

Devopness API JS/TS SDK - Painless essential DevOps to everyone

100 lines (99 loc) 5.87 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DevopnessApiClient = void 0; const ActionService_1 = require("./services/ActionService"); const ApiBaseService_1 = require("./services/ApiBaseService"); const ApplicationService_1 = require("./services/ApplicationService"); const CredentialService_1 = require("./services/CredentialService"); const CronJobService_1 = require("./services/CronJobService"); const DaemonService_1 = require("./services/DaemonService"); const EnvironmentService_1 = require("./services/EnvironmentService"); const HookRequestService_1 = require("./services/HookRequestService"); const HookService_1 = require("./services/HookService"); const LogService_1 = require("./services/LogService"); const NetworkRuleService_1 = require("./services/NetworkRuleService"); const NetworkService_1 = require("./services/NetworkService"); const OrganizationService_1 = require("./services/OrganizationService"); const PipelineService_1 = require("./services/PipelineService"); const ProjectService_1 = require("./services/ProjectService"); const ResourceEventService_1 = require("./services/ResourceEventService"); const ResourceLinkService_1 = require("./services/ResourceLinkService"); const RoleService_1 = require("./services/RoleService"); const ServerService_1 = require("./services/ServerService"); const ServiceService_1 = require("./services/ServiceService"); const SocialAccountService_1 = require("./services/SocialAccountService"); const SshKeyService_1 = require("./services/SshKeyService"); const SslCertificateService_1 = require("./services/SslCertificateService"); const StaticService_1 = require("./services/StaticService"); const SubnetService_1 = require("./services/SubnetService"); const TeamInvitationService_1 = require("./services/TeamInvitationService"); const TeamService_1 = require("./services/TeamService"); const UserService_1 = require("./services/UserService"); const VariableService_1 = require("./services/VariableService"); const VirtualHostService_1 = require("./services/VirtualHostService"); class DevopnessApiClient { constructor(options) { ApiBaseService_1.ApiBaseService.configuration = new ApiBaseService_1.Configuration(options || {}); // we initialize the services explicitly, instead of auto initialize them on property declaration in the beginning of the class, // cause some (or all) of them depend on `ApiBaseService.configuration` property be set. Furthermore, we ensure all assertions // for non provided required parameters are quickly returned to the end user before spending time loading extra resources this.actions = new ActionService_1.ActionService(); this.applications = new ApplicationService_1.ApplicationService(); this.credentials = new CredentialService_1.CredentialService(); this.cronjobs = new CronJobService_1.CronJobService(); this.daemons = new DaemonService_1.DaemonService(); this.environments = new EnvironmentService_1.EnvironmentService(); this.hookRequests = new HookRequestService_1.HookRequestService(); this.hooks = new HookService_1.HookService(); this.logs = new LogService_1.LogService(); this.networkRules = new NetworkRuleService_1.NetworkRuleService(); this.networks = new NetworkService_1.NetworkService(); this.organizations = new OrganizationService_1.OrganizationService(); this.pipelines = new PipelineService_1.PipelineService(); this.projects = new ProjectService_1.ProjectService(); this.resourceEvents = new ResourceEventService_1.ResourceEventService(); this.resourceLinks = new ResourceLinkService_1.ResourceLinkService(); this.roles = new RoleService_1.RoleService(); this.servers = new ServerService_1.ServerService(); this.services = new ServiceService_1.ServiceService(); this.socialAccounts = new SocialAccountService_1.SocialAccountService(); this.sshKeys = new SshKeyService_1.SshKeyService(); this.sslCertificates = new SslCertificateService_1.SslCertificateService(); this.static = new StaticService_1.StaticService(); this.subnets = new SubnetService_1.SubnetService(); this.teamInvitations = new TeamInvitationService_1.TeamInvitationService(); this.teams = new TeamService_1.TeamService(); this.users = new UserService_1.UserService(); this.variables = new VariableService_1.VariableService(); this.virtualHosts = new VirtualHostService_1.VirtualHostService(); this.onTokenExpired = () => { // do nothing. }; } get accessToken() { return ApiBaseService_1.ApiBaseService.accessToken; } set accessToken(accessToken) { const MIN_TOKEN_LENGHT = 100; /** * As a complete access token validation rule might be too much to be implemented here, we * at least check for min length and return a substring of it to help users identify the * issue when first initializing this SDK from their apps */ if (accessToken && accessToken.length < MIN_TOKEN_LENGHT) { throw new Error(`"${accessToken.substring(0, 10)} ..." doesn't seem to be a valid access token issued by Devopness API.`); } ApiBaseService_1.ApiBaseService.accessToken = accessToken; } /** * * @summary Sets the callback function to be executed when the access token expires. * @static * @param {function(string)} callback - The callback function to be executed. * This function should accept a single string parameter representing the expired access token. */ set onTokenExpired(callback) { ApiBaseService_1.ApiBaseService.onTokenExpired = callback; } } exports.DevopnessApiClient = DevopnessApiClient;