4.0.3 • Published 7 months ago

trimble-connect-sdk v4.0.3

Weekly downloads
282
License
SEE LICENSE IN ht...
Repository
-
Last release
7 months ago

Trimble Connect SDK for JavaScript

The official Trimble Connect SDK for JavaScript, available for browsers and mobile devices.

The Trimble Connect SDK for JavaScript provides a JavaScript API for Trimble Connect services (including TCPS, PSet, Organizer Services) you can use to build browser-based web, mobile and hybrid apps. The JavaScript API lets developers build libraries or applications that make use of Trimble Connect services.

Get started with usage

Go ahead and add the component as a dependency to your project: npm install trimble-connect-sdk --save

For ES6-module-friendly consumers, you can import the modules directly, or import them from the root module:

Typical usage example in web app:

import * as TC from "trimble-connect-sdk";

const tidParams = {
    clientId: "id_received_on_app_registration_in_tppas",
    clientSecret: "secret_key_received_on_app_registration_in_tppas",
    appName: 'name_of_the_app_registered_in_tppas',
    redirectUri: 'uri_where_tid4_login_flow_will_redirect',
    serviceUri: "https://id.trimble.com/",
};
const tidCreds = new TC.TIDCredentials(tidParams);

// initialize the TPaaS TID credentials with initial tokens received from e.g. auth code grant OAuth2 flow
tidCreds.tokens = {
    access_token: "string",
    expires_in: 3600,
    id_token: "string",
    refresh_token: "string",
    scope: "string",
    token_type: "string",
};

// initialize the service credentials with the TID as a root credentials
const serviceCredentials = new TC.ServiceCredentials(tidCreds);

// configure services clients
// Note: TCPSClient.listServers() should be used to fetch region specific URIs.
// It is possible to get URI with region using TCPS.regionToServiceUri.
const orgServiceUri = await TCPS.regionToServiceUri('eu-west-1', 'orgApi');
const orgClientEU = new TC.Organizer({
    credentials: serviceCredentials,
    serviceUri: orgServiceUri,
});
TC.TCPSClient.config.credentials = serviceCredentials;

// if you need to use different service environments you can specify serviceUri explicitli:
orgClientEU.config.serviceUri = "https://org-api.trimble.com/v1/";
TC.TCPSClient.config.serviceUri = "https://app.connect.trimble.com/tc/api/2.0/";


// after this you can use OrganizerClient and TCPSClient normally all token acqusition and refresh will be handled automatically
const forestId = ...;
const treeV0 = await orgClientEU.createTree(forestId, { name: "name", type: "LBS" });
const treeV1 = await orgClientEU.updateTree(forestId, treeV0.id, { name: "name2" });
const treeV2 = await orgClientEU.deleteTree(forestId, treeV0.id);
const tree = await orgClientEU.getTree(forestId, treeV0.id, { deleted: true });

const servers = await TC.TCPSClient.listServers();
const projects = await TC.TCPSClient.listProjects(servers[0]);

For unit testing TPaaS TID tokens can be acquied using the password flow and providing username/passowrd to the credentials provider like below. Please note that for the user facing apps the OAuth2 authorization grant flow should be used as a more secure authientication flow.

import * as TC from "trimble-connect-sdk";
const tpaasParams = {
    clientId: "id_received_on_app_registration_in_tppas",
    clientSecret: "secret_key_received_on_app_registration_in_tppas",
    appName: 'name_of_the_app_registered_in_tppas',
    redirectUri: 'uri_where_tid4_login_flow_will_redirect',
    serviceUri: "https://id.trimble.com/",
};
const tpaasCredsForUnitTesting = new TC.TIDCredentials(tpaasParams, {
    username: "user@trimble.com",
    password: "pass",
});
orgClientEU.config.credentials = new TC.ServiceCredentials(tpaasCredsForUnitTesting);

If you received tokens elsewhere you could initialize services with those tokens directly. Note in this case the token refresh will not work automatically when token is expired.

import * as TC from "trimble-connect-sdk";

orgClientEU.config.credentials = {token: "token_received_from_elsewhere"};
TC.TCPSClient.config.credentials = {token: "token_received_from_elsewhere"};

In Node.js, the TypeScript-generated CommonJS package cannot be imported as nested modules, but the modules still can be imported directly from the top-level module:

const { Organizer, ErrorCodes, ServiceError } = require('trimble-connect-sdk');

The build includes both ES6 modules and CommonJS modules, so you may reference them directly from their installation in the node_modules directory. (This may be helpful for using the library in different contexts, with the ES modules being supplied especially so you can do tree-shaking with e.g. Rollup.)

Note that the build target is ES2015, since all current evergreen browsers and the current LTS of Node support all ES2015 features. (Strictly speaking, Node 6 does not support all of ES2015, but this library goes nowhere near the couple features it has behind a flag.)

Usage with TypeScript

The Trimble Connect SDK for JavaScript bundles TypeScript definition files for use in TypeScript projects and to support tools that can read .d.ts files. Our goal is to keep these TypeScript definition files updated with each release for any public api.

Pre-requisites

Before you can begin using these TypeScript definitions with your project, you need to make sure your project meets a few of these requirements:

  • Use TypeScript v2.x

  • Includes the TypeScript definitions for node. You can use npm to install this by typing the following into a terminal window: npm install --save-dev @types/node

  • If you are targeting at es5 or older ECMA standards, your tsconfig.json has to include 'es5' and 'es2015.promise' under compilerOptions.lib. See tsconfig.json for an example.

In the Browser

To use the TypeScript definition files in a front-end project, add the following line to the top of your JavaScript file:

/// <reference types="trimble-connect-sdk" />

Questions

General questions can be sent to jari.juntunen@trimble.com in-depth questions about the component can be sent to alexey.otavin@trimble.com.

4.0.3

7 months ago

4.0.1

12 months ago

4.0.2

12 months ago

3.0.3

1 year ago

3.0.2

1 year ago

2.0.25-beta

1 year ago

3.0.1

1 year ago

2.0.26-beta

1 year ago

2.0.24-beta

1 year ago

2.0.24

1 year ago

2.0.23

2 years ago

2.0.22

2 years ago

2.0.21-beta

2 years ago

2.0.20-beta

2 years ago

2.0.19

2 years ago

2.0.18

2 years ago

2.0.20

2 years ago

2.0.21

2 years ago

2.0.15

2 years ago

2.0.16

2 years ago

2.0.13

2 years ago

2.0.14

2 years ago

2.0.11

2 years ago

2.0.12

2 years ago

2.0.10

2 years ago

2.0.17

2 years ago

2.0.16-beta.0

2 years ago

2.0.15-beta.0

2 years ago

2.0.15-beta.1

2 years ago

2.0.15-beta.2

2 years ago

2.0.15-beta.3

2 years ago

2.0.15-beta.4

2 years ago

2.0.15-beta.5

2 years ago

2.0.9

3 years ago

2.0.8

3 years ago

2.0.7

3 years ago

2.0.6

3 years ago

2.0.5

3 years ago

2.0.4

3 years ago

2.0.3

3 years ago

2.0.2

3 years ago

2.0.1

3 years ago

1.2.21

3 years ago

1.2.20

3 years ago

1.2.19

3 years ago

1.2.18

3 years ago

1.2.17

4 years ago

1.2.16

4 years ago

1.2.15

4 years ago

1.2.14

4 years ago

1.2.12

4 years ago

1.2.13

4 years ago

1.2.11

4 years ago

1.2.10

4 years ago

1.2.9

4 years ago

1.2.8

4 years ago

1.2.7

4 years ago

1.2.6

4 years ago

1.2.5

4 years ago

1.2.4

4 years ago

1.2.3

4 years ago

1.2.2

4 years ago

1.2.1

4 years ago