Tools for accessing Autodesk Forge APIs from Node.js apps and from browser.
npm install forge-server-utils!Publish to NPM

!node
!npm downloads
!platforms

Unofficial tools for accessing Autodesk Forge APIs from Node.js applications
and from browsers, built using TypeScript and modern language features like
async/await
or generators.
The TypeScript implementation is transpiled into CommonJS JavaScript module with type definition files,
so you can use it both in Node.js projects, and in TypeScript projects:
``js`
// JavaScript
const { DataManagementClient } = require('forge-server-utils');
`ts`
// TypeScript
import {
DataManagementClient,
IBucket,
IObject,
IResumableUploadRange,
DataRetentionPolicy
} from 'forge-server-utils';
#### Authentication
If you need to generate 2-legged tokens
manually, you can use the AuthenticationClient class:
`js`
const { AuthenticationClient } = require('forge-server-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),token
or a single property (for authentication using a pre-generated access token):
`js`
const { DataManagementClient, BIM360Client } = require('forge-server-utils');
const dm = new DataManagementClient({ client_id: '...', client_secret: '...' });
const bim360 = new BIM360Client({ token: '...' });
#### Data Management
`js
const { DataManagementClient } = require('forge-server-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
`js`
const { ModelDerivativeClient } = require('forge-server-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('
console.log('Job', job);
#### Design Automation
`js`
const { DesignAutomationClient } = require('forge-server-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);
#### Reality Capture
`js`
const { OutputFormat, RealityCaptureClient, SceneType } = require('forge-server-utils');
const { FORGE_CLIENT_ID, FORGE_CLIENT_SECRET } = process.env;
const recap = new RealityCaptureClient({ client_id: FORGE_CLIENT_ID, client_secret: FORGE_CLIENT_SECRET });
const options = {
scenename: '
scenetype: SceneType.Aerial,
format: OutputFormat.RecapPhotoMesh,
callback: '
};
const photoscene = await recap.createPhotoScene(options);
console.log('Photoscene', photoscene);
The transpiled output from TypeScript is also bundled using webpack,
so you can use the same functionality in a browser. There is a caveat, unfortunately: at the moment
it is not possible to request Forge access tokens from the browser
due to CORS limitations,
so when creating instances of the various clients, instead of providing client ID and secret
you will have to provide the token directly.
`html`
Note that you can also request a specific version of the library from CDN by appending @https://cdn.jsdelivr.net/npm/forge-server-utils@4.0.0/dist/browser/forge-server-utils.js
to the npm package name, for example, .
`bash``
export FORGE_CLIENT_ID=
export FORGE_CLIENT_SECRET=
export FORGE_BUCKET=
export FORGE_MODEL_URN=
yarn run build # Transpile TypeScript into JavaScript
yarn test