@procore/js-sdk
A wrapper for the procore API
Last updated 19 days ago by dev-account-admin .
ISC · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @procore/js-sdk 
SYNC missed versions from official npm registry.

Procore JS SDK

CircleCI

A node.js and browser compatible JS SDK for the procore API.

Installation

yarn add @procore/js-sdk

We recommend installing the package with yarn

Example

Authorization Code Flow

Setting up a server

import 'isomorphic-fetch';
import { client, oauth, refresher, me, projects, images } from '@procore/js-sdk';

const token = document.head.querySelector('value=auth_token').getAttribute('content');

const authorizer = oauth(token);

const refreshToken = token => fetch(
  '/oauth/procore/refresh',
  { method: 'POST', headers: { 'Authorization': `Bearer ${token}` } }
);

const procore = client(
  refresher(authorizer, refreshToken)
);

Promise.all([
  procore.get(me()),
  procore.get(projects({ company_id: 2 })),
  procore.get(images({ action: 'most_recent' }))
])
.then(onSuccess);

Implicit Grant Flow

When creating an app, register the redirect URI as your app's root URL. E.g. https://example.com

import 'isomorphic-fetch';
import qs from 'qs';
import { client, oauth, implicit, me, projects, images } from '@procore/js-sdk';

const clientId = document.head.querySelector('value=client_id').getAttribute('content');
const redirectUri = document.head.querySelector('value=redirect_uri').getAttribute('content');

const accessToken = qs.parse(window.location).access_token;

if ( !accessToken ) {
  window.location = implicit({ id: clientId, uri: redirectUri });
}

const procore = client(oauth(accessToken));
Promise.all([
    procore.get(me()),
    procore.get(projects({ company_id: 2 })),
    procore.get(images({ action: 'most_recent' }))
  ])
})
  .then(onSuccess);

Responses

A single API response contains the response body (JSON parsed), original request, and complete response. isomorphic-fetch is the underlying http library, so both the request and response follow its specification. See docs for more details.

  procore
    .get(projects({ company_id: 1 }))
    .then({ body, response, request } => {
      console.log(body[0].name); // ACME Construction LLC.
      console.log(response.headers.get('Total')) // 865 (Total records for the resource)
    });

Formatting the response

By default, the SDK tries to format the response as JSON, you can control the response formatting passing the formatter option as follow:

// Create your own formatter
function formatter(response: Response): Promise<unknown> {
  return response.text()
}

// Pass the formatter configuration
procore.get(myendpoint(), { formatter })

Tests

yarn test

Endpoint Generator

js-sdk-endpoints generates interfaces and endpoint functions for improved developer experience. See the project for more details.

interface DirectCosts {
  action: string;
  qs?: any;
  id?: number;
  project_id: number;

}

function directCosts({ action, qs, id, project_id }: DirectCosts): any {
  return {
    base: '/vapid/projects/{project_id}/direct_costs',
    action,
    params: { id, project_id },
    qs
  }
}

export default directCosts

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/procore/js-sdk. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

  1. Create PR with version change npm version minor
  2. Merge PR
  3. Circle ci will release a new version of the package

License

The package is available as open source under the terms of the MIT License.

About Procore

Procore Logo

Manage Version is maintained by Procore Technologies.

Procore - building the software that builds the world.

Learn more about the #1 most widely used construction management software at procore.com

Current Tags

  • 2.4.1                                ...           latest (19 days ago)

24 Versions

  • 2.4.1                                ...           19 days ago
  • 2.4.0                                ...           2 months ago
  • 2.3.1                                ...           8 months ago
  • 2.3.0                                ...           a year ago
  • 2.2.2                                ...           2 years ago
  • 2.2.1                                ...           2 years ago
  • 2.2.0 [deprecated]           ...           2 years ago
  • 2.1.0                                ...           2 years ago
  • 2.0.2                                ...           3 years ago
  • 2.0.1                                ...           3 years ago
  • 2.0.0                                ...           3 years ago
  • 1.4.0                                ...           3 years ago
  • 1.3.0                                ...           3 years ago
  • 1.2.0                                ...           3 years ago
  • 1.1.0                                ...           3 years ago
  • 1.0.1                                ...           3 years ago
  • 0.12.0                                ...           3 years ago
  • 0.11.0                                ...           3 years ago
  • 0.10.0                                ...           4 years ago
  • 0.9.0                                ...           4 years ago
  • 0.8.1                                ...           4 years ago
  • 0.7.3                                ...           4 years ago
  • 0.7.2                                ...           4 years ago
  • 0.7.1                                ...           4 years ago

Copyright 2014 - 2016 © taobao.org |