### Install project dependencies Source: https://github.com/d-velop/dvelop-sdk-node/blob/main/CONTRIBUTING.md Install all necessary project dependencies using npm. This command should be run after cloning the repository. ```bash npm i ``` -------------------------------- ### Interface documentation example Source: https://github.com/d-velop/dvelop-sdk-node/blob/main/CONTRIBUTING.md Example of documenting an interface with JSDoc, including general information and property descriptions. ```typescript /** * This is my interface. It faces inter really well. * @category MyStuff */ export interface MyInterface { /** * Value held by my interface. **DO NOT put numbers here** */ value: string; } ``` -------------------------------- ### Install and Use @dvelop-sdk/task in TypeScript Source: https://github.com/d-velop/dvelop-sdk-node/blob/main/README.md Install the @dvelop-sdk/task package and use the createTask function to create tasks within d.velop. Requires systemBaseUri and authSessionId for authentication. ```bash npm i @dvelop-sdk/task ``` ```typescript import { createTask } from "@dvelop-sdk/task"; (async function main() { const taskLocation = await createTask({ systemBaseUri: "https://umbrella-corp.d-velop.cloud", authSessionId: "dQw4w9WgXcQ" }, { subject: "Cover up lab accident", assignees: ["XiFkyR35v2Y"] }); console.log(taskLocation); // some/task/location })(); ``` -------------------------------- ### Build and Start Application Source: https://github.com/d-velop/dvelop-sdk-node/blob/main/README.md Compiles TypeScript code to JavaScript and starts the d.velop application using Node.js. Ensure the APP_SECRET environment variable is set. ```bash npx tsc && node src/main.js ``` -------------------------------- ### Install and Use @dvelop-sdk/dms in TypeScript Source: https://github.com/d-velop/dvelop-sdk-node/blob/main/README.md Install the @dvelop-sdk/dms package and use the getRepository function to interact with d.velop DMS. Requires systemBaseUri and authSessionId for authentication. ```bash npm i @dvelop-sdk/dms ``` ```typescript import { Repository, getRepository } from "@dvelop-sdk/dms"; (async function main() { const repo: Repository = await getRepository({ systemBaseUri: "https://steamwheedle-cartel.d-velop.cloud", authSessionId: "dQw4w9WgXcQ" }, { repositoryId: "qnydFmqHuVo", }); console.log(repo.name); // Booty Bay Documents })(); ``` -------------------------------- ### Function documentation example Source: https://github.com/d-velop/dvelop-sdk-node/blob/main/CONTRIBUTING.md Example of documenting a function with JSDoc, including error handling and category. ```typescript /** * Provides a greeting string. * * @throws {@link UnknownPersonError} indicated that the person to be greeted was not found. * * ```typescript * const greeting: string = sayHi("Emma Watson"); * console.log(greeting) //print "Moin moin Emma Watson!" * ``` * * @category Social */ export function sayHi(to: string): string { ... } ``` -------------------------------- ### Install Dependencies Source: https://github.com/d-velop/dvelop-sdk-node/blob/main/README.md Installs the necessary npm packages for an Express-based d.velop application, including development dependencies for TypeScript. ```bash npm i express cookie-parser @dvelop-sdk/express-utils npm i typescript @types/express @types/cookie-parser -D ``` -------------------------------- ### Clone the d.velop SDK for Node.js repository Source: https://github.com/d-velop/dvelop-sdk-node/blob/main/CONTRIBUTING.md Clone the project repository to start contributing. Ensure you have Git installed. ```git git clone https://github.com/d-velop/dvelop-sdk-node.git ``` -------------------------------- ### Express App Setup with d.velop SDK Source: https://github.com/d-velop/dvelop-sdk-node/blob/main/README.md Sets up an Express application with d.velop SDK middleware for context, signature validation, and authentication. Includes basic routes and error handling for d.velop specific errors. ```typescript import express, { Application, NextFunction, Request, Response } from "express" import cookieParser from "cookie-parser"; import { authenticationMiddleware, contextMiddleware, validateSignatureMiddlewareFactory, InvalidRequestSignatureError, UnauthorizedError, redirectToLoginPage } from "@dvelop-sdk/express-utils"; const app: Application = express(); const appName: string = "acme-myapp"; const appPort: number = 5000; app.use(cookieParser()); app.use(contextMiddleware); // Make the req.dvelopContext-property available app.use(validateSignatureMiddlewareFactory(process.env.APP_SECRET)); // Check the d.velop signature. app.get(`/${appName}/me`, authenticationMiddleware, (req: Request, res: Response) => { res.status(200).send(`

