• 0 Votes
    2 Posts
    59 Views

    Use API blocking in the cloud code category to block all apis from client that write your user entities. Then clients can only write their entities using cloud-code and there you have the total control

  • 0 Votes
    3 Posts
    166 Views

    @JasonL Thanks, I ended up with this cloudCode:

    isForceCreate = String(data.callingMessage.forceCreate) == "true"; isNewUser = String(data.message.newUser) == "true"; var response = {}; response.status = 200; response.data = data.message; if (isForceCreate && isNewUser) { var min = 10000000, max = 999999999 prefix = ["player", "user", "member"] const num = Math.floor(Math.random() * (max - min + 1)) + min; const pre = prefix[Math.floor(Math.random() * prefix.length)]; var defaultPlayerName = pre + String(num); var playerStateProxy = bridge.getPlayerStateServiceProxy(); // We are changing the player name on the server. playerStateProxy.updatePlayerName(defaultPlayerName); // And in this API Call's return data. response.data.playerName = pre + String(num); } response; //return the object

    This works just the way I need

  • 0 Votes
    2 Posts
    101 Views

    I posted this almost 13 days ago with zero answers, so I took some time to look through a bunch of documentation and did a ton of trial and error. Please Braincloud for the love of god add this to your API.

    Rhino does not handle Arrays the way that other coding languages do.

    I figured it out, unlike most arrays that return an array after you call push- Rhino returns the new length. So if you call push, don't set it's value.

    var copyArray = []; //I assume this line tells it to be an array for (var i = 0; i < postResult.data..length; i++) { copyArray[i] = postResult.data[i]; //arrays do not behave like .Net arrays, you can change length without initializing, so you just set each index to the index of the array you're copying } copyArray.push(variableToAdd); //Do NOT set this as the value of your array, the push method returns an int (length of array) NOT an array! //you probably dont need to call push at all to add to the array as shown in the for loop above if you already know your length or want a specific length

    Then just set your value to the variable, like this

    var entityData = { "variableName": copyArray }; //No need to call Array(copyArray) or any of the prototype. slice stuff. If you call Array() you'll just nest the array a second time.

    Use this page for further info on functions you can do with arrays.

  • 0 Votes
    5 Posts
    167 Views

    These points above are indeed good examples regarding "forcing bad practices":

    If I have 3 free API calls after the API call, after the 3rd freebie, I can return it and call again for 1 core + 3 more that can branch off again. This is inefficient for BC, yet beneficial for end-users (thus, forcing bad practices since it costs and gives more if we avoid the pre and post hooks).

    If a workaround to save API costs would be more work for the user, and costs more for BC, that's a lose-lose. If such a "hole" exists, shouldn't it be repriced for that consideration to make it the win-win you folks want it to be?

  • 0 Votes
    3 Posts
    119 Views

    Hi Reza, a simple workaround I would recommend is using our atomic methods, such as IncrementGlobalStats, to form the field values with the returned value of that method and some other characters you selected. (defined a global statistic ahead of time, call IncrementGlobalStats() get the returned current value of the global statistic, e.g. 123, then combine with the name you selected to a unique name, such as name_123)

  • 2 Votes
    6 Posts
    149 Views

    Well - the new release isn't out yet - it's just a Release Candidate.

    https://github.com/mozilla/rhino/releases

    That said - we are very happy to see the progress - since it has been over a year since 1.7.13 was released!

    Hopefully soon!

  • 0 Votes
    3 Posts
    112 Views
  • 0 Votes
    3 Posts
    126 Views

    Edit . you can get all custom entities for the current user with the query

    { "entityType": "[entitytype]", "ownerId": "[profileId]", "context": { "pagination": { "rowsPerPage": 50, "pageNumber": 1 }, "searchCriteria": { // other search criteria here }, "sortCriteria": { "createdAt": 1 } } }
  • 0 Votes
    5 Posts
    239 Views

    Cheers guys. Thanks for the quick response!

  • 0 Votes
    2 Posts
    231 Views

    Hi,

    Here are the steps to setting up a webhook to call a custom cloud code script in brainCloud:

    Step 1 - Write your script

    Go to Design | Cloud Code | Scripts and create your script You might want to just start with a simple script that logs the incoming parameters (see sample below) Be sure to enable the S2S callable field on the Details page.

    Step 2 - Declare the webhook and link it to your script

    Go to Design | Cloud Code | WebHooks and create your webhook Link it to the script that you just wrote. If you don't see your script in the list, double-check the state of the S2S callable field You can optionally restrict the webhook to be callable via a range of ip ranges (good for additional security) Click [Save] and copy the webhook URL that gets generated

    Step 3 - Go to the external service, and give it your webhook URL

    This step varies by service of course.

    Step 4 - Trigger the webhook to test

    This also varies by service. You could use Postman to do it as well.

    Step 5 - Confirm the structure of the incoming parameters

    It is a bit difficult to figure out what a webhook will send you ahead-of-time The simplest is to invoke the hook, and then examine the results See the sample logging script below for an example Then view the logged input data via Monitoring | Global Monitoring | Recent Errors. Be sure to enable Info -level messages, and click [Refresh]

    Step 6 - Complete the writing of your script

    Now that you know how the parameters are being sent, you should be good to complete your script. More info on webhook development here - https://getbraincloud.com/apidocs/apiref/?cloudcode#cc-ccscripts-webhooks Good luck!

    Sample script - just dumps parameters:

    var response = {}; bridge.logInfoJson("Script invoked from webhook. Contents of data...", data); // Return the webhook response response.statusOverride = 200; response.jsonResponse = {}; response;

    Note - you can also view the request sent and response received from your webhook via the Server Logs. For more information on brainCloud logs - see this knowledge base article.

    Hope that helps!

    Paul.

  • 0 Votes
    2 Posts
    180 Views

    brainCloud's Cloud Code is based on Apache Rhino, which is an open-source implementation of JavaScript. This engine is highly sandboxed within the brainCloud API servers for security purposes.

    brainCloud currently ships with Apache Rhino version 1.7.7.1.

    Rhino implements JavaScript 1.7, and is basically ES4 with partial ES5 and ES6 support.

    Summary from a Stack Overflow discussion here:

    2019-05-27_11-54-35.png

    Hope that helps!

    Paul.