Giter Site home page Giter Site logo

box / box-salesforce-sdk Goto Github PK

View Code? Open in Web Editor NEW
55.0 55.0 52.0 594 KB

This is the Salesforce SDK for integrating with the Box Platform.

Home Page: https://developer.box.com/guides/tooling/sdks/salesforce/

License: Apache License 2.0

Apex 99.98% JavaScript 0.02%
apex

box-salesforce-sdk's People

Contributors

bassman531 avatar dependabot[bot] avatar dp3000 avatar jasonpan12 avatar jcleblanc avatar krystiancharubin 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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

box-salesforce-sdk's Issues

BoxGroup generates invalid request urls

Resource strings in BoxGroup.cls have a '/' prefix and the base url from BoxApiConnection has a '/' suffix. When joined these generate an invalid url and the request fails.

The automated release is failing 🚨

🚨 The automated release from the master branch failed. 🚨

I recommend you give this issue a high priority, so other packages depending on you could benefit from your bug fixes and new features.

You can find below the list of errors reported by semantic-release. Each one of them has to be resolved in order to automatically publish your package. I’m sure you can resolve this πŸ’ͺ.

Errors are usually caused by a misconfiguration or an authentication problem. With each error reported below you will find explanation and guidance to help you to resolve it.

Once all the errors are resolved, semantic-release will release your package the next time you push a commit to the master branch. You can also manually restart the failed CI job that runs semantic-release.

If you are not sure how to resolve this, here is some links that can help you:

If those don’t help, or if this issue is reporting something you think isn’t right, you can always ask the humans behind semantic-release.


No npm token specified.

An npm token must be created and set in the NPM_TOKEN environment variable on your CI environment.

Please make sure to create an npm token and to set it in the NPM_TOKEN environment variable on your CI environment. The token must allow to publish to the registry https://registry.npmjs.org/.


Good luck with your project ✨

Your semantic-release bot πŸ“¦πŸš€

Custom object usage limits

Exposing Box content within 1 or more custom objects in Salesforce may have serious consequences for clients API usage limits. We believe the architecture of this system poses unique challenges for developers, administrators and for Salesforce operations team to track API utilization.

We propose an enhancement which would audit the number updates made to Salesforce Custom Objects and audit the clients usage limit associated with the Salesforce instance. This data would be visible on granular level for analysis. This data could be useful to correlate the changes in the target instance for verifying more complex work flows.

Metadata support

Have a customer who wants to pull metadata from SFDC and apply it to Box content.

Trouble with connecting Salesforce with Box using JWT

