npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

fsv-v2

v1.0.2

Published

forge server utils forked

Downloads

5

Readme

forge-server-utils

Publish to NPM npm version node npm downloads platforms license

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.

Autodesk Forge

Usage

Server Side

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:

// JavaScript
const { DataManagementClient } = require('forge-server-utils');
// 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:

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), or a single token property (for authentication using a pre-generated access token):

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

Data Management

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

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('<your-document-urn>', [{ type: 'svf', views: ['2d', '3d'] }]);
console.log('Job', job);

Design Automation

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

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: '<scene name>',
    scenetype: SceneType.Aerial,
    format: OutputFormat.RecapPhotoMesh,
    callback: '<callback>'
};
const photoscene = await recap.createPhotoScene(options);
console.log('Photoscene', photoscene);

Client Side (experimental)

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.

<script src="https://cdn.jsdelivr.net/npm/forge-server-utils/dist/browser/forge-server-utils.js"></script>
<script>
	const data = new forge.DataManagementClient({ token: '<your access token>' });
	const deriv = new forge.ModelDerivativeClient({ token: '<your access token>' });
	data.listBuckets()
		.then(buckets => { console.log('Buckets', buckets); })
		.catch(err => { console.error('Could not list buckets', err); });
	deriv.submitJob('<your document urn>', [{ type: 'svf', views: ['2d', '3d'] }])
		.then(job => { console.log('Translation job', job); })
		.catch(err => { console.error('Could not start translation', err); });
</script>

Note that you can also request a specific version of the library from CDN by appending @<version> to the npm package name, for example, https://cdn.jsdelivr.net/npm/[email protected]/dist/browser/forge-server-utils.js.

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>
yarn run build # Transpile TypeScript into JavaScript
yarn test