[New Feature] Server side actions now support node modules

I think the issue with my specific example is forcing the datatype there (obviously Response is not defined as a null, so there’s some typecasting that has to be done – it seems this is bad to do).

The thing I’m wondering right now is this:

Let us say that we let the user pass us a “list of any data type”. How do we tell if that list is (1) a list of complex objects with fields or (2) a list of primitives. I literally, actually cannot figure it out.

Surely one of the more experienced plugin wranglers here knows the correct/fastest/most performant way to tell this.

(I can’t come up with a single boolean expression that will evaluate false for one and true for the other… but I suck at some JavaScript stuff. Every time I think “ah, I have the solution!” the expression throws an error. So I just keep thrashing on this and thrashing is bad…)

Aside: Some basic documentation-by-example on stuff like this would go a long way, @Bubble! I’m SURE there’s a proscribed way to do that check. Just tell us the correct way! Gah.

1 Like

@marca: the problem of click/unclick “uses node modules” results in multiple dependencies input fields is back…

1 Like

After a few hours I remain confused. If the use node modules only looks for dependencies in the package where are the modules placed? Can you link to npm somehow or how is this done? When I run the workflow it is (obviously) failing with error cannot find /xxxxx module which is required inside of the function.

We do not care where the modules are placed. They come from NPM and they magically wind up in our deployment package.

Basically what this is doing is just like how webtask.io does it (though they have a nifty search interface). You basically are just saying, “Oh hai, I want moment-timezone.” And so you do:

{
“dependencies”: {
“moment-timezone”: “latest”
}
}

In the “Add your custom package…” field.

Now, apparently you can add non-NPM stuff as NPM’s package.json docs tell us that we can get stuff from a Git URL or from an NPM package at some remote URL that’s in a tar archive, etc.

I’ve not gotten any of that to work, but then I don’t use NPM on the command line and so am not really into creating packages and stuff. I mistakenly thought in one thing I was trying to do that I needed to somehow get a certain .js file bundled into my deployment package, but it turned out that wasn’t the case and so I’ve not messed around with other methods.

If you’re new or new-ish to this, basically what you do is “see something on NPM, copy its name, drop that in the JSON area”. Click the build package link. DONE!

('Course, now you have to do the rest of any install / require stuff in your action code, but again, just follow the instructions.)

4 Likes

How timely - I just in the last five minutes figured how to add .tgz URL as a dependency and the build succeeded. Good time. Thanks for your reply!

1 Like

See, you are way more advanced than me!

:grin:

Is it possible to return XML instead on JSON and have Bubble still render the results? Appears it only plays well with JSON

Read docs: https://docs.npmjs.com/files/package.json … is all I can say. ?

1 Like

Hi @keith. Welp… I have it returning JSON so that’s out of the way…

Next issue goes like this - would love to hear your thoughts…

The function builder wants function(properties, context) and I’m having trouble presenting what bubble wants to see.

All of the “RETURNED VALUES” above are set corresponding with what the object returns.

The dependencies are loaded and the code works on npm.runkit.com

However - when I test it returns 200 with an empty object.

When I click the “show documentation” thingy on the editor it says:

Properties: Empty object as you haven’t defined any fields for this action.

When I attempt to add the fields that are in the returned object as it suggests it grumbles about not proper javaScript.

{
value1: string
value2: string
}

…Is what it suggests.

In the run_server code box I have something like…

function(properties, context) {

var thishere = require(‘thisthere’)(‘key1’,‘key2’);

thishere.orders.search({
‘Action’: ‘ListOrders’
});
}

I have tried every which way I can imagine to add in and include:

{
value1: string
value2: string
}

But it says not valid javascript. And here I thought I knew Javascript pretty alright. Guess no so much, huh.

Apparently adding the expected returned values is not good enough and these pairs have to be included in order to not get an empty response.

Thoughts?

Maybe I’m not totally understanding the issue you’re having here, but I think it’s that you’re not seeing any returned values from the script?

Ignoring npm for a moment, are you able to successfully return a test object? If not, this is the syntax for that (and sorry it this is totally basic and not the problem that you’re having :roll_eyes:):

If you’re already here, or can get the above to work fine then it’s something a little messier upstream within your npm package, or more likely the way that you are calling it.

1 Like

@elledarrow, I don’t know if this is the issue, but syntax-wise, there should be a comma separating each key-value pair.

1 Like

Yeah, that may be what @elledarrow is missing. I know that in the “documentation” pop up, the “return value” structure is shown without commas, but that’s not valid JSON. To generalize a bit, you want:

{
  value1: the_string_to_return1,
  value2: the_string_to_return2,
  some_other_key: some_other_value_to_return
}

Also, @exception-rambler’s suggestion is the best first step: Just build a minimal function that simply takes in a value from a field in the plugin and returns it to you. Once you’ve got that going…

-K-

Thanks for the reply @exception-rambler. Something simple like your example works. The npm package works and the way I am calling it works - on npm.runkit.com anyways.

The {value1:string} issue described above is resolved I had it narrowed down to Bubble not liking describing a data type as “List of Strings” - even though that’s the suggested format on the example when the list check box is marked.

When I run the plugin it returns 200 - it just still has an empty response.

As well, even though I have the return values set - the editor still says “properties”:empty object etc. "

Very odd.

Happy to be a second pair of eyes on it if you want to add me as a collaborator: ed@wedgehog.io

That is a generous offer, @exception-rambler - it looks like I need to upgrade my Bubble account to add a collaborator. Standby.

I might be wrong, but I think that’s true of apps but not plugins.
You’ll find it at the bottom of your plugin Settings tab.

1 Like

@keith An update regarding speed: we’re aware that server side actions are a lot slower than they ought to be, and will be putting some effort into rectifying this situation. If anyone has any particular comments/complaints/observations on this front, please direct them my way.

4 Likes

I’m PM-ing you a video with some details that you might find helpful. Thank so much, @marca. I also have bug report filed re: this.