Hello,
I am trying to connect Salesforce with box using JWT. Following this link(https://github.com/box/box-salesforce-sdk/blob/master/doc/platform.md). I am getting these errors:

Class.BoxPlatformApiConnection.constructJwtSignature: line 218, column 1
Class.BoxPlatformApiConnection.constructJwtAssertion: line 174, column 1
Class.BoxPlatformApiConnection.authenticate: line 134, column 1
Class.BoxPlatformApiConnection.getAppEnterpriseConnection: line 95, column 1

Am I missing some setup?

Thanks.

getChildren for the folder doesn't work

list<BoxItem.Info> children = folder.getChildren();

throws an exception

BoxJsonObject.BoxJsonObjectException: Json string passed to BoxJsonObject.parseJsonObjectArray was not valid json

BoxApiRequest.checkContextForCallout() method does nothing

The current checkContextForCallout() method looks like this:

private void checkContextForCallout() {
   if (Limits.getLimitCallouts() < 1) {
      throw new BoxApiRequestException('BoxApiRequest unable to make a callout due to no remaining callouts allowed (Limits.getLimitCallouts() == 0).');
   }
}

However, getLimitCallouts() returns the per transaction callout limit -- so, 100 is always returned.
If the intent is to make sure that the number of callouts made so far hasn't hit the limit, then the method should probably be:

private void checkContextForCallout() {
   if (Limits.getLimitCallouts() <= Limits.getCallouts()) {
      throw new BoxApiRequestException('BoxApiRequest unable to make a callout due to no remaining callouts allowed.');
   }
}

Folder.Info.uploadEmail is always null

In the following code:

BoxFolder.Info info = folder.getFolderInfo();
BoxUploadEmail.Info emailInfo = info.uploadEmail;

emailInfo will always be null, because the class isn't parsing the json response correctly for the upload email info. Per the docs, the correct json tag is folder_upload_email; the code is checking for upload_email. PR forthcoming.

Compilation issues with BoxFile.cls

When trying to deploy via Deploy to Salesforce Functionality, the deploy fails with multiple errors all pointing to BoxFile.cls

classes/BoxFile.cls(263,14):Missing ';' at 'responseBody'

There is a missing assignment at line 263. In
String responseBody BoxApiRequest.ensureBoxResourceResponseBody(response, 'BoxFile.getTrashedFile', new set<Integer>{200});

Should be

String responseBody = BoxApiRequest.ensureBoxResourceResponseBody(response, 'BoxFile.getTrashedFile', new set<Integer>{200});
If this issue is not already being addressed, I'll create a PR.

Cannot obtain user token based on the enterprise configuration for your app

I am using the JWT auth and not able to connect with the app user after creating one through enterprise connection. ` BoxJwtEncryptionPreferences preferences = new BoxJwtEncryptionPreferences();
preferences.setPublicKeyId(publicKeyId);
preferences.setPrivateKey(privateKey);

       BoxPlatformApiConnection pApi = BoxPlatformApiConnection.getAppEnterpriseConnection(userId, clientId, clientSecret, preferences);

BoxApiConnection api = new BoxApiConnection (pApi.getAccessToken()); //create api instance

BoxUser.createAppUser (api, 'appUser2');

`
This one successfully gives me the token and creates a user for the app.

After that one I am trying to getappuserconnection but getting error. What am I missing? My app is configured to work with app users.

BoxPlatformApiConnection pApi = BoxPlatformApiConnection.getAppUserConnection(userId, clientId, clientSecret, preferences);

Remove custom JSON parsing

When the SDK was originally written, the decision was made to use custom JSON parsing for a few reasons:
-Some fields required custom handling (datetime fields, for example)
-Consistency with the Box Java SDK

After real-world use, it turns out that these reasons are inadequate to justify a custom JSON parser. Simply defaulting to the built in JSON class methods is a much better option both in terms of performance and usability.

Sandbox Package Link in Repo readme is out of date.

Ran into an issue where getting the current User failed with "Invalid long: 1.0e+15"; the stack trace and inspection of the raw response show that the raw JSON response includes:

"space_amount":1.0e+15

which BoxUser.Info is trying to parse as a long(); Apex's long.valueOf(x) method cannot parse scientific notation.

Looks like commit c4b5287 addressed that issue for a space_amount number of other fields back in March; I just installed the SDK today using the "Sandbox Package Link" in the readme, and didn't get that fix. Not sure how to tell how old the installed code is, but it isn't current.

Compilation issues

  • Line 228 in BoxFileTests does not compile
  • Line 263 in BoxFile does not compile
    • ensureBoxResourceResponseBody does not exist
    • Changed to getBoxResourceResponseBody
  • Line 354 invalid public declaration

JTI becomes invalid after rate limiting

We are using box-salesforce-sdk to allow our community users to download and upload box files. We use JWT authentication and will sometimes issues of an invalid/non-unique JTI. We have contacted Box Support who mentioned that they had seen rate limits being hit on our account. This is similar to a problem that occurred in the node.js version of the SDK. box/box-node-sdk#403

Error Message
{"error":"invalid_grant","error_description":"Please check the 'jti' claim. A unique 'jti' value is required."}

Platform Auth

The enterprise example from platform.md does not compile when used in a new class.

Line 8 Errors

  • Unexpected token ')'.
  • Invalid character in identifier: )
  • Invalid type: publicKeyId
  • Invalid constructor name: preferences.setPublicKeyId

Same errors for line 9 with the privateKey variable respectively.

Parameters are in the wrong order in BoxEnterprise getEnterpriseEvents

The URL string has the limit parameter as item 0 and stream_position as item 1.
private static final String GET_ENTERPRISE_EVENTS_URL = '/events?stream_type=admin_logs&limit={0}&stream_position={1}';

But when replacing the values in the getEnterpriseEvents method, streamPosition is first and numberOfEventsLimit is second.

        String url =
            this.api.baseUrl +
            String.format(
                GET_ENTERPRISE_EVENTS_URL,
                new List<String>{
                    streamPosition,
                    String.valueOf(numberOfEventsLimit)
                }
            );

Box SDK code coverage lacking: If you need more code coverage, use this.

This helped me to cover the gaps left in code coverage for:

  • BoxUploadEmail
  • BoxEmailAlias
  • BoxEnterprise
  • BoxFolder
  • BoxApiRequest

It is not beautiful but I was in a jam and if you found this issue, I suspect you are too.

