How to use the box-node-sdk.getPreconfiguredInstance function in box-node-sdk

To help you get started, we’ve selected a few box-node-sdk examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github box / boxcli / src / box-command.js View on Github external
try {
				configObj = JSON.parse(fs.readFileSync(environment.boxConfigFilePath));
			} catch (ex) {
				throw new BoxCLIError('Could not read environments config file', ex);
			}

			if (!environment.hasInLinePrivateKey) {
				try {
					configObj.appAuth.privateKey = fs.readFileSync(environment.privateKeyPath, 'utf8');
					DEBUG.init('Loaded JWT private key from %s', environment.privateKeyPath);
				} catch (ex) {
					throw new BoxCLIError(`Could not read private key file ${environment.privateKeyPath}`, ex);
				}
			}

			this.sdk = BoxSDK.getPreconfiguredInstance(configObj);
			this.sdk.configure({ ...SDK_CONFIG });

			client = this.sdk.getAppAuthClient('enterprise', environment.enterpriseId, tokenCache);
			DEBUG.init('Initialized client from environment config');

			if (environment.useDefaultAsUser) {
				client.asUser(environment.defaultAsUserId);
				DEBUG.init('Impersonating default user ID %s', environment.defaultAsUserId);
			}

			if (this.flags['as-user']) {
				client.asUser(this.flags['as-user']);
				DEBUG.init('Impersonating user ID %s', this.flags['as-user']);
			}
		} else {
			// No environments set up yet!
github box / samples / box-node-lambda-sample / index.js View on Github external
/**
 * This sample demonstrates how to call Box APIs from a Lambda function using the Box Node SDK.
 *
 * For step-by-step instructions on how to create and authorize a Box application,
 * see https://github.com/box/samples/tree/master/box-node-lambda-sample.
 */

'use strict';

const BoxSDK = require('box-node-sdk');

// Load the config from an environment variable for security and configuration management.
const boxConfig = JSON.parse(process.env.BOX_CONFIG);

const sdk = BoxSDK.getPreconfiguredInstance(boxConfig);

/**
 * Create a service account client that performs actions in the context of the specified
 * enterprise.  The app has a unique service account in each enterprise that authorizes the app.
 * The service account contains any app-specific content for that enterprise.
 * Depending on the scopes selected, it can also create and manage app users or managed users
 * in that enterprise.
 *
 * The client will automatically create and refresh the service account access token, as needed.
 */
const client = sdk.getAppAuthClient('enterprise');

/**
 *  YOUR CODE GOES HERE!!!
 *
 *  This sample function returns details of the current user (the service account).
github box / samples / box-node-webhook-to-lambda-sample / index.js View on Github external
/**
 * This sample shows how to connect a Box webhook to a Lambda function via API Gateway.
 *
 * For step-by-step instructions on how to create a Box application and a webhook,
 * see https://github.com/box/samples/tree/master/box-node-webhook-to-lambda-sample
 */

'use strict';

const BoxSDK = require('box-node-sdk');

// Load the config from an environment variable for security and configuration management.
const boxConfig = JSON.parse(process.env.BOX_CONFIG);

BoxSDK.getPreconfiguredInstance(boxConfig);

/**
 *  YOUR CODE GOES HERE!!!
 *
 *  This sample function simply logs details of the webhook event to Cloudwatch.
 *  Your code could forward the event to SNS or Kinesis for further processing.
 *  For FILE.UPLOADED events, you could use the Box Node SDK to download the file, analyze it,
 *  and update the file on Box with metadata that contains the results of the analysis.
 */
function handleWebhookEvent(webhookEvent) {
    // Print basic information about the Box event
    let message = `webhook=${webhookEvent.webhook.id}`;

    // The event trigger: FILE.DOWNLOADED, FILE.UPLOADED, etc.
    message += `, trigger=${webhookEvent.trigger}`;
github box / samples / box-node-express-skeleton-app / app / box-service / boxClientService.js View on Github external
constructor() {
		this.BoxConfig = new BoxConfig(BoxSDKConfig, BoxSDKConfig.boxConfigFilePath);
		this.BoxSdk = Box.getPreconfiguredInstance(this.BoxConfig.getConfig());
		this.BoxCache = BoxCache;
	}

box-node-sdk

Official SDK for Box Plaform APIs

Apache-2.0
Latest version published 4 days ago

Package Health Score

87 / 100
Full package analysis