Giter Site home page Giter Site logo

merge-node-client's Introduction

Merge Node Library

npm shield

The Merge Node.js library provides access to the Merge API from JavaScript/TypeScript.

Documentation

API reference documentation is available here.

Installation

npm install --save @mergeapi/merge-node-client
# or
yarn add @mergeapi/merge-node-client

Instantiation

import { MergeClient } from '@mergeapi/merge-node-client';

const merge = new MergeClient({
  apiKey: 'YOUR_API_KEY',
  accountToken: 'YOUR_ACCOUNT_TOKEN',
});

Categories

This SDK contains the ATS, HRIS, CRM, Ticketing, Accounting, and File Storage categories. Even if you do not plan on using more than one Merge API category right now, the SDK provides upgrade-flexibility in case you find new Merge API categories useful in the future.

Each category is namespaced:

const merge = new MergeClient({
  apiKey: 'YOUR_API_KEY',
  accountToken: 'YOUR_ACCOUNT_TOKEN',
});

merge.ats. // APIs specific to the ATS Category

merge.hris. // APIs specific to the HRIS Category

Usage

Below are code snippets of how you can use the Node SDK.

Create Link Token

import { MergeClient, Merge } from '@mergeapi/merge-node-client';

const merge = new MergeClient({
  apiKey: 'YOUR_API_KEY',
  // `accountToken` may be omitted if necessary (e.g., during the initial Link session)
  accountToken: 'YOUR_ACCOUNT_TOKEN', 
});

const linkTokenResponse = await merge.ats.linkToken.create({
    endUserEmailAddress: "[email protected]",
    endUserOrganizationName: "acme",
    endUserOriginId: "1234",
    categories: [Merge.ats.CategoriesEnum.Ats],
    linkExpiryMins: 30,
});

console.log("Created link token", linkTokenResponse.linkToken)

Retrieve Account Token Using Public Token

import { MergeClient, Merge } from '@mergeapi/merge-node-client';

const merge = new MergeClient({
  apiKey: 'YOUR_API_KEY'
});

const accountTokenResponse = await merge.ats.accountToken.retrieve(publicToken)

console.log("Retrieved account token", accountTokenResponse.accountToken)

Get Employee

import { MergeClient, Merge } from '@mergeapi/merge-node-client';

const merge = new MergeClient({
  apiKey: 'YOUR_API_KEY',
  accountToken: 'YOUR_ACCOUNT_TOKEN',
});


employee = await merge.hris.employees.retrieve("0958cbc6-6040-430a-848e-aafacbadf4ae")

Get Candidate

import { MergeClient, Merge } from '@mergeapi/merge-node-client';

const merge = new MergeClient({
  apiKey: 'YOUR_API_KEY',
  accountToken: 'YOUR_ACCOUNT_TOKEN',
});


candidate = await merge.ats.candidates.retrieve(
  "521b18c2-4d01-4297-b451-19858d07c133"
)

Filter Candidate

import { MergeClient, Merge } from '@mergeapi/merge-node-client';

const merge = new MergeClient({
  apiKey: 'YOUR_API_KEY',
  accountToken: 'YOUR_ACCOUNT_TOKEN',
});

const candidatesResponse = await merge.ats.candidates.list({
  created_after: "2030-01-01"
})

console.log(candidatesResponse.results)

Get Contact

import { MergeClient, Merge } from '@mergeapi/merge-node-client';

const merge = new MergeClient({
  apiKey: 'YOUR_API_KEY',
  accountToken: 'YOUR_ACCOUNT_TOKEN',
});

contact = await merge.accounting.contacts.retrieve(
  "c640b80b-fac9-409f-aa19-1f9221aec445"
)

Create Ticket

import { MergeClient, Merge, TicketStatusEnum } from '@mergeapi/merge-node-client';

const merge = new MergeClient({
  apiKey: 'YOUR_API_KEY',
  accountToken: 'YOUR_ACCOUNT_TOKEN',
});

await merge.ticketing.tickets.create({
  model: {
    name: "Please add more integrations",
    assignees: ["17a54124-287f-494d-965e-3c5b330c9a68"],
    creator: "3fa85f64-5717-4562-b3fc-2c963f66afa6",
    due_date: "2022-10-11T00:00:00Z",
    status: TicketStatusEnum.Open,
  },
})

File Download

import { MergeClient, Merge } from '@mergeapi/merge-node-client';
import * as fs from 'fs/promises';

const merge = new MergeClient({
  apiKey: 'YOUR_API_KEY',
  accountToken: 'YOUR_ACCOUNT_TOKEN',
});

const listResponse = await merge.filestorage.files.list({
  name: "<FILE_NAME>"
})

const file = response.results[0]
const localFilepath = `<LOCAL_FILE_PATH>/${file.name}`

const response = await merge.filestorage.files.downloadRetrieve(file.id)
const fileStream = fs.createWriteStream(localFilepath);
await stream.pipeline(response, fileStream);

Pagination

The SDK may return paginated results. Endpoints that return paginated results will include a next and prev property on the response. To get the next page, you can pass in the value of next to the cursor property on the request. Similarly, to get the previous page, you can pass in the value of prev to the cursor property on the request.

Below is an example of iterating over all pages:

// response contains the first page
let response = merge.hris.employees.list({
  createdAfter: "2030-01-01",
})

// if there is a next page, load it by passing `next` to the cursor argument
while (response.next != null) {
    response = merge.hris.employees.list({
        cursor: response.next, 
        created_after: "2030-01-01",
    })
}

Contributing

