skygeario / skygear-sdk-js Goto Github PK
View Code? Open in Web Editor NEWSkygear SDK for JavaScript
Home Page: https://docs.skygear.io/guides/quickstart/js/
License: Other
Skygear SDK for JavaScript
Home Page: https://docs.skygear.io/guides/quickstart/js/
License: Other
Follow the example in Skygear JS SDK documentation.
const unFollow = new skygear.relation.Follower([ben]);
skygear.relation.remove(unFollow).then((result) => {
console.log(result.success); // Return an array of user, here is [ben]
}, (error) => {
console.error(error);
});
It will throw an exception, TypeError: Cannot read property 'user_id' of undefined
.
This exception is due to the fact that JS SDK expects Skygear server returns a list of users whose relation is successfully removed in result.data
. However, the server does not return that field currently.
No exception when removing a relation
Throw an exeception
Current skygear.publicDB.save
assuming the input is a Record Object. So the user need to fetch the remote record or construct a new Record(with correct ACL), even it have the key and just want to update one attribute.
skygear.publicDB.query(Note)
returns a Record
with an Object in a referenced field. It should returns a Reference
instead of an Object.
When _id
is included as a property of the attrs
of Record
constructor, it is expected to be a typed id, i.e. my_table_name/some-id
After the record instance is constructed, _id
is typeless id, i.e. some-id
.
It is very confusing. It would be better to support id
as one of the property of attrs
which is interpreted as typed id. The new constructor must issue deprecation warning for users who still use _id
for the constructor. Then _id
will always mean typeless id.
const Note = skygear.Record.extend('note');
const noteRecord = new Note({
_id: 'note/1',
});
console.log(noteRecord._id); // this logs "1"
For browsers which don't support local storage, for example safari private mode.
http://sdkjsexample.skygeario.com/static/example/record.html
Give something looks "normal"
using skygear.Location
will be better than using skygear.Geolocation
because geolocation refers to the detection of the user's location, while skygear does not provide such feature.
According to the docs https://docs.skygear.io/js/guide/query#pagination-ordering, under the sub-section Counting the records,
To get the number of records matching a query, set the overallCount of the Query to true.
However, by real experiment, there was nothing at the second arguments of the success callback, e.g.:
query.overallCount = true;
skygear.publicDB.query(query).then(function(records, overallCount) {
console.log('overallCount: ', overallCount);
});
it yields:
overallCount: undefined
When using batch atomic save functions, some framework like react.js would pollute the array, which intervene the skygear function.
We should clean it up for popular framework (react.js, Jquery, vue.js, angular.js)
skygear.pubsub.publish('ping', null)
skygear.pubsub.publish('ping', undefined)
Any of the above two lines of code would crash pubsub and immediately close the socket connection.
According to the docs https://docs.skygear.io/js/guide/query#pagination-ordering, we can perform a query with paginated results by specifying either query.page
or query.offset
.
However, by real experiment, only offset
worked; page
never worked. We are pretty sure we didn't specifying both of them at the same time.
By a quick search at the code here: https://github.com/SkygearIO/skygear-SDK-JS/blob/master/lib/query.js#L38 (Not sure whether I am looking at the correct file ๐ป )
I guess only the preference offset
is effective; page
is ignored.
Though, such issue does not bother our development much as we can still use .offset
in this way:
query.offset = limit * (page - 1)
After skygear.saveUser
successfully changed email for the current user, skygear.currentUser.email
is still the old one.
Even in simple html5 app, we will want to check the error code. Currently the error code only available via node module require.
Follow up #62 (comment)
We can provide a helper and example usage in doc.
Even when roles are associated in _user_role
database, user
object in skygear.currentUser
or skygear.getUsersByEmail
have user.roles
being an empty array []
.
We have skygear.getUsersByEmail([ ... ])
, then why not skygear.getUsersByUsername([ ... ])
?
The Skygear API Key is made public in all the examples pages
Make the configuration of end point to be an text input.
To pay safe, skygear.on() should first check whether the handler exists in the handler list before adding it to the list.
To Update:
let query = new skygear.Query(Note);
query.equalTo('_id', '123456...');
skygear.publicDB.query(query)
.then((records) => {
let note = records[0];
note['content'] = 'Hello New World';
return skygear.publicDB.save(note);
}).then(...);
To Delete:
skygear.publicDB.delete({
'id': 'note/123456...'
}).then(...);
It is confusing that Update API uses _id
but delete API uses id
. Also, if I try to use id
for update, then there is 500 internal server error saying column note.id
does not exist; if I try to use _id
for delete, there is 400 bad request error saying _id
should be of format '{type}/{id}' got "".
I think it would be quite convenient to automatically fetch the user profile every time when user signs up or logs in.
Frederick Lam, [29 Jun 2016, 2:08 AM]:
if (latitude < -90 || latitude > 90) {
throw new Error('Latitude is not in expected range (-90, 90)');
}
if (!_lodash2['default'].isNumber(longitude)) {
throw new Error('Longitude is not a number');
}
if (longitude < -180 || latitude > 180) {
throw new Error('Longitude is not in expected range (-180, 180)');
}
should be if (longitude < -180 || longitude > 180) thanks.
it will throw exception if no permission to delete the record.
Also, suggest the record (like conversation) can be delete if the user is admin. (now only owner can delete)
The form submission event in src/components/Main.js
, when you press the signup button, it will call doLogin() function.
const attachment = new skygear.Asset({
name: value.file.name,
file: value.file
});
Portal Assets Setting:
ASSET_STORE_PUBLIC: YES
With value.file.name containing a space, I will get 403 (Forbidden) from amazon s3.
https://s3-us-west-2.amazonaws.com/skygear-cloud-asset/landingpagegentest/3607751b-219a-4046-97f3-2bdbd0cbe748-sf%20%281%29.jpeg 403 (Forbidden)
TypeError: Cannot read property '_presaveAssetTask' of undefined
Same as getUsersByEmail
, intended for admin query.
We need to construct a query for that purpose now
We upload an image file to server using JS SDK, to our own table news_stress_image
, which has a column photo
referencing the table _asset
. Then we queried the table news_stress_image
and wanted to get the (publicly accessible) image url.
The raw json result from the SDK's web service is captured:
{
"result": [
{
"_access": [
{
"level": "read",
"public": true
}
],
"_created_at": "2016-08-09T07:57:35.219725Z",
"_created_by": "22de813c-b277-4e72-99a6-c514a8bc8e6a",
"_id": "news_stress_image/71fb8c6a-31c2-4f1b-bab8-0d98c511a4b7",
"_ownerID": "22de813c-b277-4e72-99a6-c514a8bc8e6a",
"_type": "record",
"_updated_at": "2016-08-09T07:57:35.219725Z",
"_updated_by": "22de813c-b277-4e72-99a6-c514a8bc8e6a",
"news_stress_id": {
"$id": "news_stress/fdbb4b77-0030-446c-979c-4d51fec65dfd",
"$type": "ref"
},
"photo": {
"$name": "180180b3-eb17-4a0c-8309-97da9444e677-news-stress-image",
"$type": "asset",
"$url": "https://s3-ap-northeast-1.amazonaws.com/cloudpillar-sky-test/180180b3-eb17-4a0c-8309-97da9444e677-news-stress-image"
}
},
...
]
}
The returned url at record.photo.url
-- https://s3-ap-northeast-1.amazonaws.com/cloudpillar-sky-test/180180b3-eb17-4a0c-8309-97da9444e677-news-stress-image -- does not works. An error xml string stating "Access Denied" is returned.
From docs https://docs.skygear.io/js/guide/asset, we saw in the comment:
// if configured properly, the url should look like the following
// <ASSET_STORE_URL_PREFIX>/<asset-id>-<your-asset-name>
Then logging into Skygear Developer Portal and we saw that the environment variable ASSET_STORE_URL_PREFIX
is having value https://skygearprototype.staging.skygeario.com/files
. Thus the url https://skygearprototype.staging.skygeario.com/files/180180b3-eb17-4a0c-8309-97da9444e677-news-stress-image works actually but wasn't returned from SDK.
Would please advise whether there are some mistakes in our environment variables?
Was inspired by this commit: oursky/doorlock@ba23e99
The developer in the above commit has to explicitly re-subscribe to a channel onConnectionClose()
The SDK maybe should have a default retry value and / or infinity by default?
The error list in JS SDK: 274fbec#diff-b83d27d3c5374e6d6de83271284db8c4R16
The error list in skygear-server https://github.com/SkygearIO/skygear-server/blob/2fa211c93e4b0a70acf2ecaa42fef511cfa430ca/skyerr/skyerr.go#L35
Duplicated
and ResourceNotFound
. So all subsequent error codes are shifted by one.RecordQueryInvalid
has been added to server side but not in the JS SDKCurrently formJSON() of asset has url, but toJSON() remove the url. So a deserialize asset cannot be serialized to its original form.
Console error message:
Unhandled promise rejectionTypeError: Object doesn't support property or method 'from'
The section about classes in https://babeljs.io/docs/usage/caveats/
The class QueryResult extends Array
in lib/query_result.js
, and it uses the static method Array.from
through QueryResult.from
http://babeljs.io/docs/plugins/transform-proto-to-assign/
Open any website written with skygear JS SDK on IE10. When there is a query, the error message will appear
Users can change their email by calling skygear.saveUser
. Why can't they change their username?
While skygear SDK provide auto reconnect for Websocket connection, and it works if the application code is receiving the onClose
event from the network stack. But in real life JS implementation, waiting network time out is not useful and too long.
Like what skygear-SDK-iOS: https://github.com/SkygearIO/skygear-SDK-iOS/blob/master/Pod/Classes/SKYPubsub.m#L52 Ping/Pong will be more desired. It make the TCP connect more active and promote the disconnect event faster to application level. Since JS in browser will not expose such low level API (refs: https://html.spec.whatwg.org/multipage/comms.html#ping-and-pong-frames) We may want to implement an application level Ping/Pong.
Refs: https://github.com/oursky/doorlock/blob/master/daemon-trigger-skygear/index.js
Above implementation of heartbeat is battle test and proved to be reliable.
Unexpected clear of user roles during update of email.
user.roles
keep as it. Don't clear the the user roles if no role is provided.
According to https://docs.skygear.io/js/guide/users/, the purpose of the function skygear.saveUser is to update (current) user's email.
But by real experience I found that it also modified the user's role setting (which actually removed all records in table _user_role, of my current user).
skygear.saveUser({
id: skygear.currentUser.id,
email: '[email protected]',
}).then((user) => {
console.log(user.roles);// It become empty array
}, (error) => {
console.error(error);
});
require('skygear');
will result error.
It works with in process memory storage
Error: Cannot find module 'localStorage'`
Step to reproduce the error:
npm install -g react-native-cli
react-native init BuggyProject
(takes 5 minutes)package.json
to include "skygear": "github:bensonby/skygear-SDK-JS-1#0.14-test-custom-build"
inside dependencies
npm install
index.ios.js
to have import skygear from 'skygear'
in the first line of codereact-native run-ios
transformed 681/682 (100%)[node-haste] Encountered an error while persisting cache:
> ReferenceError: Unknown plugin "add-module-exports" specified in "/Users/lijiahang/Developer/oursky/BuggyProject/node_modules/localforage/.babelrc" at 0, attempted to resolve relative to "/Users/lijiahang/Developer/oursky/BuggyProject/node_modules/localforage"
> at /Users/lijiahang/Developer/oursky/BuggyProject/node_modules/babel-core/lib/transformation/file/options/option-manager.js:177:17
> at Array.map (native)
> at Function.normalisePlugins (/Users/lijiahang/Developer/oursky/BuggyProject/node_modules/babel-core/lib/transformation/file/options/option-manager.js:153:20)
> at OptionManager.mergeOptions (/Users/lijiahang/Developer/oursky/BuggyProject/node_modules/babel-core/lib/transformation/file/options/option-manager.js:245:36)
> at OptionManager.init (/Users/lijiahang/Developer/oursky/BuggyProject/node_modules/babel-core/lib/transformation/file/options/option-manager.js:360:12)
> at File.initOptions (/Users/lijiahang/Developer/oursky/BuggyProject/node_modules/babel-core/lib/transformation/file/index.js:223:65)
> at new File (/Users/lijiahang/Developer/oursky/BuggyProject/node_modules/babel-core/lib/transformation/file/index.js:140:24)
> at Pipeline.transform (/Users/lijiahang/Developer/oursky/BuggyProject/node_modules/babel-core/lib/transformation/pipeline.js:46:16)
> at transform (/Users/lijiahang/Developer/oursky/BuggyProject/node_modules/react-native/packager/transformer.js:108:26)
> TransformError: /Users/lijiahang/Developer/oursky/BuggyProject/node_modules/localforage/dist/localforage.js: Unknown plugin "add-module-exports" specified in "/Users/lijiahang/Developer/oursky/BuggyProject/node_modules/localforage/.babelrc" at 0, attempted to resolve relative to "/Users/lijiahang/Developer/oursky/BuggyProject/node_modules/localforage"
Localforage github repo has talked about installing additional dependencies for build systems, so I proceeded with installing the following (please also take a look at their .babelrc
file):
npm install --save-dev babel-plugin-system-import-transformer
npm install --save-dev babel-plugin-add-module-exports
npm install --save-dev babel-preset-es2015
npm install --save-dev babel-preset-es2015-loose
react-native run-ios
cannot retrieve own user record after the password is changed. 401 is returned, see example.
authtoken is expired error is raised.
skygear.changePassword(currentPassword, password).then((newAuth) =>{
let query = new skygear.Query( new skygear.Record.extend('user'));
query.equalTo('_id', skygear.currentUser.id);
//newAuth == skygear.accessToken => true
return skygear.publicDB.query(query);
}).then(() => {
//can't get into here
}, (err) =>{
//error here is 401
})
In some environments (e.g. react-native on android , spec compliant browsers ) there is a limit on the storage. The SDK does not has an option for user to opt-out for caching.
This results in the limit of the storage being exceeded and causing the database to fail every time a write operation is issued. The implementation of database does not handle this case.
For the users who are suffering from the problem, they need to purge the cache of skygear at the very beginning of their app lifecycle to ensure that they have a functioning storage to work with.
A proper solution to this issue is to allow user to opt-out cache at all and introduce a policy to purge the cache when limit exceeded.
Currently it will just say "TypeError: Cannot read property 'toJSON' of undefined, a proper error message should make it easier for debug.
Record is not currently copy constructible because of #72
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.