Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

kinvey-js-sdk

Package Overview
Dependencies
Maintainers
1
Versions
108
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

kinvey-js-sdk - npm Package Compare versions

Comparing version 4.0.0 to 4.1.0

lib/datastore/autostore.d.ts

2

lib/datastore/cache.d.ts
import { Storage, Entity } from '../storage';
import { Query } from '../query';
export declare function isValidTag(tag: string): boolean;

@@ -15,3 +14,2 @@ export declare class DataStoreCache<T extends Entity> extends Storage<T> {

constructor(tag?: string);
serializeQuery(query?: Query): string;
}

@@ -18,0 +16,0 @@ export declare enum SyncEvent {

Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var isString_1 = tslib_1.__importDefault(require("lodash/isString"));
var isEmpty_1 = tslib_1.__importDefault(require("lodash/isEmpty"));
var storage_1 = require("../storage");

@@ -40,12 +39,2 @@ var kinvey_1 = require("../kinvey");

}
QueryCache.prototype.serializeQuery = function (query) {
if (!query) {
return '';
}
if ((query.skip && query.skip > 0) || (query.limit && query.limit < Number.MAX_SAFE_INTEGER)) {
return null;
}
var queryObject = query.toQueryObject();
return queryObject && !isEmpty_1.default(queryObject) ? JSON.stringify(queryObject) : '';
};
return QueryCache;

@@ -52,0 +41,0 @@ }(DataStoreCache));

@@ -392,8 +392,10 @@ Object.defineProperty(exports, "__esModule", { value: true });

