forge-nodejs-utils
v4.0.0
Published
Tools for accessing Autodesk Forge APIs from Node.js apps.
Downloads
4
Maintainers
Readme
forge-nodejs-utils
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