While we value open-source contributions to this SDK, this library is generated programmatically. Additions made directly to this library would have to be moved over to our generation code, otherwise they would be overwritten upon the next generated release. Feel free to open a PR as a proof of concept, but know that we will not be able to merge it as-is. We suggest opening an issue first to discuss with us!

On the other hand, contributions to the README are always very welcome!

merge-node-client's People

Contributors

aapzu avatar dsinghvi avatar fern-api[bot] avatar hmafzal avatar leewang0 avatar rmkonnur avatar tbusillo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

merge-node-client's Issues

punycode deprecation warning in NodeJS v21

@mergeapi/merge-node-client depends on an outdated version of node-fetch (2.7.0, latest is 3.3.2), which depends on an outdated version of whatwg-url (5.0.0, latest is 14), which depends on punycode, which is deprecated in Node 21 and will be removed in a future version.

This triggers the following deprecation warning at every start:

(node:50865) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.

FYI fetch() is also natively available as a global (and stable) in NodeJS v21, which uses the undici implementation under the hood, which is also available on NPM: https://www.npmjs.com/package/undici
It has zero dependencies.

Depends on vulnerable axios dependency

# npm audit report

axios  0.8.1 - 1.5.1
Severity: moderate
Axios Cross-Site Request Forgery Vulnerability - https://github.com/advisories/GHSA-wf5p-g6vw-rhxx
No fix available
node_modules/@mergeapi/merge-node-client/node_modules/axios
  @mergeapi/merge-node-client  *
  Depends on vulnerable versions of axios
  node_modules/@mergeapi/merge-node-client

2 moderate severity vulnerabilities

README examples are incorrect

The documentation in the README has many examples with incorrect inputs and invalid object syntax.

For example:

const candidatesResponse = await merge.ats.candidates.list({
    created_after="2030-01-01"
})

should be

const candidatesResponse = await merge.ats.candidates.list({
    createdAfter: "2030-01-01"
})

ParseError in merge.ticketing.tickets.remoteFieldClassesList

The method fails due to a ParseError for a Jira account with this stack trace:

ParseError: response -> results -> [3] -> item_schema -> item_choices -> [0]: Expected string. Received object.; response -> results -> [6] -> item_schema -> item_choices -> [0]: Expected string. Received object.; response -> results -> [8] -> item_schema -> item_choices -> [0]: Expected string. Received object.; response -> results -> [10] -> item_schema -> item_choices -> [0]: Expected string. Received object.; response -> results -> [12] -> item_schema -> item_choices -> [0]: Expected string. Received object.; response -> results -> [13] -> item_schema -> item_choices -> [0]: Expected string. Received object.; response -> results -> [16] -> item_schema -> item_choices -> [0]: Expected string. Received object.; response -> results -> [17] -> item_schema -> item_choices -> [0]: Expected string. Received object.
    at node_modules/@mergeapi/merge-node-client/core/schemas/builders/schema-utils/getSchemaUtils.js:25:19
    at Generator.next (<anonymous>)
    at fulfilled (node_modules/@mergeapi/merge-node-client/core/schemas/builders/schema-utils/getSchemaUtils.js:5:58)
    at processTicksAndRejections (node:internal/process/task_queues:95:5) {
  errors: [
    { path: [Array], message: 'Expected string. Received object.' },
    { path: [Array], message: 'Expected string. Received object.' },
    { path: [Array], message: 'Expected string. Received object.' },
    { path: [Array], message: 'Expected string. Received object.' },
    { path: [Array], message: 'Expected string. Received object.' },
    { path: [Array], message: 'Expected string. Received object.' },
    { path: [Array], message: 'Expected string. Received object.' },
    { path: [Array], message: 'Expected string. Received object.' }
  ]
}

Standardisation of `fieldMappings`

For the new SDK, the field names have been converted from snake case to camel case. However, I've noticed this translation has not extended to the contents of fieldMappings which is now appearing as so in the get employee response from the SDK:

 fieldMappings: {
      organization_defined_targets: {},
      linked_account_defined_targets: {}
    }

I understand that the internals of organization_defined_targets need to be freeform, but wondering if the type could be changed from

fieldMappings?: Record<string, unknown>;

to

 fieldMappings?: {
        organizationDefinedTargets: Record<string, {value: unknown}>;
        linkedAccountDefinedTargets: Record<string, {value: unknown}>;
    }

Just preference to avoid a mismatch of casing and to introduce some stricter typing.

CRM opportunity.partialUpdate documentation is incorrect

The documentation and types for PatchedOpportunityRequest are all marked as optional. However, the endpoint returns an error if all fields are not passed in when making a request to Salesforce.

{
  "warnings": [],
  "errors": [
    {
      "source": null,
      "title": "Error",
      "detail": "We've encountered an error while sending this request to the Salesforce API. Please contact [email protected] if this problem persists.",
      "problem_type": "ERROR"
    }
  ]
}

Tested that the opportuntity patch endpoint works as expected in a curl request if all model fields are passed in

More comprehensive types for postMetaRetrieve methods

Hi Merge team, i'm working with the NodeJS API to prototype some functionality which would allow our platform to make ATS /applications POST requests based on the assembled metadata fetched from your API. There's a few tricky steps here as I have to find out whether I can POST at all depending on the capability of the linked account (or fallback on a link instead of a form from the user CTA), and then work out what fields are required from the user to assemble any prerequisite associated records such as candidates and attachments.

Currently the MetaResponse type is just Record<string, unknown> which makes wrangling the sub-structures quite a painful exercise. At least typing out the model property would be a start, although having a variable type for the possible structures under model.properties would be much more useful.

Many thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.