`
@istest
private class ppg_BoxPackageTests {

private static String url = 'https://example.com';
private static String method = 'GET';
private static String accessToken = 'accesstoken';
private static String refreshToken = 'refreshtoken';
private static String clientId = 'clientid';
private static String clientSecret = 'clientsecret';

@IsTest
static void boxFolder() {
    String mockResponseBody = '{"type":"collaboration","id":"791293","created_by":{"type":"user","id":"17738362","name":"sean rose","login":"[email protected]"},"created_at":"2012-12-12T10:54:37-08:00","modified_at":"2012-12-12T11:30:43-08:00","expires_at":null,"status":"accepted","accessible_by":{"type":"user","id":"18203124","name":"sean","login":"[email protected]"},"role":"editor","acknowledged_at":"2012-12-12T11:30:43-08:00","item":{"type":"folder","id":"11446500","sequence_id":"0","etag":"0","name":"Shared Pictures"}}';
    Test.setMock(HttpCalloutMock.class, new BoxTestMockCallout(mockResponseBody, 'Created', 201));

    BoxApiConnection api = new BoxApiConnection('accesstoken');
    BoxFolder folder = new BoxFolder(api, '11446500');

    String folderInfoResponseBody = '{"type":"folder","id":"11446498","sequence_id":"1","etag":"1","name":"Pictures","created_at":"2012-12-12T10:53:43-08:00","modified_at":"2012-12-12T11:15:04-08:00","description":"Some pictures I took","size":629644,"path_collection":{"total_count":1,"entries":[{"type":"folder","id":"0","sequence_id":null,"etag":null,"name":"All Files"}]},"created_by":{"type":"user","id":"17738362","name":"sean rose","login":"[email protected]"},"modified_by":{"type":"user","id":"17738362","name":"sean rose","login":"[email protected]"},"owned_by":{"type":"user","id":"17738362","name":"sean rose","login":"[email protected]"},"shared_link":{"url":"https://www.box.com/s/vspke7y05sb214wjokpk","download_url":null,"vanity_url":null,"is_password_enabled":false,"unshared_at":null,"download_count":0,"preview_count":0,"access":"open","permissions":{"can_download":true,"can_preview":true}},"folder_upload_email":{"access":"open","email":"[email protected]"},"parent":{"type":"folder","id":"0","sequence_id":null,"etag":null,"name":"All Files"},"item_status":"active","item_collection":{"total_count":1,"entries":[{"type":"file","id":"5000948880","sequence_id":"3","etag":"3","sha1":"134b65991ed521fcfe4724b7d814ab8ded5185dc","name":"tigers.jpeg"}],"offset":0,"limit":100}}';
    BoxFolder.Info folderInfo = new BoxFolder.Info(folderInfoResponseBody);

    Test.startTest();
    BoxCollaboration.Role collabRole = BoxCollaboration.Role.EDITOR;
    BoxCollaboration.Info groupCollab = folder.collaborate(new BoxGroup(api, '791293'), collabRole);
    BoxCollaboration.Info userCollab = folder.collaborate(new BoxUser(api, '829384'), collabRole);
    folder.getCollaborations();
    folder.deleteFolder(true);
    folder.rename('bananaMangoSherbert');
    folder.getFolderInfo();
    folder.updateFolderInfo(folderInfo);
    folder.uploadFile(Blob.valueOf('Who\'s a good blobby blob blob?'), 'SherbertBlob.pdf');
    folder.uploadFile(new Attachment(Body = Blob.valueOf('Who\'s a good blobby blob blob?')), 'MangoBlob.pdf');
    folder.uploadFile(new Document(Body = Blob.valueOf('Who\'s a good blobby blob blob?')), 'BananaBlob.pdf');
    folder.getChildren();
    folder.getChildren(2, 10);
    Test.stopTest();
    // No Asserts because we don't create this logic, just trying to cover it so we can deploy this unmanaged package to production.
}

@IsTest
static void apiRequest() {
    list<BoxTestMockCallout.MockResponse> responses = new list<BoxTestMockCallout.MockResponse>();
    BoxTestMockCallout.MockResponse redirectResponse = new BoxTestMockCallout.MockResponse('{"status":"redirect"}', 'REDIRECT', 301);
    responses.add(redirectResponse);
    BoxTestMockCallout.MockResponse successResponse = new BoxTestMockCallout.MockResponse('{"Status":"success"}', 'OK', 200);
    responses.add(successResponse);
    Test.setMock(HttpCalloutMock.class, new BoxTestMockCallout(responses));

    Test.startTest();
    BoxApiConnection api = new BoxApiConnection(clientId, clientSecret, accessToken, refreshToken);
    api.lastRefresh = DateTime.now().getTime() - 5;
    api.expires = api.lastRefresh + 60000;
    BoxApiRequest request = new BoxApiRequest(api, url, method);
    request.setBody('request body');
    request.addJsonContentTypeHeader();
    request.setMultipartFormBody(Blob.valueOf('request body'), 'requestfilename.pdf');
    request.setTimeout(500);
    HttpResponse finalResponse = request.send();
    BoxApiRequest.ensureBoxResourceResponseCode(finalResponse, 'get', new Set<Integer> {400});
    BoxApiRequest.getBoxResourceResponseBody(finalResponse, 'get');
    try {
        BoxApiRequest.ensureBoxResourceResponseCode(null, 'apiMethod', new Set<Integer> {400});
        System.assert(false, 'Expected an exception to be thrown before we get to this point.');
    } catch (Exception ex) {
        System.assert(true, 'Expected a box exception because we passed in a null response into ensureBoxResourceResponseCode.');
    }

    try {
        BoxApiRequest.getBoxResourceResponseBody(null, 'get');
        System.assert(false, 'Expected an exception to be thrown before we get to this point.');
    } catch (Exception ex) {
        System.assert(true, 'Expected a box exception because we passed in a null response into getBoxResourceResponseBody.');
    }

    Test.stopTest();

    System.assertEquals(200, finalResponse.getStatusCode());
}

@IsTest
static void enterprise() {
    String mockResponseBody = '{"chunk_size": 3,"next_stream_position": "28893355","entries": [{"source": null,"created_by": {"type": "user","id": "181216415","name": "sean rose","login": "[email protected]"},"created_at": "2012-12-12T10:53:43-08:00","event_id": "28893270","event_type": "ADD_LOGIN_ACTIVITY_DEVICE","ip_address": "67.218.117.3","type": "event","session_id": null},{"source": null,"created_by": {"type": "user","id": "181216415","name": "sean rose","login": "[email protected]"},"created_at": "2012-12-12T10:53:43-08:00","event_id": "28893272","event_type": "LOGIN","ip_address": "67.218.117.3","type": "event","session_id": null},{"source": {"type": "folder","id": "387630341","sequence_id": "0","name": "A BNE"},"created_by": {"type": "user","id": "181216415","name": "sean rose","login": "[email protected]"},"created_at": "2012-12-12T10:53:43-08:00","event_id": "28893354","event_type": "UPLOAD","ip_address": "67.218.117.3","type": "event","session_id": null}]}';
    Test.setMock(HttpCalloutMock.class, new BoxTestMockCallout(mockResponseBody, 'OK', 200));

    BoxApiConnection api = new BoxApiConnection('accesstoken');

    BoxEnterprise enterprise = new BoxEnterprise(api,'10543463');
    BoxEnterprise.Info enterpriseInfo = new BoxEnterprise.Info();
    enterpriseInfo.addValue('name', 'Tv Enterprise');
    enterpriseInfo.addValue('name', new BoxEnterprise.Info());
    enterpriseInfo = new BoxEnterprise.Info('{"name": "Tv Enterprise"}');

    Test.startTest();
    list<BoxEvent.Info> events = enterprise.getEnterpriseEvents();
    System.assertNotEquals(null, enterprise.getObjectType(), 'Expected the object type to not be null.');
    System.assertEquals(3, events.size());
    events = enterprise.getEnterpriseEvents(10, 'streamPosition', 'eventType', 'createdAfter', 'createdBefore');
    Test.stopTest();
}

@IsTest
static void emailAlias() {
    BoxApiConnection api = new BoxApiConnection('accesstoken');
    BoxEmailAlias boxEmailAlias = new BoxEmailAlias(api,'10543463');
    BoxEmailAlias.Info emailAliasInfo = new BoxEmailAlias.Info();
    emailAliasInfo = new BoxEmailAlias.Info('{"email": "[email protected]" }');
    emailAliasInfo = new BoxEmailAlias.Info(emailAliasInfo);
    emailAliasInfo.addValue('email', '[email protected]');
    emailAliasInfo.addValue('email', emailAliasInfo);
    boxEmailAlias.getObjectType();
    boxEmailAlias.setInfo(emailAliasInfo);


    Test.startTest();
    emailAliasInfo.parseMember('is_confirmed', 'true');
    emailAliasInfo.parseMember('email','[email protected]');
    Test.stopTest();

    System.assertEquals(true, emailAliasInfo.isConfirmed);
    System.assertEquals('[email protected]', emailAliasInfo.email);
}

@IsTest
static void uploadEmail() {
    BoxApiConnection api = new BoxApiConnection('accesstoken');
    BoxUploadEmail uploadEmail = new BoxUploadEmail(api,'10543463');
    BoxUploadEmail.Info uploadEmailInfo = new BoxUploadEmail.Info();
    uploadEmailInfo = new BoxUploadEmail.Info('{"access": "open"}');
    uploadEmailInfo.addValue('email', '[email protected]');
    uploadEmailInfo.addValue('key', uploadEmailInfo);

    Test.startTest();
    uploadEmailInfo.parseMember('access', 'open');
    uploadEmailInfo.parseMember('email', '[email protected]');
    uploadEmail.getObjectType();
    uploadEmail.setInfo(uploadEmailInfo);
    Test.stopTest();

    System.assertEquals(BoxUploadEmail.Access.OPEN, uploadEmailInfo.access);
    System.assertEquals('[email protected]', uploadEmailInfo.email);
}

}
`

Missing meta-data and Search classes in Salesforce SDK

Hi,
In the Salesforce SDK, I am not able to find the Metadata and Search classes, although they are available in the java sdk. Can you please let me know how we can get doc meta-data and search for documents using the Salesforce SDK. Hoping for a quick response as its hampering our further development.

Any API/Property in Box that show that this particulater file is Previewd

Ability to notify the client(End User) when a NEW file to view is available.
I.E: IF a new file has been uploaded to the box and is in a portal(UI) folder want to indicate to the client that a new document is available to view.

Note: We just want to indicate our end user that you have a new notification as you don't view this particular(New/Existing) file
Exp- In Attached Picture, there is Banking Form(A Box-Folder which has a file which havnt preview by this user)
12

Test Class Compilation Errors

We have deployed complete sdk and encountered compilation errors below. Can we have updated test classes please.

Compilation Complete
Compilation Errors found:
BoxApiRequestTests: line 123, column 27: Variable does not exist: HEADER_LOCATION_LOWER_CASE
BoxApiRequestTests: line 129, column 17: Method is not visible: System.HttpResponse BoxApiRequest.handleRedirect(System.HttpResponse)
BoxApiRequestTests: line 172, column 27: Variable does not exist: HEADER_LOCATION_CAPITALIZED
BoxApiRequestTests: line 178, column 17: Method is not visible: System.HttpResponse BoxApiRequest.handleRedirect(System.HttpResponse)
BoxFileTests: line 260, column 41: Method does not exist or incorrect signature: void getExpiringEmbedLink() from the type BoxFile
BoxFileTests: line 301, column 50: Method does not exist or incorrect signature: void getTrashedFile() from the type BoxFile
BoxTestMockCallout: line 55, column 35: Variable does not exist: HEADER_LOCATION_LOWER_CASE
BoxTestMockCallout: line 60, column 35: Variable does not exist: HEADER_LOCATION_CAPITALIZED
Box compile errors

Add support for uploading Files

With the move to Lightning Experience, Attachments are being replaced by Files. We currently make it easy to upload attachments from Salesforce to Box. We should do the same for files.

Improved error messaging

Tried to push revision and submit pull request but received 403. The custom error messages in BoxApiRequest (lines 134, 136) provide no useful information. Messaging should utilize response.getBody() to provide useful debugging info. If you approve me, I can submit PR for your review.

Issue installing

Failures:
classes/BoxApiConnection.cls(69,37):Dependent class is invalid and needs recompilation:
Class.BoxApiRequest.getBoxResourceResponseBody: line 205, column 23
BoxResource: line 36, column 36: Dependent class is invalid and needs recompilation:
BoxFolder: line 341, column 12: Invalid type: BoxFile.Info
classes/BoxApiConnectionTests.cls(11,37):Dependent class is invalid and needs recompilation:
Class.BoxApiConnection.authenticate: line 69, column 37

Add support for body parameters when uploading new file version

Currently, the SDK only supports building a multipart/form-data body using the file content only. However, the Upload File Version operation supports additional body parameters for specifying a new 'name' as well as the 'content_modified_at' attribute. (https://developer.box.com/reference#upload-a-new-version-of-a-file)

(The "BoxBase64" class itself seems to be non-standard (looks like it's blending in some "quoted-printable" encoding?, etc.), and we've been unsuccessful at trying to modify this class to support the additional body parameters...)

The workaround is to upload the new file version then rename the file in a separate request.

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.