forge-nodejs-utils
TypeScript icon, indicating that this package has built-in type declarations

4.0.0 • Public • Published

forge-nodejs-utils

build status npm version node npm downloads platforms license

Unofficial tools for accessing Autodesk Forge APIs from Node.js applications, built using TypeScript and modern language features like async/await or generators.

Usage

The TypeScript implementation is transpiled into JavaScript with type definition files, so you can use it both in Node.js projects (as a CommonJS module), and in TypeScript projects (as an ES6 module):

// JavaScript
const { DataManagementClient } = require('forge-nodejs-utils');
// TypeScript
import {
    DataManagementClient,
    IBucket,
    IObject,
    IResumableUploadRange,
    DataRetentionPolicy
} from 'forge-nodejs-utils';

Authentication

If you need to generate 2-legged tokens manually, you can use the AuthenticationClient class:

const { AuthenticationClient } = require('forge-nodejs-utils');
const { FORGE_CLIENT_ID, FORGE_CLIENT_SECRET } = process.env;
const auth = new AuthenticationClient(FORGE_CLIENT_ID, FORGE_CLIENT_SECRET);
const authentication = await auth.authenticate(['bucket:read', 'data:read']);
console.log('2-legged token', authentication.access_token);

Other API clients in this library are typically configured using a simple JavaScript object containing either client_id and client_secret properties (for 2-legged authentication), or a single token property (for authentication using a pre-generated access token):

const { DataManagementClient, BIM360Client } = require('forge-nodejs-utils');
const dm = new DataManagementClient({ client_id: '...', client_secret: '...' });
const bim360 = new BIM360Client({ token: '...' });

Data Management

const { DataManagementClient } = require('forge-nodejs-utils');
const { FORGE_CLIENT_ID, FORGE_CLIENT_SECRET } = process.env;
const data = new DataManagementClient({ client_id: FORGE_CLIENT_ID, client_secret: FORGE_CLIENT_SECRET });
 
const buckets = await data.listBuckets();
console.log('Buckets', buckets.map(bucket => bucket.bucketKey).join(','));
 
const objects = await data.listObjects('foo-bucket');
console.log('Objects', objects.map(object => object.objectId).join(','));

Model Derivatives

const { ModelDerivativeClient } = require('forge-nodejs-utils');
const { FORGE_CLIENT_ID, FORGE_CLIENT_SECRET } = process.env;
const derivatives = new ModelDerivativeClient({ client_id: FORGE_CLIENT_ID, client_secret: FORGE_CLIENT_SECRET });
const job = await derivatives.submitJob('<your-document-urn>', [{ type: 'svf', views: ['2d', '3d'] }]);
console.log('Job', job);

Design Automation

const { DesignAutomationClient } = require('forge-nodejs-utils');
const { FORGE_CLIENT_ID, FORGE_CLIENT_SECRET } = process.env;
const client = new DesignAutomationClient({ client_id: FORGE_CLIENT_ID, client_secret: FORGE_CLIENT_SECRET });
const bundles = await client.listAppBundles();
console.log('App bundles', bundles);

Testing

export FORGE_CLIENT_ID=<your-client-id>
export FORGE_CLIENT_SECRET=<your-client-secret>
export FORGE_BUCKET=<your-test-bucket>
export FORGE_MODEL_URN=<testing-model-urn>
npm run build # First transpile TypeScript code is into JavaScript 
npm test

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
4.0.00latest

Version History

VersionDownloads (Last 7 Days)Published
4.0.00
3.4.00
3.3.10
3.3.00
3.2.00
3.1.00
3.0.30
3.0.20
3.0.10
3.0.00
2.2.00
2.1.00
2.0.40
2.0.30
2.0.20
2.0.10
2.0.00
1.6.10
1.6.00
1.5.10
1.5.00
1.4.10
1.3.00
1.2.00
1.1.10
1.1.00
1.0.20
1.0.10
1.0.00
0.10.00
0.9.00
0.8.10
0.8.00
0.7.00
0.6.00
0.5.00
0.4.00
0.3.00

Package Sidebar

Install

npm i forge-nodejs-utils

Weekly Downloads

0

Version

4.0.0

License

MIT

Unpacked Size

1.53 MB

Total Files

80

Last publish

Collaborators

  • petrbroz