GithubHelp home page GithubHelp logo

petrbroz / forge-server-utils Goto Github PK

View Code? Open in Web Editor NEW
34.0 9.0 19.0 3.16 MB

Tools for accessing Autodesk Forge APIs from modern Node.js apps.

Home Page: https://petrbroz.github.io/forge-server-utils/docs/index.html

JavaScript 8.68% TypeScript 89.50% HTML 1.81%
autodesk forge api nodejs async generator

forge-server-utils's Introduction

aps-sdk-node

Publish to NPM npm version node npm downloads platforms license

Unofficial SDK for accessing Autodesk Platform Services from Node.js applications and from browsers, built using TypeScript and modern language features like async/await or generators.

Autodesk Platform Services

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('aps-sdk-node');
// TypeScript
import {
	DataManagementClient,
	IBucket,
	IObject,
	IResumableUploadRange,
	DataRetentionPolicy
} from 'aps-sdk-node';

Authentication

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

const { AuthenticationClient } = require('aps-sdk-node');
const { APS_CLIENT_ID, APS_CLIENT_SECRET } = process.env;
const auth = new AuthenticationClient(APS_CLIENT_ID, APS_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('aps-sdk-node');
const dm = new DataManagementClient({ client_id: '...', client_secret: '...' });
const bim360 = new BIM360Client({ token: '...' });

Data Management

const { DataManagementClient } = require('aps-sdk-node');
const { APS_CLIENT_ID, APS_CLIENT_SECRET } = process.env;
const data = new DataManagementClient({ client_id: APS_CLIENT_ID, client_secret: APS_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('aps-sdk-node');
const { APS_CLIENT_ID, APS_CLIENT_SECRET } = process.env;
const derivatives = new ModelDerivativeClient({ client_id: APS_CLIENT_ID, client_secret: APS_CLIENT_SECRET });
const job = await derivatives.submitJob('<your-document-urn>', [{ type: 'svf', views: ['2d', '3d'] }]);
console.log('Job', job);

Design Automation

const { DesignAutomationClient } = require('aps-sdk-node');
const { APS_CLIENT_ID, APS_CLIENT_SECRET } = process.env;
const client = new DesignAutomationClient({ client_id: APS_CLIENT_ID, client_secret: APS_CLIENT_SECRET });
const bundles = await client.listAppBundles();
console.log('App bundles', bundles);

Reality Capture

const { OutputFormat, RealityCaptureClient, SceneType } = require('aps-sdk-node');
const { APS_CLIENT_ID, APS_CLIENT_SECRET } = process.env;
const recap = new RealityCaptureClient({ client_id: APS_CLIENT_ID, client_secret: APS_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 APS 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/aps-sdk-node/dist/browser/aps-sdk-node.js"></script>
<script>
	const data = new APS.DataManagementClient({ token: '<your access token>' });
	const deriv = new APS.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/aps-sdk-node.js.

Testing

export APS_CLIENT_ID=<your-client-id>
export APS_CLIENT_SECRET=<your-client-secret>
export APS_BUCKET=<your-test-bucket>
export APS_MODEL_URN=<testing-model-urn>
yarn run build # Transpile TypeScript into JavaScript
yarn test

forge-server-utils's People

Contributors

dependabot[bot] avatar liskaj avatar mazerab avatar petrbroz avatar stonesthatwhisper avatar vasicem avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

forge-server-utils's Issues

x-user-id header support

When retrieving BIM360 hubs, projects, folders, items and versions, one can specify user context in a 2-legged authentication by setting x-user-id in the request headers.

This issue was created to add support for x-user-id in forge-server-utils.

Issues when translating files that are uploaded using uploadObjectStreamResumable

Tried uploading over 100mb file using uploadObjectStreamResumable with the block of code below,

const nbChunks = Math.ceil(fileContent.ContentLength / minChunk);
const chunksMap = Array.from({ length: nbChunks }, (elem, idx) => idx);
const promisedObj = await Promise.all(chunksMap.map(chunkIdx => {
  const byteOffset = chunkIdx * minChunk;
  const chunkBytes = Math.min(fileContent.ContentLength, (chunkIdx + 1) * minChunk) - byteOffset;

  return ObjectsApi.uploadObjectStreamResumable(bucket_key, fileName, stream, chunkBytes, byteOffset, fileContent.ContentLength, sessionId);
}));

but getting,

{
  "type": "warning",
  "code": "Navisworks-EmptyFile",
  "message": "There is no geometry that can be displayed"
}

and,

{
  "type": "error",
  "message": "Unrecoverable exit code from extractor: -1073741829",
  "code": "TranslationWorker-InternalFailure"
}

when translating. I've also tried for...of, and reduce when uploading chunks but getting 504 Gateway Timeout issues.

Error with`getVersionDetails`

Hi,

When I try to use the "getVersionDetails" with bim360 client, I get a 404 error.
You're route is like that :
const response = await this.get('data/v1/projects/${projectId}/items/${itemId}/versions/${versionId}', {}, ReadTokenScopes);

but in the Forge documentation there's not "items/itemsID" part so I think this function should be :
const response = await this.get('data/v1/projects/${projectId}/versions/${versionId}', {}, ReadTokenScopes);

Can you confirm ? Or maybe I missed something ?

uploadObject function - Uploading file larger than 10MB

I have an issue with the uploadObject fonction from forge-server-utils. I receive Request body larger than maxBodyLength limit error on the request.
The problem is coming on file larger than 10MB (you can find the sample in the attachments).
sample_bodyLengthError.zip

What is strange is that I cannot replicate the error using forge-apis module. However, implementing my "own" axios request in setting maxBodyLength and maxContentLength to Infinity will lead to the same error.

Implement direct-to-s3 apis

Hi @petrbroz ,

Will you be updating this API to include the upcoming changes for direct-to-s3? I can see you've made a start in projects, but would be keen to learn of any timeline you're working to, if at all?

Can't retrieve BIM 360 Issues (problem with pagination API)

I cannot retrieve a list of BIM 360 Issues using this library due to Autodesk changed their response body structure:
Instead of response.links.next.href url is now placed directly in response.links.next property which results in an undefined url, thus no more data can be fetched, so the BIM360Client.listIssues method returns an Error instead of list of issues.

Screen Shot 2022-02-18 at 3 56 39 PM

Source code reference:

https://github.com/petrbroz/forge-server-utils/blob/42868665917ebd4d1fcb191eb086c522e3463d34/src/bim360.ts#L877

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.