
Security News
vlt Launches "reproduce": A New Tool Challenging the Limits of Package Provenance
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
yodata-client-js
Advanced tools
A JavaScript SDK to provide API access the Yodata.io platform, within a browser based application.
Use this JavaScript library to access the Yodata platform with your browser, node.js, or Meteor based applications. All API calls accept and return JSON objects.
At the moment, the only requirement to use this library is jQuery (tested with v1.11.1) with a browser based app. There are no required modules for node.js or Meteor apps.
yodata.client.js
file to your website file structure.yodata.client.ui.js
file from the yodata-client-ui-js project and follow the instructions to configure the login button.YDClient
object can be accessed through the client UI library's api
property.npm i yodata-client-js
, or add the "yodata-client-js": "0.0.18"
(using the current version number) to the dependencies
node your package.json file and run npm install
.meteor add bshamblen:yodata-client
and hit enter. Please refer to the meteor-yodata-client Github repository for Meteor specific examples.//Make sure you have your login button configured in your HTML with the necessary app client ID and scopes.
var ydClientUi = null;
$(document).ready(function() {
ydClientUi = new YDClientUi();
ydClientUi.onAuthStateChanged(function() {
if(ydClientUi.isAuthenticated()) {
//logged in state, make API calls to populate UI.
ydClientUi.api.userProfile(function(err, results) {
if (err || !results) {
ydClientUi.logout();
} else {
$('#welcomeMessage').html('Welcome <strong>' + results.profile.name + '</strong>');
reloadTasks();
}
});
} else {
//logged out state. Hide UI elements that require login
}
});
}
function reloadTasks() {
var options = {
limit: 100,
sort: {createdAt: -1}
}
ydClientUi.api.find('yodata.task', options , function(err, results) {
if (err) {
//an error occurred
} else {
//Render the task list in the UI
}
});
}
var YDClient = require('yodata-client-js');
//load the auth token from your database, memory, cookies or query string and pass it to the constructor.
var client = new YDClient({ authToken: 'an auth token that was returned by the client side ui library.'});
var options = {
limit: 100,
sort: {createdAt: -1}
}
client.find('yodata.task', options , function(err, results) {
if (err) {
//an error occurred
} else {
//do something with the array of tasks
}
});
The Yodata JavaScript client uses the standard arguments for a JavaScript async callback function. All of your callback functions for each of the methods below should accept both an error and a result object:
function(err, results) {
if (err) {
//handle the error
} else {
//do something with your results
}
}
required scope: POST:modelId
Saves a new document for the currently logged in user.
The results for this call will be the complete, inserted document, including default values for properties that have them defined, the auto generated objectId, createdAt, and modifiedAt values.
var newTask = {
title: 'New task',
priority: 'high'
};
ydClient.api.insert('yodata.task', newTask , function(err, insertedTask) {
if (err) {
//an error occurred
} else {
//do something with the inserted task document
}
});
required scope: PUT:modelId
Updates an existing, complete document for the currently logged in user. You must load the entire document from either a find
, findById
, or findOne
call first, update the poperties you'd like to change, then pass the entire document back to the update
method.
If you are going to use the save
method, you should use documents that have not been populated with related records, or have limited the fields in the response.
Using the save
method will overwrite the entire document with whatever you pass as the doc
parameter.
The results for this call will be the complete, updated document.
//The previouslyLoadedTask variable represents a document loaded from one of the find methods.
previouslyLoadedTask.title = 'New title for existing task';
ydClient.api.save('yodata.task', previouslyLoadedTask , function(err, updatedTask) {
if (err) {
//an error occurred
} else {
//do something with the updated task document
}
});
required scope: PATCH:modelId
Updates part of a document, using the objectId
parameter to indicate which document to update. The modifier
parameter should be an object containing one or more standard update
parameters for a mongodb update
collection method.
For example, if you want to change the firstName
property of a record you would use {$set: { firstName: 'Bob' }}
.
At least one update operator is required, but $isolated
, $bit
and $currentDate
are not supported.
Please see the mongoDB documentation regarding modifying documents for further informaiton.
var modifier = {
$set: {
title: 'Updated Title'
},
$unset: {
notes: ''
}
};
ydClient.api.update('yodata.task', task.objectId, modifier , function(err, updatedTask) {
if (err) {
//an error occurred
} else {
//do something with the updated task document
}
});
required scope: DELETE:modelId
Deletes one or more documents, with the given objectId(s), for the current user. To delete more than one record, you may pass a comma separated list of objectId
s. If no error is returned, the command completed successfully.
ydClient.api.remove('yodata.task', task.objectId, function(err) {
if (err) {
//an error occurred
} else {
//remove was successful
}
});
//or, to delete more than one document in a single call
var listOfObjectIds = ids.join(',');
ydClient.api.remove('yodata.task', listOfObjectIds, function(err) {
if (err) {
//an error occurred
} else {
//remove was successful
}
});
required scope: GET:modelId
Returns exactly one document, with the given criteria, for the current user. The result will be a single object, if found.
The following options are available.
option | description | default |
---|---|---|
criteria | Using the mongoDB syntax to perform a find. | none |
fields | A comma separated list of fields to return in the results, like 'firstName,lastName' . Or, to omit a field, prepend a minus sign to the field name, like 'firstName,lastName,-objectId' | none |
populate | An object that specifies the options to include related data from a referenced model. | none |
sort | The sort order for your results. Use the mongoDb syntax for sorting | { createdAt: -1 } |
var options = {
criteria: {
title: 'test',
priority: 'high'
},
sort: {
modifiedAt: -1
},
fields: 'title,priority',
populate: {
path: 'files',
match: {fileExtension: '.jpg'},
select: 'fileName fileSize',
options: {
limit: 5,
sort: {fileSize: -1}
}
}
}
ydClient.api.findOne('yodata.task', options, function(err, task) {
if (err) {
//an error occurred
} else {
//do something with the task document.
}
});
required scope: GET:modelId
Returns exactly one document, with the given objectId, for the current user. The result will be a single object, if found. An error will be returned if the objectId could not be located for the current user.
The following options are available.
option | description | default |
---|---|---|
fields | A comma separated list of fields to return in the results, like 'firstName,lastName' . Or, to omit a field, prepend a minus sign to the field name, like 'firstName,lastName,-objectId' | none |
populate | An object that specifies the options to include related data from a referenced model. | none |
var options = {
fields: 'title,priority',
populate: {
path: 'files',
match: {fileExtension: '.jpg'},
select: 'fileName fileSize',
options: {
limit: 5,
sort: {fileSize: -1}
}
}
}
ydClient.api.findById('yodata.task', objectId, options, function(err, task) {
if (err) {
//an error occurred
} else {
//do something with the task document.
}
});
required scope: GET:modelId
Returns an array of documents, including metadata for the total number of records that match the given criteria
option, as well as URLs to obtain the first, previous, next, and last page of documents, based on the given offset
and limit
of the current query. The following options are available.
option | description | default |
---|---|---|
criteria | Using the mongoDB syntax to perform a find | none |
limit | The maximum number of records to return | 10 |
offset | The number of records to skip. | 0 |
sort | The sort order for your results. Use the mongoDb syntax for sorting | { createdAt: -1 } |
fields | A comma separated list of fields to return in the results, like 'firstName,lastName' . Or, to omit a field, prepend a minus sign to the field name, like 'firstName,lastName,-objectId' | none |
populate | An object that specifies the options to include related data from a referenced model. | none |
Here's an example of how to sort by a lastName field, in reverse alphabetical order, returning the second set of 100 documents.
var options = {
sort: { lastName: -1 },
limit: 100,
skip: 100
}
ydClient.api.find('yodata.task', options, function(err, results) {
if (err) {
//handle the error
} else {
//do something with the results (array of tasks)
}
});
required scope: GET:modelId
Returns unique values from a collection, based on the given fields
option. For example, if you use the fields
option with a value of lastName
the result set will be a list of unique last names (in no particular order). Sorting must be performed locally, after the results are returned. If you require a sorted list, please use the aggregate
method and use the $sort
aggregation operator in the last stage.
The following options are available.
option | description | default |
---|---|---|
criteria | Using the mongoDB syntax to perform a find. | none |
fields | A comma separated list of fields to return in the results, like 'firstName,lastName' . | none |
populate | An object that specifies the options to include related data from a referenced model. | none |
required scope: GET:modelId
Pass the criteria
option to return the count of records that match the criteria. If no criteria
option is passed, the result will be the total number of documents in the given collection for the current user.
The following options are available.
option | description | default |
---|---|---|
criteria | Using the mongoDB syntax to perform a find. | none |
The following query returns the count of tasks that are not completed. The results
return value is an object with one key, count
. For example, if the number of documents found was 10 the response would be { count: 10 }
.
var options = {
criteria: {
completed: false
}
}
ydClientUi.api.count('yodata.task', options, function(err, results) {
if (err) {
//handle the error
} else {
//do something with the count
console.log(results.count);
}
});
required scope: GET:modelId
Use the pipeline
option to pass an array of mongoDB aggregation stages. The following is an example of how you could query the yodata.tasks
collection to return a sorted list of tags and their count:
var options = {
pipeline: [
{
$unwind: '$tags'
},
{
$group: {
_id: '$tags',
count: {
$sum: 1
}
}
},
{
$sort: {
_id: 1
}
}
]
}
ydClientUi.api.aggregate('yodata.task', options, function(err, tagList) {
if (err) {
//handle the error
} else {
//display the list of tags and their counts...
}
});
required scope: GET:user-profile
Returns the profile of the user or organization associated with the current authentication token.
required scope: POST:files
Allows you to upload a binary file using a multi-part form data post. The result in the callback function is a special file
object, which you can use to reference the file in collection.
required scope: GET:files
Public files have a publicFileUrl
property, which would allow you to access the file directly using an img
tag (if it's an image) or a link. For private files a two step process is used to generate a download token, which can be used to download the file from the download URL. For security reasons the URL that's returned by this function is only valid for 10 minutes.
FAQs
This package is no longer supported and has been deprecated. To avoid malicious use, npm is hanging on to the package name.
The npm package yodata-client-js receives a total of 2 weekly downloads. As such, yodata-client-js popularity was classified as not popular.
We found that yodata-client-js demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
Research
Security News
Socket researchers uncovered a malicious PyPI package exploiting Deezer’s API to enable coordinated music piracy through API abuse and C2 server control.
Research
The Socket Research Team discovered a malicious npm package, '@ton-wallet/create', stealing cryptocurrency wallet keys from developers and users in the TON ecosystem.