### Installing op-client package Source: https://github.com/alexey2baranov/node-op-client/blob/master/README.md This command installs the op-client package from npm, allowing you to use it in your Node.js or browser project. ```bash npm add op-client ``` -------------------------------- ### Development setup commands Source: https://github.com/alexey2baranov/node-op-client/blob/master/README.md These commands are used to set up the development environment for the op-client library. They include cloning the repository, navigating to the project directory, and running unit tests. ```bash # clone repo git clone https://github.com/alexey2baranov/node-op-client cd node-op-client # run unit tests npm test # to run integrated test run OpenProject, setup OAuth2.0 connection and fill /.env file npm run server:up touch .env npm run test:integration npm run server:down ``` -------------------------------- ### Environment file example Source: https://github.com/alexey2baranov/node-op-client/blob/master/README.md This is an example of the .env file required for running the integration tests. It contains the base URL of the OpenProject server, the client ID, and the client secret for OAuth 2.0 authentication. ```env BASE_URL=http://localhost:8093 CLIENT_ID=... CLIENT_SECRET=... ``` -------------------------------- ### Basic OpenProject operations with op-client Source: https://github.com/alexey2baranov/node-op-client/blob/master/README.md This code demonstrates how to use the op-client library to interact with an OpenProject server. It covers creating an EntityManager instance, retrieving and modifying work packages, creating new work packages, retrieving work package collections, and fetching other entities like Types, Projects, Statuses, Custom Options and Users. ```typescript import {CO, Duration, EntityManager, Project, Status, StatusEnum, Type, WP, TypeEnum, User} from "../src"; import {config} from "dotenv"; // reading ENVIRONMENT from .env file config(); (async () => { // create EntityManager instance const em = new EntityManager({ baseUrl: process.env.BASE_URL, oauthOptions: { clientId: process.env.CLIENT_ID, clientSecret: process.env.CLIENT_SECRET, }, createLogger: () => console }); // get Work Package by id const wp = await em.get(WP, 12) // modify Work package wp.type = new Type(TypeEnum.Epic) wp.subject = 'Quick start Demo' wp.estimatedTime = new Duration({days: 24, hours: 15}) wp.startDate = new Date() await em.patch(wp, false); // or patch some fields only eg em.patch(wp, false, ['startDate','_links.type']); // create new Work Package const wp2 = new WP() wp2.type = new Type(TypeEnum.Task) wp2.project= new Project(1) wp2.subject = 'Read all examples' wp.assignee= new User(1) await em.create(wp2) console.log(wp2.createdAt) // -> current date // get Work package collection by filters const wpCollection = await em.getMany(WP, { offset: 2, pageSize: 5, filters: [{ project: { operator: "!", values: 2 }, }] }) console.log(wpCollection[2].subject) // -> Upload presentations to website // get Type by id const type = await em.get(Type, TypeEnum.Milestone); console.log(type.self.title) // ->Milestone // get Project by id const project = await em.get(Project, 1); console.log(project.self.title) // ->Demo project // get Status by id const status = await em.get(Status, StatusEnum.InProgress); console.log(status.self.title) // ->In Progress // get Custom Option by id try { const co = await em.get(CO, 1); console.log(co.self.title) // ->In progress } // this will throw error if you haven't at least one CustomOptions catch(err){ console.log(err.message) // ->404 [urn:openproject-org:api:v3:errors:NotFound] The requested resource could not be found. } // get User by id const user = await em.get(User, 1); console.log(user.self.title) // ->System })() ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.