How to combine two `hello.init` into one? - javascript

I am trying to use hello.js init API to sign in Microsoft Graph later. The code below is how I am doing now and it works.
repo
However, is there a way to combine these two hello.init into one? Thanks
hello.init({
msft: {
oauth: {
version: 2,
auth: 'https://login.microsoftonline.com/common/oauth2/v2.0/authorize'
},
scope_delim: ' ',
form: false
}
});
hello.init({
msft: myAppId
}, {
redirect_uri: window.location.href
});

I got the answer from the creator of hello.js Andrew Dodson on GitHub.
hello.init ({msft:appid}) is short for hello.init ({msft:{id:appid}})
so you just need to define an id prop on your definition and it'll all
work. Fyi this is undocumented and may change in the future.
So in my case, the solution is
hello.init({
msft: {
id: myAppId,
oauth: {
version: 2,
auth: 'https://login.microsoftonline.com/common/oauth2/v2.0/authorize'
},
scope_delim: ' ',
form: false
},
},
{ redirect_uri: window.location.href }
);

Related

How to use VueGtag to track Google Ads conversions in Vue2 application

I'm trying to use VueGtag to track Google Ads conversions (signups) in Vue2 application.
I've added the following code to main.js:
import VueGtag from 'vue-gtag'
...
Vue.use(VueGtag, {
config: { id: 'AW-123456890AB' }
})
What code should I add to my signup callback function? The documentation is very sparse. Is it something like this?
register() {
...
this.$gtag.event('sign_up')
...
}
You can try the following:
this.$gtag.event('conversion', {
'send_to': 'TAG_ID/CONVERSION_LABEL',
'key': value
})
Make sure you add a config property with the tag id:
Vue.use(VueGtag, {
config: { id: "TAG_ID" },
disableScriptLoad: true
});
Someone asked a similar question in this issue from the 'vue-gtag' package repository.

How do I programmatically set class level permissions in Parse?

According to the Parse Schema Javascript docs, there does not seem to be a way to set classLevelPermission using the JS api. It seems to be possible via the REST api, however. Is there a way to do it with the JS api?
try this in javascript.This is for your reference i did this in angular 6 -
setCLP() {
const httpOptions = {
headers: new HttpHeaders({
'Content-Type': 'application/json',
'X-Parse-Application-Id': enter application id ,
'X-Parse-Master-Key': enter master key
})
};
{
"url": 'your schema url' + 'enter your classname ',
"reqparam":{
"className" : abc,
"classLevelPermissions" :
{
"find": {
'*' : true
},
'*' : true
},
"create": { '*': true },
"update": { '*': false },
"delete": { '*' : true },
}
}
}, httpOptions).toPromise();
console.log(result);
return result;
}
There is no API for setting CLP with the JavaScript SDK, hopefully this is a feature we will see added in the future.
See this issue for a possible workaround.
This is now available in the Parse JS SDK.
setCLP(clp) → {Parse.Schema}
Sets Class Level Permissions when creating / updating a Schema.

How to use search_type from elasticsearch javascript library

I am trying to execute a search query with search_type of count with the elasticsearch.angular.js build from the npm module.
I can execute the query like this:
POST /index1/type1/_search?search_type=count
{
"aggs": {
"reviews": {
"nested": {
"path": "reviews"
}
}
}
}
but when I try to translate the query to the .js api, I get an error. My code looks like this:
var requestObject = {
index:'index1',
type:'type1',
searchType: 'count',
body: {
query:{
aggs: {
reviews: {
nested: {
path: "reviews"
}
}
}
}
};
esClient.search(requestObject)
The trace looks like this:
console.js:1 DEBUG: 2015-08-04T15:28:59Z
starting request { method: 'POST',
path: '/index1/type1/_search',
body: { aggs: { reviews: [Object] } },
query: { search_type: 'count' } }
That looks OK to an elasticsearch newbie, but the request completes with an error: ReferenceError: count is not defined.
What am I missing here please?
It turned out that my problem was a stupid error on my part (thanks #robertklep for pointing it out). The code above actually works correctly. As I was not able to find an example of using using searchType from the api, I am leaving this here in the hope it will be useful to somebody else.

How can I retrieve,add data using Quickbase API and javascript

I am very new to Quickbase.
I want to query the quickbase using javascript to get a table records and also insert to it.
How should I do this?
Any help is highly appreciated.
To improve #rtpHarry's answer, the JavaScript SDK he is referencing has seen better days. It hasn't been updated in 2 years, and doesn't work in IE11.
Now this is a shameless plug, full disclosure, I am the author of this module;
But Node-QuickBase is much, much easier to use and works both in the browser and on the server - no code change.
Here is an example:
Within Nodejs:
var QuickBase = require('quickbase');
var quickbase = new QuickBase({
realm: 'www',
appToken: '*****'
});
quickbase.api('API_Authenticate', {
username: '*****',
password: '*****'
}).then(function(result){
return quickbase.api('API_DoQuery', {
dbid: '*****',
clist: '3.12',
options: 'num-5'
}).then(function(result){
return result.table.records;
});
}).map(function(record){
return quickbase.api('API_EditRecord', {
dbid: '*****',
rid: record[3],
fields: [
{ fid: 12, value: record[12] }
]
});
}).then(function(){
return quickbase.api('API_DoQuery', {
dbid: '*****',
clist: '3.12',
options: 'num-5'
});
}).then(function(result){
console.log(result);
}).catch(function(err){
console.error(err);
});
Within the Browser:
<script type="text/javascript" src="quickbase.browserify.min.js"></script>
<script type="text/javascript">
var quickbase = new QuickBase({
realm: 'www',
appToken: '*****'
});
quickbase.api('API_Authenticate', {
username: '*****',
password: '*****'
}).then(function(result){
return quickbase.api('API_DoQuery', {
dbid: '*****',
clist: '3.12',
options: 'num-5'
}).then(function(result){
return result.table.records;
});
}).map(function(record){
return quickbase.api('API_EditRecord', {
dbid: '*****',
rid: record[3],
fields: [
{ fid: 12, value: record[12] }
]
});
}).then(function(){
return quickbase.api('API_DoQuery', {
dbid: '*****',
clist: '3.12',
options: 'num-5'
});
}).then(function(result){
console.log(result);
}).catch(function(err){
console.error(err);
});
</script>
Before you begin you need to set up a user in QuickBase.
In order for you to use the API you need to have a developer key.
There is a JavaScript SDK that you can use which is available on GitHub. This will shield you from the details of the API.
However, this doesn't let you use this inside any random webpage if that's what you're attempting:
HTML pages using QuickBaseClient.js must be hosted within QuickBase
applications as file attachments or as text (code) pages because web
browsers only allow JavaScript code to access the web site the
JavaScript originated from.
If you do want do that then there are workarounds.

Name of Azure blob/filename when uploading

When I upload to azure container the filename that is saved is the uuid(guid) how can I change that?
I create the signatur by using the querystring "bloburi" added in the signature request.
$("#fine-uploader").fineUploaderAzure({
autoUpload : true,
debug: true,
validation: {
itemLimit: 10,
sizeLimit: 209715200 // 200 mb
},
resume: {
enabled: true,
id: 'ResumeUpload',
cookiesExpireIn: 7
},
extraButtons: {
folders: true
},
deleteFile: {
enabled: true
},
request: {
endpoint: 'https://xxx.blob.core.windows.net/'
},
cors: {
//all requests are expected to be cross-domain requests
expected: true,
//if you want cookies to be sent along with the request
sendCredentials: true
},
signature: {
endpoint: '/sig/'
},
uploadSuccess: {
endpoint: '/success'
}
});
The docs are wrong.
For version 4.4.0 the correct property to set is:blobProperties
// 'uuid', 'filename', or a function which may be promissory
blobProperties: {
name: "uuid"
},
I know this is an old question, but I ran into the same problem. You'll need to pass a Promise to get it to work:
name: function (id) {
return new Promise(function (resolve) {
resolve("The String You Want to Pass");
});
}
The default value for the name option is 'uuid' which will set the filename in Azure to the uuid. You can instead set it to 'filename' to have the object stored under the filename, or provide a function that will create some other name.
blobProperties: {
name: 'filename'
}
From my experience, the best method for generating filenames is to save the filename under a unique id subfolder. This guarantees that you save the original filename, and that there are no naming collisions.
blobProperties: {
name: function(id) {
var uuid = this.getUuid(id),
filename = this.getName(id);
return uuid + '/' + filename;
}
}

Categories

Resources