CacheStore.prototype.pull = function (query, options) {
if (query === void 0) { query = new query_1.Query(); }
if (options === void 0) { options = {}; }
return tslib_1.__awaiter(this, void 0, void 0, function () {
var network, cache, queryCache, useDeltaSet, useAutoPagination, queryKey, findQueryCacheQuery, queryCacheDocs, queryCacheDoc, count, queryObject, url, request, response_1, _a, changed, deleted, removeQuery, headers_1, error_5, response_2, count_1, pageSize_1, pageCount, pageQueries, pagePromises, pageCounts, totalPageCount, headers_2, response, docs, headers;
var pullQuery, network, cache, queryCache, useDeltaSet, useAutoPagination, queryCacheDocs, queryCacheDoc, count, queryObject, url, request, response_1, _a, changed, deleted, removeQuery, headers_1, error_5, response_2, count_1, pageSize_1, pageCount, pageQueries, pagePromises, pageCounts, totalPageCount, headers_2, response, docs, headers;
return tslib_1.__generator(this, function (_b) {
switch (_b.label) {
case 0:
pullQuery = new query_1.Query({ filter: query.filter });
network = new networkstore_1.NetworkStore(this.collectionName);

@@ -404,8 +406,6 @@ cache = new cache_1.DataStoreCache(this.collectionName, this.tag);

useAutoPagination = options.useAutoPagination === true || options.autoPagination || this.useAutoPagination;
queryKey = queryCache.serializeQuery(query);
findQueryCacheQuery = new query_1.Query().equalTo('query', queryKey).equalTo('collectionName', this.collectionName);
return [4 /*yield*/, queryCache.find(findQueryCacheQuery)];
return [4 /*yield*/, queryCache.find(new query_1.Query().equalTo('query', pullQuery.key).equalTo('collectionName', this.collectionName))];
case 1:
queryCacheDocs = _b.sent();
queryCacheDoc = queryCacheDocs.shift() || { collectionName: this.collectionName, query: queryKey, lastRequest: null };
queryCacheDoc = queryCacheDocs.shift() || { collectionName: this.collectionName, query: pullQuery.key, lastRequest: null };
return [4 /*yield*/, this.pendingSyncCount()];

@@ -427,10 +427,7 @@ case 2:

}
if (!(useDeltaSet && queryCacheDoc && queryCacheDoc.lastRequest)) return [3 /*break*/, 11];
if (!(useDeltaSet && queryCacheDoc.lastRequest)) return [3 /*break*/, 11];
_b.label = 3;
case 3:
_b.trys.push([3, 10, , 11]);
queryObject = { since: queryCacheDoc.lastRequest };
if (query) {
queryObject = Object.assign({}, query.toQueryObject(), queryObject);
}
queryObject = Object.assign({ since: queryCacheDoc.lastRequest }, pullQuery.toQueryObject());
url = http_1.formatKinveyBaasUrl(http_1.KinveyBaasNamespace.AppData, "/" + this.collectionName + "/_deltaset", queryObject);

@@ -475,3 +472,3 @@ request = new http_1.KinveyHttpRequest({ method: http_1.HttpRequestMethod.GET, auth: http_1.KinveyHttpAuth.Session, url: url });

_b.sent();
return [4 /*yield*/, network.count(query, Object.assign({}, options, { rawResponse: true })).toPromise()];
return [4 /*yield*/, network.count(pullQuery, Object.assign({}, options, { rawResponse: true })).toPromise()];
case 13:

@@ -483,3 +480,3 @@ response_2 = _b.sent();

pageQueries = times_1.default(pageCount, function (i) {
var pageQuery = new query_1.Query(query);
var pageQuery = new query_1.Query(pullQuery);
pageQuery.skip = i * pageSize_1;

@@ -505,8 +502,8 @@ pageQuery.limit = Math.min(count_1 - (i * pageSize_1), pageSize_1);

return [2 /*return*/, totalPageCount];
case 16: return [4 /*yield*/, network.find(query, Object.assign({}, options, { rawResponse: true })).toPromise()];
case 16: return [4 /*yield*/, network.find(pullQuery, Object.assign({}, options, { rawResponse: true })).toPromise()];
case 17:
response = _b.sent();
docs = response.data;
if (!query) return [3 /*break*/, 19];
return [4 /*yield*/, cache.remove(query)];
if (!pullQuery) return [3 /*break*/, 19];
return [4 /*yield*/, cache.remove(pullQuery)];
case 18:

@@ -513,0 +510,0 @@ _b.sent();

export declare enum DataStoreType {
Auto = "Auto",
Cache = "Cache",

@@ -3,0 +4,0 @@ Network = "Network",

@@ -5,2 +5,3 @@ Object.defineProperty(exports, "__esModule", { value: true });

var kinvey_1 = require("../errors/kinvey");
var log_1 = require("../log");
var cache_1 = require("./cache");

@@ -10,4 +11,6 @@ var networkstore_1 = require("./networkstore");

var cache_2 = require("./cache");
var autostore_1 = require("./autostore");
var DataStoreType;
(function (DataStoreType) {
DataStoreType["Auto"] = "Auto";
DataStoreType["Cache"] = "Cache";

@@ -29,3 +32,10 @@ DataStoreType["Network"] = "Network";

}
if (type === DataStoreType.Network) {
if (type === DataStoreType.Auto) {
datastore = new autostore_1.AutoStore(collectionName, Object.assign({}, options, { autoSync: true }));
}
else if (type === DataStoreType.Cache) {
log_1.logger.warn('DataStoreType.Cache will be deprecated soon. Please use DataStoreType.Auto instead.');
datastore = new cachestore_1.CacheStore(collectionName, Object.assign({}, options, { autoSync: true }));
}
else if (type === DataStoreType.Network) {
if (tagWasPassed) {

@@ -36,5 +46,2 @@ throw new kinvey_1.KinveyError('The tagged option is not valid for data stores of type "Network"');

}
else if (type === DataStoreType.Cache) {
datastore = new cachestore_1.CacheStore(collectionName, Object.assign({}, options, { autoSync: true }));
}
else if (type === DataStoreType.Sync) {

@@ -44,3 +51,3 @@ datastore = new cachestore_1.CacheStore(collectionName, Object.assign({}, options, { autoSync: false }));

else {
throw new Error('Unknown data store type.');
throw new kinvey_1.KinveyError('Unknown data store type.');
}

@@ -47,0 +54,0 @@ return datastore;

@@ -20,3 +20,3 @@ import { Aggregation } from '../aggregation';

save(doc: any, options?: any): Promise<any>;
remove(query?: Query, options?: any): Promise<any>;
remove(query: Query, options?: any): Promise<any>;
removeById(id: string, options?: any): Promise<any>;

@@ -23,0 +23,0 @@ subscribe(receiver: LiveServiceReceiver, options?: any): Promise<boolean>;

@@ -286,7 +286,10 @@ Object.defineProperty(exports, "__esModule", { value: true });

case 0:
if (query && !(query instanceof query_1.Query)) {
if (!query) {
throw new kinvey_1.KinveyError('A query must be provided to remove entities.');
}
if (!(query instanceof query_1.Query)) {
throw new kinvey_1.KinveyError('Invalid query. It must be an instance of the Query class.');
}
_a = options.rawResponse, rawResponse = _a === void 0 ? false : _a, timeout = options.timeout, properties = options.properties, trace = options.trace, skipBL = options.skipBL;
queryObject = Object.assign({}, query ? query.toQueryObject() : {}, {});
queryObject = Object.assign({}, query ? query.toQueryObject() : {});
url = http_1.formatKinveyBaasUrl(http_1.KinveyBaasNamespace.AppData, this.pathname, queryObject);

@@ -293,0 +296,0 @@ request = createRequest(http_1.HttpRequestMethod.DELETE, url);

@@ -26,3 +26,3 @@ export * from './activeUser';

export * from './mobileIdentityConnect';
export * from './networkConnection';
export * from './network';
export * from './noActiveUser';

@@ -29,0 +29,0 @@ export * from './noResponse';

@@ -28,3 +28,3 @@ Object.defineProperty(exports, "__esModule", { value: true });

tslib_1.__exportStar(require("./mobileIdentityConnect"), exports);
tslib_1.__exportStar(require("./networkConnection"), exports);
tslib_1.__exportStar(require("./network"), exports);
tslib_1.__exportStar(require("./noActiveUser"), exports);

@@ -31,0 +31,0 @@ tslib_1.__exportStar(require("./noResponse"), exports);

@@ -7,3 +7,4 @@ Object.defineProperty(exports, "__esModule", { value: true });

var js_base64_1 = require("js-base64");
var kinvey_1 = require("../kinvey");
var kinvey_1 = require("../errors/kinvey");
var kinvey_2 = require("../kinvey");
var session_1 = require("./session");

@@ -140,15 +141,24 @@ function byteCount(str) {

KinveyHttpHeaders.prototype.setAuthorization = function (auth) {
var appKey = kinvey_2.getAppKey();
var appSecret = kinvey_2.getAppSecret();
var masterSecret = kinvey_2.getMasterSecret();
var session = session_1.getSession();
var value = '';
if (auth === KinveyHttpAuth.App) {
var credentials = js_base64_1.Base64.encode(kinvey_1.getAppKey() + ":" + kinvey_1.getAppSecret());
if (!appKey || !appSecret) {
throw new kinvey_1.KinveyError('Missing appKey and/or appSecret to authorize the request.');
}
var credentials = js_base64_1.Base64.encode(appKey + ":" + appSecret);
value = "Basic " + credentials;
}
else if (auth === KinveyHttpAuth.Master) {
var credentials = js_base64_1.Base64.encode(kinvey_1.getAppKey() + ":" + kinvey_1.getMasterSecret());
if (!appKey || !masterSecret) {
throw new kinvey_1.KinveyError('Missing appKey and/or masterSecret to authorize the request.');
}
var credentials = js_base64_1.Base64.encode(appKey + ":" + masterSecret);
value = "Basic " + credentials;
}
else if (auth === KinveyHttpAuth.Session) {
var session = session_1.getSession();
if (!session || !session._kmd || !session._kmd.authtoken) {
throw new Error('There is no active user to authorize the request. Please login and retry the request.');
throw new kinvey_1.KinveyError('There is no active user to authorize the request.');
}

@@ -155,0 +165,0 @@ value = "Kinvey " + session._kmd.authtoken;

@@ -31,21 +31,4 @@ import { SessionStore, HttpAdapter } from './http';

appVersion: string;
deviceId: Promise<string>;
};
export declare function initialize(config: Config): {
apiHost: string;
apiHostname: string;
apiProtocol: string;
appKey: string;
appSecret: string;
masterSecret: string;
authHost: string;
authHostname: string;
authProtocol: string;
micHost: string;
micHostname: string;
micProtocol: string;
_defaultTimeout: number;
defaultTimeout: number;
encryptionKey: string;
_appVersion: string;
appVersion: string;
};
export declare function initialize(config: Config): void;

@@ -7,2 +7,3 @@ Object.defineProperty(exports, "__esModule", { value: true });

var kinvey_2 = require("./errors/kinvey");
var device_1 = require("./device");
function init(config) {

@@ -43,3 +44,4 @@ // Check that an appKey was provided

_appVersion: http_1.getAppVersion(),
appVersion: http_1.getAppVersion()
appVersion: http_1.getAppVersion(),
deviceId: device_1.getDeviceId()
};

@@ -49,5 +51,5 @@ }

function initialize(config) {
return init(config);
throw new kinvey_2.KinveyError('initialize() has been deprecated. Please use init().');
}
exports.initialize = initialize;
//# sourceMappingURL=init.js.map
export interface QueryObject {
filter?: any;
fields?: string[];
filter?: any;
sort?: any;

@@ -10,4 +10,4 @@ limit?: number;

private _parent?;
filter: any;
private _fields?;
filter: any;
private _sort?;

@@ -17,2 +17,3 @@ private _limit?;

constructor(query?: Query | QueryObject);
readonly key: string;
fields: string[];

@@ -240,3 +241,3 @@ sort: any;

*/
and(...args: any): this;
and(...args: any): Query;
/**

@@ -302,4 +303,4 @@ * Performs a logical NOR operation on the query and the provided queries.

*/
join(operator: string, queries: any): this;
private join;
process(docs?: object[]): any;
}

@@ -11,2 +11,3 @@ Object.defineProperty(exports, "__esModule", { value: true });

var query_1 = require("./errors/query");
var kinvey_1 = require("./errors/kinvey");
var UNSUPPORTED_CONDITIONS = ['$nearSphere'];

@@ -42,2 +43,13 @@ var PROTECTED_FIELDS = ['_id', '_acl'];

}
Object.defineProperty(Query.prototype, "key", {
get: function () {
if ((this._skip && this._skip > 0) || (this._limit && this._limit < Number.MAX_SAFE_INTEGER)) {
return null;
}
var queryObject = this.toQueryObject();
return queryObject && !isEmpty_1.default(queryObject) ? JSON.stringify(queryObject) : '';
},
enumerable: true,
configurable: true
});
Object.defineProperty(Query.prototype, "fields", {

@@ -520,3 +532,3 @@ get: function () {

if (this._parent && Object.hasOwnProperty.call(this._parent.filter, '$and')) {
return (_a = this._parent).nor.apply(_a, args);
return (_a = this._parent.nor).apply.apply(_a, [this._parent].concat(args));
}

@@ -543,3 +555,3 @@ return this.join('$nor', args);

if (this._parent) {
return (_a = this._parent).or.apply(_a, args);
return (_a = this._parent.or).apply.apply(_a, [this._parent].concat(args));
}

@@ -554,20 +566,20 @@ return this.join('$or', args);

Query.prototype.toQueryObject = function () {
var queryPlainObject = this.toPlainObject();
var queryObject = {};
if (Object.keys(this.filter).length > 0) {
queryObject.query = this.filter;
if (Object.keys(queryPlainObject.filter).length > 0) {
queryObject.query = queryPlainObject.filter;
}
if (this.fields && this.fields.length > 0) {
queryObject.fields = this.fields.join(',');
if (queryPlainObject.fields && queryPlainObject.fields.length > 0) {
queryObject.fields = queryPlainObject.fields.join(',');
}
if (isNumber_1.default(this.limit) && this.limit < Number.MAX_SAFE_INTEGER) {
queryObject.limit = this.limit;
if (isNumber_1.default(queryPlainObject.limit) && queryPlainObject.limit < Number.MAX_SAFE_INTEGER) {
queryObject.limit = queryPlainObject.limit;
}
if (isNumber_1.default(this.skip) && this.skip > 0) {
queryObject.skip = this.skip;
if (isNumber_1.default(queryPlainObject.skip) && queryPlainObject.skip > 0) {
queryObject.skip = queryPlainObject.skip;
}
if (this.sort && Object.keys(this.sort).length > 0) {
queryObject.sort = this.sort;
if (queryPlainObject.sort && Object.keys(queryPlainObject.sort).length > 0) {
queryObject.sort = queryPlainObject.sort;
}
var keys = Object.keys(queryObject);
keys.forEach(function (key) {
Object.keys(queryObject).forEach(function (key) {
queryObject[key] = isString_1.default(queryObject[key]) ? queryObject[key] : JSON.stringify(queryObject[key]);

@@ -653,11 +665,30 @@ });

var _this = this;
var that = this;
var filters = queries.map(function (query) { return query.filter; });
// Cast, validate, and parse arguments. If `queries` are supplied, obtain
// the `filter` for joining. The eventual return function will be the
// current query.
var result = new Query(this);
var filters = queries.map(function (queryObject) {
var query = queryObject;
if (!(queryObject instanceof Query)) {
if (isPlainObject_1.default(queryObject)) {
query = new Query(queryObject);
}
else {
throw new kinvey_1.KinveyError('query argument must be of type: Kinvey.Query[] or Object[].');
}
}
return query.toPlainObject().filter;
});
// If there are no `queries` supplied, create a new (empty) `Kinvey.Query`.
// This query is the right-hand side of the join expression, and will be
// returned to allow for a fluent interface.
if (filters.length === 0) {
that = new Query();
filters = [that.filter];
that._parent = this; // Required for operator precedence
result = new Query();
filters = [result.toPlainObject().filter];
result._parent = new Query(this);
}
// Join operators operate on the top-level of `_filter`. Since the `toJSON`
// magic requires `_filter` to be passed by reference, we cannot simply re-
// assign `_filter`. Instead, empty it without losing the reference.
var currentFilter = Object.keys(this.filter).reduce(function (filter, key) {
// eslint-disable-next-line no-param-reassign
filter[key] = _this.filter[key];

@@ -667,8 +698,9 @@ delete _this.filter[key];

}, {});
// `currentFilter` is the left-hand side query. Join with `filters`.
this.addFilter(operator, [currentFilter].concat(filters));
return that;
return result;
};
Query.prototype.process = function (docs) {
var _this = this;
if (docs === void 0) { docs = []; }
var queryPlainObject = this.toPlainObject();
if (!Array.isArray(docs)) {

@@ -682,4 +714,5 @@ throw new Error('data argument must be of type: Array.');

var processedDocs = void 0;
if (this.filter && !isEmpty_1.default(this.filter)) {
processedDocs = sift_1.default(this.filter, docs);
var filter = queryPlainObject.filter;
if (filter && !isEmpty_1.default(filter)) {
processedDocs = sift_1.default(filter, docs);
}

@@ -689,6 +722,6 @@ else {

}
if (!isEmpty_1.default(this.sort)) {
if (!isEmpty_1.default(queryPlainObject.sort)) {
// eslint-disable-next-line arrow-body-style
processedDocs.sort(function (a, b) {
return Object.keys(_this.sort)
return Object.keys(queryPlainObject.sort)
.reduce(function (result, field) {

@@ -698,6 +731,6 @@ if (typeof result !== 'undefined' && result !== 0) {

}
if (Object.prototype.hasOwnProperty.call(_this.sort, field)) {
if (Object.prototype.hasOwnProperty.call(queryPlainObject.sort, field)) {
var aField = nested(a, field);
var bField = nested(b, field);
var modifier = _this.sort[field]; // -1 (descending) or 1 (ascending)
var modifier = queryPlainObject.sort[field]; // -1 (descending) or 1 (ascending)
if ((aField !== null && typeof aField !== 'undefined')

@@ -725,18 +758,18 @@ && (bField === null || typeof bField === 'undefined')) {

}
if (isNumber_1.default(this.skip) && this.skip > 0) {
if (isNumber_1.default(this.limit) && this.limit < Number.MAX_SAFE_INTEGER) {
processedDocs = processedDocs.slice(this.skip, this.skip + this.limit);
if (isNumber_1.default(queryPlainObject.skip) && queryPlainObject.skip > 0) {
if (isNumber_1.default(queryPlainObject.limit) && queryPlainObject.limit < Number.MAX_SAFE_INTEGER) {
processedDocs = processedDocs.slice(queryPlainObject.skip, queryPlainObject.skip + queryPlainObject.limit);
}
else {
processedDocs = processedDocs.slice(this.skip);
processedDocs = processedDocs.slice(queryPlainObject.skip);
}
}
else if (isNumber_1.default(this.limit) && this.limit < Number.MAX_SAFE_INTEGER) {
processedDocs = processedDocs.slice(0, this.limit);
else if (isNumber_1.default(queryPlainObject.limit) && queryPlainObject.limit < Number.MAX_SAFE_INTEGER) {
processedDocs = processedDocs.slice(0, queryPlainObject.limit);
}
if (isArray_1.default(this.fields) && this.fields.length > 0) {
if (isArray_1.default(queryPlainObject.fields) && queryPlainObject.fields.length > 0) {
processedDocs = processedDocs.map(function (doc) {
var modifiedDoc = doc;
Object.keys(modifiedDoc).forEach(function (key) {
if (_this.fields && _this.fields.indexOf(key) === -1 && PROTECTED_FIELDS.indexOf(key) === -1) {
if (queryPlainObject.fields && queryPlainObject.fields.indexOf(key) === -1 && PROTECTED_FIELDS.indexOf(key) === -1) {
delete modifiedDoc[key];

@@ -743,0 +776,0 @@ }

{
"name": "kinvey-js-sdk",
"description": "Kinvey JavaScript SDK for JavaScript applications.",
"version": "4.0.0",
"version": "4.1.0",
"license": "Apache-2.0",

@@ -25,3 +25,4 @@ "homepage": "https://github.com/Kinvey/js-sdk/tree/master/packages/js-sdk",

"prebuild": "del lib",
"build": "tsc -p tsconfig.json"
"build": "tsc -p tsconfig.json",
"test": "mocha --require ts-node/register test/**/*.spec.ts"
},

@@ -42,2 +43,3 @@ "dependencies": {

"devDependencies": {
"@types/chai": "~4.1.7",
"@types/events": "~3.0.0",

@@ -47,5 +49,11 @@ "@types/js-base64": "~2.3.1",

"@types/loglevel": "~1.5.4",
"@types/mocha": "~5.2.6",
"@types/node": "~11.11.6",
"@types/url-join": "~4.0.0",
"axios": "~0.19.0",
"chai": "~4.2.0",
"del-cli": "~1.1.0",
"mocha": "~6.1.4",
"nock": "~10.0.6",
"ts-node": "~8.1.0",
"typescript": "~3.4.4"

@@ -52,0 +60,0 @@ },

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc