# dealcloud-js

> a project to connect to Dealcloud

Latest version **1.0.4** (published 2020-04-16) · MIT license · 0 weekly downloads

## Install

```sh
npm install dealcloud-js
pnpm add dealcloud-js
yarn add dealcloud-js
bun add dealcloud-js
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.4 |
| Published | 2020-04-16 |
| First published | 2020-02-25 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=8.9 |
| Dependencies | 3 |
| Unpacked size | 98.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Maintainers | perrautc |

## Links

- npm: https://www.npmjs.com/package/dealcloud-js
- Repository: https://github.com/perrautc/dealcloud-js
- Homepage: https://github.com/perrautc/dealcloud-js#readme
- Issues: https://github.com/perrautc/dealcloud-js/issues
- npm.io page: https://npm.io/package/dealcloud-js

## Dependencies (3)

- [he](https://npm.io/package/he.md) ^1.2.0
- [lodash](https://npm.io/package/lodash.md) ^4.17.15
- [strong-soap](https://npm.io/package/strong-soap.md) ^1.21.0

## Recent versions

- 1.0.4 (latest) — 2020-04-16
- 1.0.3 — 2020-03-11
- 1.0.2 — 2020-02-27
- 1.0.1 — 2020-02-25
- 1.0.0 — 2020-02-25

## README

#DealCloud

### Other Resources
[Dealcloud-Python](https://github.com/holtjp/dealcloud-python)

## install
```
    npm install dealcloud-js
```

# Examples
### Create Client
```javascript
    const dealcloud = require('dealcloud-js');
    const params = {
        username: 'username@firm.com',
        password: 'password'
        url: 'https://schema.dealcloud.{com|eu}'
    };

    const client = await dealcloud.createClient(params,{});
```
## No Parameters
These methods do not require or accept any params.
### Get Currencies
```javascript
    const dealcloud = require('dealcloud-js');
    const params = {
        username: 'username@firm.com',
        password: 'password'
        url: 'https://schema.dealcloud.{com|eu}'
    };

    const client = await dealcloud.createClient(params,{});
    const currencies = await dealcloud.getCurrencies(client);

```

### Get Lists
```javascript
    const dealcloud = require('dealcloud-js');
    const params = {
        username: 'username@firm.com',
        password: 'password'
        url: 'https://schema.dealcloud.{com|eu}'
    };

    const client = await dealcloud.createClient(params, {})
    const result = await dealcloud.getLists(client);
```

### Get Fields
```javascript
    const dealcloud = require('dealcloud-js');
    const params = {
        username: 'username@firm.com',
        password: 'password'
        url: 'https://schema.dealcloud.{com|eu}'
    };

    const client = await dealcloud.createClientAsync(params, {})
    const result = await dealcloud.getFields(client);
```

## Parameters
These methods require params.

### Modified Entries
```javascript
    const dealcloud = require('dealcloud-js');
    const params = {
        username: 'username@firm.com',
        password: 'password'
        url: 'https://schema.dealcloud.{com|eu}'
    };

    const fromDate = "2018-10-26T21:32:52"; //can be any valid date format
    const client = await dealcloud.createClient(params, {});
    const result = await dealcloud.getModifiedEntries({client, entryListId, fromDate});
```

### Filtered Entries
```javascript
    function Value(arg, argType="string") {

        return {
            $attributes: {
                "$xsiType": `{http://www.w3.org/2001/XMLSchema}xsd:${argType}`,
            },
            $value: arg
        }
    }

    const filterInfo = [{
        FieldId: 58743,
        FilterOperation: "StartsWith",
        Value: Value("G")
    }]
    const entryListId = 67337; //Id parameter returned by getLists
    const srcFilters = {FilterInfo: filterInfo};
    const client = await dealcloud.createClientAsync(params)
    const result = await dealcloud.getFilteredEntries({client, entryListId, srcFilters});
```
## Chains
These methods require a parameter returned by one or more of the No Params methods

### Get Entries
```javascript
    const dealcloud = require('dealcloud-js');
    const params = {
        username: 'username@firm.com',
        password: 'password'
        url: 'https://schema.dealcloud.{com|eu}'
    };

    const entryListId = 67337; //Id parameter returned by getLists
    const client = await dealcloud.createClientAsync(params, {})
    const result = await dealcloud.getListEntries({client, entryListId});
```

### Get Records
```javascript
    const client = await dealcloud.createClientAsync(params, {})

    // Getting Lists
    const entryLists = await dealcloud.getLists(client);

    // Getting Fields
    const allfields = await dealcloud.getFields(client);

    // Random entry list
    const entryList = entryLists[Math.floor(Math.random() * entryLists.length)];

    const entries = await dealcloud.getListEntries({client, entryListId: entryList.Id});
    const entryFields = _.filter(allfields, {'EntryListId': entryList.Id})

    // If pulling against an empty entry list could get an error, 
    // this is needed only because i'm pulling from random entry lists
    if (entries == null){
        return [];
    }

    /**
     * If filtering, run this loop twice, first only for fields that you would like to filter on but for all entries
     * Filter DCPull results however you'd like
     * Run this loop again for all fields, but only for the filtered entries
     */
    entries.NamedEntry.forEach(entry => {
        //With Schema replace this with a for in or for of loop and loop through properties of schema
        entryFields.forEach(field => {
            //Get All Fields
            DCPulls.push(new DCPull(fieldId = field.Id, entryId = entry.Id))
        })
    });

    // Without Batching
    // const result = await processDCPullAsync(client, DCPulls)

    // Batching DCPulls into batching of 10k pulls, can specify alternate batch sizes
    const result = await batchDCPulls(client, DCPulls);
    return result;
```
The actual batching function
```javascript
async function batchDCPulls(client, DCPulls, batchSize = 10000) {
    const manyBatchedDCPulls = _
        .chain(DCPulls)
        .chunk(batchSize)
        .map(f => processDCPullAsync(client, f))
        .value();
        
    const manyResults = await Promise.all(manyBatchedDCPulls);
    const result = _.flatten(manyResults)
    return result;
}
```
the dcpull function
```javascript
async function processDCPullAsync(client, DCPulls) {
    const result = await dealcloud.processDCPullAsync({client, DCPulls});
    return result;
};
```
### Create Records

---
_Source: https://npm.io/package/dealcloud-js · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