Hello ${req.dvelopContext.user.displayName}

`); }); app.get(`/${appName}`, (req: Request, res: Response) => { res.status(200).send(`

Hello Tenant ${req.dvelopContext.systemBaseUri} (${req.dvelopContext.tenantId})

`); }); app.use((err: any, req: Request, res: Response, _: NextFunction) => { if (err instanceof InvalidRequestSignatureError) { res.status(403).send("Forbidden"); // Indicates a problem with the App-Secret } else if (err instanceof UnauthorizedError) { redirectToLoginPage(req, res); // Not authenticated => send to IDP login-page } else { console.log(err); res.status(500).send("Internal Server Error"); } }); app.listen(appPort, () => { console.log(`D.velop app listening on port ${appPort} ...`); }); ``` -------------------------------- ### Use @dvelop-sdk/dms in ES6 JavaScript Source: https://github.com/d-velop/dvelop-sdk-node/blob/main/README.md Install the @dvelop-sdk/dms package and configure your package.json to use ES6 modules. Then use the getRepository function to interact with d.velop DMS. ```bash npm i @dvelop-sdk/dms ``` ```json //package.json { "type":"module" } ``` ```javascript //main.js import { Repository, getRepository } from "@dvelop-sdk/dms"; async function main() { const repo = await getRepository({ systemBaseUri: "https://steamwheedle-cartel.d-velop.cloud", authSessionId: "dQw4w9WgXcQ" }, { repositoryId: "qnydFmqHuVo", }); console.log(repo.name); // Booty Bay Documents } await main(); ``` -------------------------------- ### Error class documentation example Source: https://github.com/d-velop/dvelop-sdk-node/blob/main/CONTRIBUTING.md Example of documenting an error class with JSDoc, including general information and category. ```typescript /** * Music is playing but its not Britney. * @category Error */ export class UppsIDidItAgainError extends Error { ... } ``` -------------------------------- ### Implement Custom Provider Factory with Initialization Source: https://github.com/d-velop/dvelop-sdk-node/blob/main/packages/logging/README.md Demonstrates creating a provider factory that accepts initialization parameters to configure the provider function. ```typescript // or have some init async function myProviderFactory(howMuchIsTheFish: number): ProviderFn { return (context: DvelopContext, event: DvelopLogEvent, level: DvelopLogLevel) => Promise { // jump through hoops } } ``` -------------------------------- ### Build the project Source: https://github.com/d-velop/dvelop-sdk-node/blob/main/CONTRIBUTING.md Compile the TypeScript code and build the project artifacts. This is a necessary step before testing or running the SDK. ```bash npm run build ``` -------------------------------- ### Run project tests Source: https://github.com/d-velop/dvelop-sdk-node/blob/main/CONTRIBUTING.md Execute the test suite to ensure the project is functioning correctly. This command is used to verify code changes. ```bash npm test ``` -------------------------------- ### Use Console and File Transports Source: https://github.com/d-velop/dvelop-sdk-node/blob/main/packages/logging/README.md Demonstrates how to use the default console and file transports. The console transport logs to the console, while the file transport logs to a specified file. ```typescript import { TransportFn, consoleTransportFactory, fileTransportFactory } from "@dvelop-sdk/logging"; const consoleTransport: TransportFn = consoleTransportFactory(); await consoleTransport("Hello World!"); // log "Hello World" to console in Node.js and Browsers const fileTransport: TransportFn = fileTransportFactory("./logs.txt"); await fileTransport("Hello World!"); // log "Hello World" to logs.txt ``` -------------------------------- ### Initialize DvelopLogger Source: https://github.com/d-velop/dvelop-sdk-node/blob/main/packages/logging/README.md Initializes the DvelopLogger with a specified log level and one or more providers. Supports OTEL provider with configurable transports like console and file. ```typescript const logger = new DvelopLogger({ level: "info",// logs info and above providers: [ // Providers define a logging scheme. Currently only OTEL is supported. otelProviderFactory({ appName: "acme-myapp", appVersion: "1.0.0", instanceId: "0", // Transports define where to logging statements are send. Multiple transports can be used. transports: [ consoleTransportFactory(), // logs to console fileTransportFactory("./logs.txt") // logs to file 'logs.txt' ] }) ], }); ``` -------------------------------- ### Run all tests Source: https://github.com/d-velop/dvelop-sdk-node/blob/main/CONTRIBUTING.md Executes all tests for the project. This command is automatically run on commit. ```npm npm run test ``` -------------------------------- ### Run automated license checking Source: https://github.com/d-velop/dvelop-sdk-node/blob/main/CONTRIBUTING.md Runs automated license checking on project dependencies. Should be executed when adding a new dependency. ```npm npm run license ``` -------------------------------- ### Configure DvelopLogger with OpenTelemetry Provider Source: https://github.com/d-velop/dvelop-sdk-node/blob/main/packages/logging/README.md Sets up the main DvelopLogger with a specified log level and an OpenTelemetry provider configured with console and file transports. ```typescript const logger = new DvelopLogger({ level: "info", providers: [ otelProviderFactory({ appName: "acme-myapp", appVersion: "1.0.0", instanceId: "0", transports: [ consoleTransportFactory(), fileTransportFactory("./logs.txt") ] }) ], }); ``` -------------------------------- ### Generate typedoc documentation locally Source: https://github.com/d-velop/dvelop-sdk-node/blob/main/CONTRIBUTING.md Generates typedoc documentation locally in the /docs directory. This directory is ignored by git. ```npm npm run docs ``` -------------------------------- ### Implement Custom Provider Function Source: https://github.com/d-velop/dvelop-sdk-node/blob/main/packages/logging/README.md Shows how to implement a custom provider function that can perform specific logging logic. ```typescript // do a fixed provider async function myProvider(context: DvelopContext, event: DvelopLogEvent, level: DvelopLogLevel): Promise { // jump through hoops } ``` -------------------------------- ### Implement Custom Provider Factory with Transports Source: https://github.com/d-velop/dvelop-sdk-node/blob/main/packages/logging/README.md Illustrates a provider factory that accepts transport functions to format and send log events. ```typescript // or even support generic TransportFunctions async function myProviderFactory(transports: TransportFn[]): ProviderFn { return (context: DvelopContext, event: DvelopLogEvent, level: DvelopLogLevel) => Promise { const formattedEvent: any = {} // jump through hoops transports.forEach(t => t(formattedEvent)); } } ``` -------------------------------- ### getRepository Function Signature Source: https://github.com/d-velop/dvelop-sdk-node/blob/main/README.md Illustrates the signature of the getRepository function, which takes a context and parameters and returns a Promise of a Repository object. ```typescript (context: DvelopContext, params: GetRepositoryParams) => Promise ``` -------------------------------- ### Continuously run tests on save Source: https://github.com/d-velop/dvelop-sdk-node/blob/main/CONTRIBUTING.md Continuously runs tests on save for files that have changed. Recommended for development. ```npm npm run test:watch ``` -------------------------------- ### Configure Default OpenTelemetry Provider Source: https://github.com/d-velop/dvelop-sdk-node/blob/main/packages/logging/README.md Initializes the default OpenTelemetry provider with application details and specific transport functions. ```typescript import { ProviderFn, otelProviderFactory } from "@dvelop-sdk/logging"; const otel: ProviderFn = otelProviderFactory({ appName: "acme-myapp", appVersion: "1.0.0", instanceId: "0", transports: [ consoleTransport, fileTransport, myTransport ] }); ``` -------------------------------- ### Lint code against specifications Source: https://github.com/d-velop/dvelop-sdk-node/blob/main/CONTRIBUTING.md Compares written code against eslint specifications. This command is automatically run on commit. ```npm npm run lint ``` -------------------------------- ### Custom Repository Name Extraction Source: https://github.com/d-velop/dvelop-sdk-node/blob/main/README.md Demonstrates how to use the getRepositoryFactory with a custom transform function to extract and format the repository name from the response. ```typescript const myGetRepositoryFunction = getRepositoryFactory( // inject the default httpRequestFunction defaultHttpRequestFunction, // inject a custom transform-function (response: HttpResponse, context: DvelopContext, params: GetRepositoryParams) => { return `The name of a repository in '${context.systemBaseUri}' is '${response.data.name}.'`; } ); const info: string = myGetRepositoryFunction({ systemBaseUri: "https://steamwheedle-cartel.d-velop.cloud", authSessionId: "dQw4w9WgXcQ" }, { repositoryId: "qnydFmqHuVo" }); console.log(info); // The name of a repository in 'https://steamwheedle-cartel.d-velop.cloud' is 'Booty Bay Documents'. ``` -------------------------------- ### Force rebuild of all javascript files Source: https://github.com/d-velop/dvelop-sdk-node/blob/main/CONTRIBUTING.md Rebuilds all javascript files for the project. This command should generally not be needed. ```npm npm run build:force ``` -------------------------------- ### TypeScript Configuration Source: https://github.com/d-velop/dvelop-sdk-node/blob/main/README.md Ensures the 'esModuleInterop' flag is set to true in your tsconfig.json for proper module interoperability. ```json //tsconfig.json { "compilerOptions": { "esModuleInterop": true, // ... } } ``` -------------------------------- ### getRepository Factory Function Source: https://github.com/d-velop/dvelop-sdk-node/blob/main/README.md Defines a factory function for creating getRepository methods. It accepts HTTP and transform functions to allow customization of the request and response handling. ```typescript export function getRepositoryFactory( httpRequestFunction: (context: DvelopContext, config: HttpConfig) => Promise, transformFunction: (response: HttpResponse, context: DvelopContext, params: GetRepositoryParams) => T, ): (context: DvelopContext, params: GetRepositoryParams) => Promise { return async (context: DvelopContext, params: GetRepositoryParams) => { const response: HttpResponse = await httpRequestFunction(context, { method: "GET", url: "/dms", follows: ["repo"], templates: { "repositoryid": params.repositoryId } }); return transformFunction(response, context, params); }; } export async function getRepository(context: DvelopContext, params: GetRepositoryParams): Promise { return getRepositoryFactory(defaultHttpRequestFunction, getRepositoryDefaultTransformFunction)(context, params); } ``` -------------------------------- ### Log a Debug Message Source: https://github.com/d-velop/dvelop-sdk-node/blob/main/packages/logging/README.md Logs a simple debug message with a context object and a string message. The OTEL-Provider transforms this into a structured log entry. ```typescript logger.debug({}, "Hello World!"); /** * { * "time":"2022-07-07T11:06:34.105Z", * "sev":9, * "body":"Hello World!", * "res":{ * "svc":{ * "name":"acme-myapp", * "ver":"1.0.0" * "inst": "0" * } * }, * "vis":1 * } */ ``` -------------------------------- ### Log an Error with Context Source: https://github.com/d-velop/dvelop-sdk-node/blob/main/packages/logging/README.md Logs an error message, including a DvelopContext object, a DvelopLogEvent object with error details, and custom attributes. This is useful for capturing exceptions. ```typescript try { convinceLeonidasThatThisIsMadness(); } catch (error: any) { logger.error({ systemBaseUri: "https://sparta.d-velop.cloud", tenantId: "T8r3cWM4JII" }, { name: "MissionFailedLogger", message: "Apparently this is Sparta", error: error, customAttributes: { learnings: "Don't stand near a well" } }); } /** * { * "time":"479BCT11:11:11.111Z", * "sev":17, * "name":"MissionFailedLogger", * "body":"Apparently this is Sparta", * "tn":"T8r3cWM4JII", * "res":{ * "svc":{ * "name":"acme-myapp", * "ver":"1.0.0", * "inst": "0" * } * }, * "attr":{ * "learnings":"Don't stand near a well", * "exception":{ * "message":"THIS IS SPARTA", * "type":"RoundHouseKickError", * "stacktrace":"..." * } * }, * "vis":1 * } */ ``` -------------------------------- ### Define a Custom Transport Function Source: https://github.com/d-velop/dvelop-sdk-node/blob/main/packages/logging/README.md Shows how to define a custom transport function. This function can implement any logic for handling log events. ```typescript async function myTransport(event: any): Promise { // jump through hoops } ``` -------------------------------- ### Fix linting errors automatically Source: https://github.com/d-velop/dvelop-sdk-node/blob/main/CONTRIBUTING.md Attempts to automatically fix linting errors. Should be the first action when encountering linting errors. ```npm npm run lint:fix ``` -------------------------------- ### HTTP Request Function Signature Source: https://github.com/d-velop/dvelop-sdk-node/blob/main/README.md Defines the signature for an HTTP request function used within the SDK. It takes context and configuration, returning a Promise of an HTTP response. ```typescript (context: DvelopContext, config: HttpConfig) => Promise ``` -------------------------------- ### Define Provider Function Type Source: https://github.com/d-velop/dvelop-sdk-node/blob/main/packages/logging/README.md Defines the type for a provider function, which takes context, event, and level to perform logging transformations. ```typescript export type ProviderFn = (context: DvelopContext, event: DvelopLogEvent, level: DvelopLogLevel) => Promise; ``` -------------------------------- ### Transform Function Signature Source: https://github.com/d-velop/dvelop-sdk-node/blob/main/README.md Defines the signature for a transform function. It processes an HTTP response, context, and parameters to return a generic type T. ```typescript (response: HttpResponse, context: DvelopContext, params: GetRepositoryParams) => T ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.