projectmanager-sdk
Version:
Software development kit for the ProjectManager.com API. for TypeScript
299 lines • 10.4 kB
JavaScript
/***
* ProjectManager API for TypeScript
*
* (c) 2023-2025 ProjectManager.com, Inc.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @author ProjectManager.com <support@projectmanager.com>
* @copyright 2023-2025 ProjectManager.com, Inc.
* @version 134.0.125
* @link https://github.com/projectmgr/projectmanager-sdk-typescript
*/
import { ApiKeyClient } from "./index.js";
import { ChangesetClient } from "./index.js";
import { DashboardClient } from "./index.js";
import { DiscussionClient } from "./index.js";
import { FileClient } from "./index.js";
import { HolidayClient } from "./index.js";
import { HomeFileClient } from "./index.js";
import { IntegrationClient } from "./index.js";
import { IntegrationCategoryClient } from "./index.js";
import { IntegrationProviderClient } from "./index.js";
import { LicenseClient } from "./index.js";
import { MeClient } from "./index.js";
import { NotificationClient } from "./index.js";
import { NptClient } from "./index.js";
import { NptFilesClient } from "./index.js";
import { NptStatusClient } from "./index.js";
import { ProjectClient } from "./index.js";
import { ProjectChargeCodeClient } from "./index.js";
import { ProjectCustomerClient } from "./index.js";
import { ProjectFieldClient } from "./index.js";
import { ProjectFileClient } from "./index.js";
import { ProjectFolderClient } from "./index.js";
import { ProjectMembersClient } from "./index.js";
import { ProjectPriorityClient } from "./index.js";
import { ProjectStatusClient } from "./index.js";
import { ProjectTemplateClient } from "./index.js";
import { ProjectVersionClient } from "./index.js";
import { ResourceClient } from "./index.js";
import { ResourceSkillClient } from "./index.js";
import { ResourceTeamClient } from "./index.js";
import { RiskClient } from "./index.js";
import { RiskFileClient } from "./index.js";
import { TagClient } from "./index.js";
import { TaskClient } from "./index.js";
import { TaskAssigneeClient } from "./index.js";
import { TaskFieldClient } from "./index.js";
import { TaskFileClient } from "./index.js";
import { TaskMetadataClient } from "./index.js";
import { TaskStatusClient } from "./index.js";
import { TaskTagClient } from "./index.js";
import { TaskTodoClient } from "./index.js";
import { TeamsClient } from "./index.js";
import { TimesheetClient } from "./index.js";
import { UserRoleClient } from "./index.js";
import { WorkSpaceClient } from "./index.js";
import axios from "axios";
import { default as FormData } from "form-data";
import fs from "fs";
import os from "os";
import url from "url";
/**
* Client object used to communicate with the API
*/
export class ProjectManagerClient {
// The URL of the environment we will use
serverUrl;
version = "134.0.125";
bearerToken = null;
sdkName = "TypeScript";
appName = null;
customHeaderFunc = null;
ApiKey;
Changeset;
Dashboard;
Discussion;
File;
Holiday;
HomeFile;
Integration;
IntegrationCategory;
IntegrationProvider;
License;
Me;
Notification;
Npt;
NptFiles;
NptStatus;
Project;
ProjectChargeCode;
ProjectCustomer;
ProjectField;
ProjectFile;
ProjectFolder;
ProjectMembers;
ProjectPriority;
ProjectStatus;
ProjectTemplate;
ProjectVersion;
Resource;
ResourceSkill;
ResourceTeam;
Risk;
RiskFile;
Tag;
Task;
TaskAssignee;
TaskField;
TaskFile;
TaskMetadata;
TaskStatus;
TaskTag;
TaskTodo;
Teams;
Timesheet;
UserRole;
WorkSpace;
/**
* Internal constructor for the API client
*/
constructor(customUrl) {
this.serverUrl = customUrl;
this.ApiKey = new ApiKeyClient(this);
this.Changeset = new ChangesetClient(this);
this.Dashboard = new DashboardClient(this);
this.Discussion = new DiscussionClient(this);
this.File = new FileClient(this);
this.Holiday = new HolidayClient(this);
this.HomeFile = new HomeFileClient(this);
this.Integration = new IntegrationClient(this);
this.IntegrationCategory = new IntegrationCategoryClient(this);
this.IntegrationProvider = new IntegrationProviderClient(this);
this.License = new LicenseClient(this);
this.Me = new MeClient(this);
this.Notification = new NotificationClient(this);
this.Npt = new NptClient(this);
this.NptFiles = new NptFilesClient(this);
this.NptStatus = new NptStatusClient(this);
this.Project = new ProjectClient(this);
this.ProjectChargeCode = new ProjectChargeCodeClient(this);
this.ProjectCustomer = new ProjectCustomerClient(this);
this.ProjectField = new ProjectFieldClient(this);
this.ProjectFile = new ProjectFileClient(this);
this.ProjectFolder = new ProjectFolderClient(this);
this.ProjectMembers = new ProjectMembersClient(this);
this.ProjectPriority = new ProjectPriorityClient(this);
this.ProjectStatus = new ProjectStatusClient(this);
this.ProjectTemplate = new ProjectTemplateClient(this);
this.ProjectVersion = new ProjectVersionClient(this);
this.Resource = new ResourceClient(this);
this.ResourceSkill = new ResourceSkillClient(this);
this.ResourceTeam = new ResourceTeamClient(this);
this.Risk = new RiskClient(this);
this.RiskFile = new RiskFileClient(this);
this.Tag = new TagClient(this);
this.Task = new TaskClient(this);
this.TaskAssignee = new TaskAssigneeClient(this);
this.TaskField = new TaskFieldClient(this);
this.TaskFile = new TaskFileClient(this);
this.TaskMetadata = new TaskMetadataClient(this);
this.TaskStatus = new TaskStatusClient(this);
this.TaskTag = new TaskTagClient(this);
this.TaskTodo = new TaskTodoClient(this);
this.Teams = new TeamsClient(this);
this.Timesheet = new TimesheetClient(this);
this.UserRole = new UserRoleClient(this);
this.WorkSpace = new WorkSpaceClient(this);
}
/**
* Construct a new API client to target the specific environment.
*
* Predefined environment names:
* * production - https://api.projectmanager.com
*
* @param env The name of the environment to use
* @returns The API client to use
*/
static withEnvironment(env) {
switch (env) {
case "production": return new ProjectManagerClient("https://api.projectmanager.com");
default: return new ProjectManagerClient(env);
}
}
/**
* Construct an unsafe client that uses a non-standard server; this can be necessary
* when using proxy servers or an API gateway. Please be careful when using this
* mode. You should prefer to use `withEnvironment()` instead wherever possible.
*
* @param unsafeUrl The custom environment URL to use for this client
* @returns The API client to use
*/
static withCustomEnvironment(unsafeUrl) {
return new ProjectManagerClient(unsafeUrl);
}
/**
* Configure this API client to use a JWT bearer token.
*
*
*
* @param token The JWT bearer token to use for this API session
*/
withBearerToken(token) {
this.bearerToken = token;
return this;
}
/**
* Configure a custom header function that will be called before all requests.
*
* This function can modify the request headers.
*
* @param func The async function to be called to modify headers before any request
* @returns The API client for function chaining
*/
withCustomHeaderFunc(func) {
this.customHeaderFunc = func;
return this;
}
/**
* Configures this API client to use an application name
*
* @param appName The Application Name to use for this API session
*/
withApplicationName(appName) {
this.appName = appName;
return this;
}
/**
* Construct headers for a request
*/
async getHeaders() {
const headers = {
SdkName: this.sdkName,
SdkVersion: this.version,
MachineName: os.hostname(),
};
if (this.appName !== null) {
headers["ApplicationName"] = this.appName;
}
if (this.bearerToken !== null) {
headers["Authorization"] = `Bearer ${this.bearerToken}`;
}
if (this.customHeaderFunc != null) {
return (await this.customHeaderFunc(headers));
}
else {
return headers;
}
}
/**
* Make a GET request using this client
*/
async request(method, path, options, body) {
const requestConfig = {
url: new url.URL(path, this.serverUrl).href,
method,
params: options,
data: body,
headers: await this.getHeaders(),
};
const result = await axios.request(requestConfig);
return result.data;
}
/**
* Upload a file to a REST endpoint and retrieve results as JSON
*/
async fileUpload(method, path, options, filename) {
const fileBuffer = await fs.promises.readFile(filename);
const formData = new FormData();
formData.append("file", fileBuffer);
const requestConfig = {
url: new url.URL(path, this.serverUrl).href,
method,
data: formData,
params: options,
headers: await this.getHeaders(),
};
const result = await axios.request(requestConfig);
return result.data;
}
/**
* Make a GET request using this client and download the results as a blob
*/
async requestBlob(method, path, options, body) {
const responseType = "blob";
const requestConfig = {
url: new url.URL(path, this.serverUrl).href,
method,
params: options,
data: body,
headers: await this.getHeaders(),
responseType,
};
const result = await axios.request(requestConfig);
return result.data;
}
}
//# sourceMappingURL=ProjectManagerClient.js.map