1.1.63 • Published 5 months ago

@devrev/typescript-sdk v1.1.63

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

Authorization

Setup an env variable DEVREV_TOKEN It will be used as an auth token by default, You can also pass in the url and token in client.setup() as a param (see below). It is also required to run tests.

Installation

npm install @devrev/typescript-sdk

The version can be found in package.json. The SDK is currently beta. Make sure that your project's package.json contains "type":"module" setting.

Example Usage of the Beta SDK

import {client, betaSDK} from "@devrev/typescript-sdk";

const devrevBetaSDK = client.setupBeta({ endpoint: "https://api.devrev.ai",
token: process.env.DEVREV_TOKEN });

async function test(){
    const response = await devrevBetaSDK.worksCreate({title:"New work item!",
    applies_to_part: "PROD-1",
    owned_by:["DEVU-1"],
    type: betaSDK.WorkType.Issue})
    console.log(response)
}

test()

Example Usage of the Public SDK

import {client, publicSDK} from "@devrev/typescript-sdk";

const devrevSDK = client.setup({ endpoint: "https://api.devrev.ai", token: process.env.DEVREV_TOKEN });

async function test(){
    const response = await devrevSDK.worksCreate({title:"New work item!", applies_to_part: "PROD-1", owned_by:["DEVU-16"], type: publicSDK.WorkType.Issue})
    console.log(response.status)
}

test()

Execute tests in the repo

npm test

Devrev SDK Utils Guide

Basic Setup

First, initialize the SDK with your DevRev credentials:

import { client } from '@devrev/typescript-sdk';
import { BetaSdkUtil } from '@devrev/sdk-utils';

// Initialize the DevRev SDK
const devrevSDK = new client.setupBeta({
  // Your DevRev credentials
  endpoint: "https://api.devrev.ai",
  token: "YOUR_TOKEN"
});

// Initialize the utils SDK
const sdkUtil = new BetaSdkUtil(devrevSDK);

Core Features

1. User Management

Fetch all Rev users associated with an account:

const accountId = "ACC-12345";
const revUsers = await sdkUtil.getAllRevUsersFromAccount(accountId);
// Returns array of RevUser objects

2. File Management

Upload Files

import { FileTypes } from '@devrev/sdk-utils';

// Prepare file object
const fileObject = {
  file_name: "example.txt",
  file_type: FileTypes.OTHERS,
  file: Buffer.from("Hello World"),
  custom_file_type: "text/plain" // Required when file_type is OTHERS
};

// Upload file
const artifactId = await sdkUtil.uploadFileToArtifact(fileObject);

Retrieve File Content

const artifactId = "ART-12345";
const fileContent = await sdkUtil.getFileContentFromArtifact(artifactId);

Error Handling

The SDK includes built-in API error handling that provides detailed error information:

try {
  await sdkUtil.uploadFileToArtifact(fileObject);
} catch (error) {
  // Error will be automatically handled with detailed logging:
  // === Error Details ===
  // Service: [function name]
  // API: [API endpoint]
  // Error Type: [error type]
  // Status Code: [status code]
  // Message: [error message]
}

TypeScript Support

The SDK is written in TypeScript and provides comprehensive type definitions for:

  • File management operations
  • User management
  • API Error handling

How to Contribute?

  1. Create a New Branch

    • Start by creating a separate branch for your feature or bug fix.
  2. Follow Best Coding Practices

    • Ensure your code adheres to the following guidelines:
      • Handle potential errors using try-catch blocks.
      • Use TypeScript types/interfaces from the SDK for type safety.
      • Check file type requirements before uploading.
      • Utilize built-in API error handling for consistent logging.
  3. Enhance BetaSDKUtil

    • Modify the BetaSDKUtil class to add new utilities.
    • Write comprehensive test cases to ensure functionality.
  4. Run Tests

    • Execute tests using:
      npm test
  5. Submit a Pull Request

    • Open a pull request with a clear and detailed description of your changes.
1.1.34

1 year ago

1.1.38

11 months ago

1.1.36

11 months ago

1.1.35

11 months ago

1.1.39

11 months ago

1.1.41

11 months ago

1.1.40

11 months ago

1.1.45

10 months ago

1.1.44

10 months ago

1.1.43

10 months ago

1.1.42

10 months ago

1.1.49

10 months ago

1.1.48

10 months ago

1.1.47

10 months ago

1.1.46

10 months ago

1.1.52

9 months ago

1.1.51

10 months ago

1.1.50

10 months ago

1.1.55

7 months ago

1.1.54

9 months ago

1.1.53

9 months ago

1.1.59

6 months ago

1.1.57

7 months ago

1.1.63

5 months ago

1.1.62

6 months ago

1.1.61

6 months ago

1.1.60

6 months ago

1.1.33

1 year ago

1.1.32

1 year ago

1.1.31

1 year ago

1.1.29

1 year ago

1.1.28

1 year ago

1.1.30

1 year ago

1.1.27

1 year ago

1.1.25

2 years ago

1.1.24

2 years ago

1.1.23

2 years ago

1.1.22

2 years ago

1.1.21

2 years ago

1.1.20

2 years ago

1.1.19

2 years ago

1.1.18

2 years ago

1.1.17

2 years ago

1.1.16

2 years ago

1.1.15

2 years ago

1.1.14

2 years ago

1.1.13

2 years ago

1.1.12

2 years ago

1.1.11

2 years ago

1.1.10

2 years ago

1.1.9

2 years ago

1.1.8

2 years ago

1.1.7

2 years ago

1.1.6

2 years ago

1.1.5

2 years ago

1.1.4

2 years ago

1.1.3

2 years ago

1.1.1

2 years ago

1.2.0

2 years ago

1.1.0

2 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago