Node-ACl throws uhandled rejection error - javascript

i am using ACL module in my express application.At the start of the server i define some roles and their permissions using the acl.allow() function.
But it logs in a error saying undefined rejection type.The error vanishes on giving a callback with error param.But i am not very sure about what is throwing the error and how it should be handled.
My snippet code which i am using is :
var aclmodule = new acl(new acl.mongodbBackend(config.db.URL, "accesscontrol_"));
aclmodule.allow([
{
roles:['rolea'],
allows:[
{resources:['a','b'], permissions:['*']}
]
},
{
roles:['roleb','rolec'],
allows:[
{resources:['a'], permissions:['view']}
]
},
{
roles:['rolec'],
allows:[
{resources:['o'], permissions:['view','edit']}
]
}
]);
});
The error logged in console is :
Unhandled rejection TypeError: undefined is not a function
at D:\user\web\myapp-web\node_modules\acl\lib\mongodb-backend.js:119:15
at D:\myapp\web\myapp-web\node_modules\acl\node_modules\async\lib\async.
js:607:21
at D:\myapp\web\myapp-web\node_modules\acl\node_modules\async\lib\async.
js:246:17
at iterate (D:\myapp\web\myapp-web\node_modules\acl\node_modules\async\l
ib\async.js:146:13)
at async.eachSeries (D:\myapp\web\myapp-web\node_modules\acl\node_module
s\async\lib\async.js:162:9)
at _asyncMap (D:\myapp\web\myapp-web\node_modules\acl\node_modules\async
\lib\async.js:245:13)
at Object.mapSeries (D:\myapp\web\myapp-web\node_modules\acl\node_module
s\async\lib\async.js:228:23)
at Object.async.series (D:\myapp\web\myapp-web\node_modules\acl\node_mod
ules\async\lib\async.js:605:19)
at Object.MongoDBBackend.end (D:\myapp\web\myapp-web\node_modules\acl\li
b\mongodb-backend.js:35:11)
at Object.tryCatcher (D:\myapp\web\myapp-web\node_modules\acl\node_modul
es\bluebird\js\main\util.js:26:23)
at Object.ret [as endAsync] (eval at (D:\myapp\web\myapp-web
\node_modules\acl\node_modules\bluebird\js\main\promisify.js:163:12),

Is config.db.URL a string? If so, this is the cause of your errors. The line it is failing on is (in mongodb-backend.js):
self.db.collection(... -- it is saying that .collection() is undefined. (Which would make sense if "self.db" were only a string.)
Node-acl expects a database instance when creating a new mongodbBackend, like it says in the docs -- for example:
mongoose.connection.on('connected', function() {
var myAcl = new acl(new acl.mongodbBackend(mongoose.connection.db));
});

Related

Cannnot Load Workbook in SuiteScript 2.0 N/query Module

I'm trying to use the query module in NetSuite's SuiteScript 2.0 API set, learn how it works so we can try to use it to display data too complex for regular scripted/saved searches. I started off by taking a default template and saving it. In the UI it comes up with results without any issues. I've tried testing with the following code:
require(['N/query']);
var query = require('N/query');
var wrkBk = query.load({ id : "custworkbook1" });
However, all I get is the following error:
Uncaught TypeError: Cannot read property '1' of undefined
at loadCondition (N.js?NS_VER=2021.1.0&minver=60&SS_JS_VERSION=1:17469)
at loadCondition (N.js?NS_VER=2021.1.0&minver=60&SS_JS_VERSION=1:17443)
at loadPostProcess (N.js?NS_VER=2021.1.0&minver=60&SS_JS_VERSION=1:17387)
at Object.loadQuery [as load] (N.js?NS_VER=2021.1.0&minver=60&SS_JS_VERSION=1:17299)
at <anonymous>:1:19
Just for kicks, I thought I'd try the asynchronous version, as well, with the following:
require(['N/query']);
var query = require('N/query');
var wrkBk = null;
query.load.promise({
id : "custworkbook1"
}).then(function(result) {
wrkBk = result;
}).catch(function(err) {
console.log("QUERY LOAD PROMISE ERROR\n\n", err);
})
And like before, got a similar error:
QUERY LOAD PROMISE ERROR
TypeError: Cannot read property '1' of undefined
at loadCondition (N.js?NS_VER=2021.1.0&minver=60&SS_JS_VERSION=1:17469)
at loadCondition (N.js?NS_VER=2021.1.0&minver=60&SS_JS_VERSION=1:17443)
at loadPostProcess (N.js?NS_VER=2021.1.0&minver=60&SS_JS_VERSION=1:17387)
at callback (N.js?NS_VER=2021.1.0&minver=60&SS_JS_VERSION=1:17410)
at myCallback (N.js?NS_VER=2021.1.0&minver=60&SS_JS_VERSION=1:2242)
at XMLHttpRequest.C.f.onload (bootstrap.js:477)
If I run the following code, I get results without errors:
query.listTables({ workbookId : "custworkbook1" });
[
{
"name": "Sales (Invoiced)",
"scriptId": "custview2_16188707990428296095"
}
]
Any idea as to what I'm missing?
I think you're loading the module incorrectly, missing the callback. As per the Help Center, it should be something like:
require(['N/query'], function (query)
{
var wrkBk = query.load({ id : "custworkbook1" });
...do stuff with wrkBk
})
Or for SS2.1:
require(['N/query'], (query) => {
let wrkBk = query.load({ id : "custworkbook1" });
...do stuff with wrkBk
})

Not sure how to display this object property in my react app

I tried console.log(response.sql.sql) but it's returning the following error: Unhandled Rejection (TypeError): Cannot read property 'sql' of undefined.
Following is the JSON.stringify of this same object-
{
"sql":{
"external":false,
"sql":[
],
"timeDimensionAlias":"line_items__created_at_day",
"timeDimensionField":"LineItems.createdAt",
"order":{
},
"cacheKeyQueries":{
},
"preAggregations":[
],
"dataSource":"default",
"aliasNameToMember":{
},
"rollupMatchResults":[
],
"canUseTransformedQuery":{
}
}
}
I am assuming the response takes a while so, at the beginning, sql is undefined.
Try to do:
console.log(response && response.sql && response.sql.sql)
try response.data.sql.sql
From my experience, anything in the response, on client-side can be read via response.data object

Asteroid Oauth loginServiceConfiguration: 'google' of undefined

I've followed the 'naive' implementation in the project README: https://github.com/mondora/asteroid-oauth-mixin
The only difference in my code from the example is changing the arrow function to a traditional for the usage of this.
asteroid.ddp.on("added", ({collection, id, fields}: { collection: string; fields: {}, id: string }) => {
if (collection === "meteor_accounts_loginServiceConfiguration") {
asteroid.loginServiceConfiguration = {
...asteroid.loginServiceConfiguration,
[id]: {
_id: id,
...fields
}
};
}
});
});
asteroid.getServiceConfig = function(providerName: string) { // ts file
return this.loginServiceConfiguration[providerName];
}
When I do asteroid.loginWith('google')
index.ts:50 Uncaught TypeError: Cannot read property 'google' of undefined
On the meteor backend I also installed meteor add accounts-base accounts-google because I assume this is a dependency.
What am I missing? Thanks!
I've tried adding DDP.loginServiceConfiguration = {} before the snippet above which resolves the error but creates a new error.
asteroid-oauth-mixin.js:787 Uncaught TypeError: Cannot read property 'clientId' of undefined
at getOauthClientId (asteroid-oauth-mixin.js:787)
at Object.getOptions (asteroid-oauth-mixin.js:720)
at Asteroid.loginWith (asteroid-oauth-mixin.js:104)
at LoginForm../src/routes/accounts/auth/LoginForm.tsx.LoginForm.handleLoginWithGoogle (
Also when I run meteor mongo should db.meteor_accounts_loginServiceConfiguration.find().count() be 0 ?
I needed to meteor add service-configuration and setup my configure-accounts.js and create a google clientId for the application.
This gets me to the point where I have a popup and can choose which user to auth with. Then I receive a new error about target origin mismatch, but I'm going to close this question as resolved.

Meteor: Uncaught Error: Must be attached (delete function)

I have an error in the console every time I'm deleting an item (List) in my Meteor application.
The error in the console is:
domrange.js:337 Uncaught Error: Must be attached
Here is the function, I can't understand where come from this error:
Lists.js
Meteor.methods({
'lists.remove'(listId) {
check(listId, String);
const list = Lists.findOne(listId);
if (list.owner !== this.userId) {
throw new Meteor.Error('not-authorized');
}
Tasks.remove({"listId": listId});
Lists.remove(listId);
},
All is working properly in the application but do you know where this error can come from ?
Ps: I'm using Blaze if it can help
thanks
It seems I found the solution adding a Meteor.isServer or better if (!this.isSimulation) (#MasterAM solution):
'lists.remove'(listId) {
check(listId, String);
const list = Lists.findOne(listId);
if (list.owner !== this.userId) {
throw new Meteor.Error('not-authorized');
}
if (!this.isSimulation) {
Tasks.remove({"listId": listId});
Lists.remove(listId);
}
},
I edited the working code with the help of #MasterAM It'w working now! No Console error anymore.

MeteorJS unexpected behaviour when calling server methods

Some how sequence or delay on server calls brings different behaviour. Code should explain this more clearly.
let editProfile = function (e) {
e.preventDefault();
let info = {};
info.username = $(".editProfile #usernameInput").val();
info.email = $(".editProfile #emailInput").val();
let picture = $(".editProfile #imageInput")[0].files[0];
if (picture) { <-|
Images.insert(picture); |Problem
} |
Meteor.call("editProfile", this, info); <-|
};
this works fine but when I try to change the sequence of these calls I get error in the console.
Meteor.call("editProfile", this, info); <-|
if (picture) { |Error is given
Images.insert(picture); |
} <-|
Error in browser:
Failed to load resource: the server responded with a status of 404 (Not Found)
Error: "Queue" failed [404] Not Found [404] [undefined], Error: failed [404] Not Found [404] [undefined]
at cfs_upload-http.js:351
at cfs_upload-http.js:77
at underscore.js:750
at XMLHttpRequest.xhr.onreadystatechange (cfs_upload-http.js:200)
If I try to do something like this: (no error is given)
Meteor.call("editProfile", this, info);
setTimeout(function () {
if (picture) {
Images.insert(picture);
}
},2000);
I would really like to know why this behaviour is affected by timeouts/sequence.

Categories

Resources