0.1.19 • Published 6 years ago

cdm-org-sdk v0.1.19

Weekly downloads
83
License
SEE LICENSE IN li...
Repository
bitbucket
Last release
6 years ago

CDM Organizer Service SDK for JavaScript

The official Organizer Service SDK for JavaScript, available for browsers and mobile devices.

The CDM Organizer Service SDK for JavaScript provides a JavaScript API for CDM Organizer Service 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 CDM services.

Get started with usage

Go ahead and add the component as a dependency to your project: npm install cdm-org-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 CDM from "cdm-org-sdk";

const tidParams = {
    clientId: "id_received_on_app_registration_in_tppas",
    clientSecret: "secret_key_received_on_app_registration_in_tppas",
    serviceUri: "https://identity.trimble.com/",
};
const tidCreds = new CDM.TIDCredentials(tidParams);
CDM.OrganizerClient.config.credentials = new CDM.ServiceCredentials(CDM.OrganizerClient, tidCreds);
CDM.TCPSClient.config.credentials = new CDM.ServiceCredentials(CDM.TCPSClient, tidCreds);

// if you need to use different service environments:
CDM.OrganizerClient.config.serviceUri = "https://org-api.stage.fulcrum-cdm.com/v1/";
CDM.TCPSClient.config.serviceUri = "https://app.connect.trimble.com/tc/api/2.0/";

// 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",
};

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

const servers = await CDM.TCPSClient.listServers();
const projects = await CDM.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.

import * as CDM from "cdm-org-sdk";
const tpaasParams = {
    clientId: "id_received_on_app_registration_in_tppas",
    clientSecret: "secret_key_received_on_app_registration_in_tppas",
    serviceUri: "https://identity.trimble.com/",
};
const tpaasCredsForUnitTesting = new CDM.TIDCredentials(tpaasParams, {
    password: "pass",
    username: "user@trimble.com",
});
CDM.OrganizerClient.config.credentials = new CDM.ServiceCredentials(CDM.OrganizerClient, tpaasCredsForUnitTesting);

If you received tokens elsewhare 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 CDM from "cdm-org-sdk";

CDM.OrganizerClient.config.credentials = {token: "token_received_from_elsewhere"};
CDM.TCPSClient.config.credentials = {token: "token_received_from_elsewhere"};

Example of creating of an other client instance (if. e.g. app need to contact service on behalf of different user):

import * as CDM from "cdm-org-sdk";

const client: CDM.Organizer = new CDM.Organizer({
    serviceUri: "https://org-api.stage.fulcrum-cdm.com/v1/",
    });

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('cdm-org-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 CDM 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 with the global CDM object in a front-end project, add the following line to the top of your JavaScript file:

/// <reference types="cdm-org-sdk" />

This will provide support for the global CDM object.

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.

0.1.19

6 years ago

0.1.18

6 years ago

0.1.17

6 years ago

0.1.16

6 years ago

0.1.15

6 years ago

0.1.14

6 years ago

0.1.13

6 years ago

0.1.12

6 years ago

0.1.11

6 years ago

0.1.10

6 years ago

0.1.9

6 years ago

0.1.8

6 years ago

0.1.7

6 years ago

0.1.6

6 years ago

0.1.5

6 years ago

0.1.4

6 years ago

0.1.3

6 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago

1.0.0

6 years ago