New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@lokalise/node-api

Package Overview
Dependencies
Maintainers
1
Versions
86
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@lokalise/node-api - npm Package Compare versions

Comparing version 0.0.1 to 0.0.2

dist/interfaces/bulk_update_key.js

42

dist/http_client/base.js

@@ -6,17 +6,22 @@ "use strict";

class ApiRequest {
constructor(uri, method, params = {}) {
constructor(uri, method, body = null, params = {}) {
this.urlRoot = 'https://api.lokalise.co/api2/';
this.promise = this.createPromise(uri, method, params);
this.params = {};
this.params = params;
this.promise = this.createPromise(uri, method, body);
return this;
}
createPromise(uri, method, params) {
createPromise(uri, method, body) {
let options = {
url: this.urlRoot + uri,
url: this.urlRoot + this.composeURI(uri),
method: method,
headers: { 'x-api-token': lokalise_1.LokaliseApi.apiKey, 'content-type': 'application/json' }
};
if (Object.keys(params).length > 0) {
options['body'] = JSON.stringify(params);
if (Object.keys(this.params).length > 0) {
// this.composeQueryString();
options['qs'] = this.params;
}
console.log(options);
if (body) {
options['body'] = JSON.stringify(body);
}
return new Promise((resolve, reject) => {

@@ -29,2 +34,3 @@ request(options, (error, response, body) => {

else {
console.log(JSON.parse(body));
resolve(JSON.parse(body));

@@ -35,2 +41,24 @@ }

}
composeURI(uri) {
let regexp = /{(\!{0,1}):(\w*)\}/g;
let matches = uri.replace(regexp, this.mapUriParams(this.params));
console.log(matches);
return matches;
}
mapUriParams(params) {
console.log(params);
return (entity, isMandaratory, paramName) => {
if (params[paramName] != null) {
return params[paramName];
}
else {
if (isMandaratory == '!') {
throw new Error('Required param ' + paramName);
}
else {
return '';
}
}
};
}
constructParameters(method, params) { }

@@ -37,0 +65,0 @@ }

33

dist/lokalise/api_methods.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const comments_1 = require("../endpoints/comments");
const Models = require("../models/index");
class LocaliseApiMethods {
constructor() {
this.comments = new comments_1.Comments();
// contributes = new Contributes();
// files = new Files()
// keys = new Keys();
// languages = new Languages();
// projects = new Projects();
// screenshots = new Screenshots();
// comments() {}
// contributes() {}
// files() {}
// keys(){}
// languages(){}
// projects(){}
// screenshots(){}
// snapshots(){}
// tasks(){}
// teamUsers(){}
// teams(){}
// TODO: Lazy loading
this.comments = new Models.Comments();
this.contributors = new Models.Contributors();
this.files = new Models.Files();
this.keys = new Models.Keys();
this.languages = new Models.Languages();
this.projects = new Models.Projects();
this.screenshots = new Models.Screenshots();
this.snapshots = new Models.Snapshots();
this.tasks = new Models.Tasks();
this.teamUsers = new Models.TeamUsers();
this.userGroups = new Models.UserGroups();
this.translations = new Models.Translations();
}

@@ -25,0 +20,0 @@ }

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const api_methods_1 = require("./api_methods");
//
class LokaliseApi extends api_methods_1.LocaliseApiMethods {

@@ -8,3 +9,3 @@ constructor(apiKey) {

LokaliseApi.apiKey = apiKey;
if (LokaliseApi.apiKey.length == 0) {
if (LokaliseApi.apiKey == null || LokaliseApi.apiKey.length == 0) {
throw new Error("Error: Instantiation failed: Please pass api key");

@@ -15,4 +16,4 @@ }

}
LokaliseApi.apiKey = '44fd964aa8ac7196762d61a4949326fea38a5f60';
LokaliseApi.apiKey = null;
exports.LokaliseApi = LokaliseApi;
//# sourceMappingURL=lokalise.js.map

@@ -5,80 +5,17 @@ "use strict";

class BaseModel {
get(id) {
let childClass = this.constructor;
let endpoint = childClass.endpoint;
let uri = endpoint + '/' + id;
console.log(this.composeURI({ id: 1 }));
return new Promise((resolve, reject) => {
let response = new base_1.ApiRequest(uri, 'GET');
response.promise.then((result) => {
resolve(this.populateObjectFromJson(result));
}).then((data) => {
reject(data);
});
});
get(id, params = {}, body = null) {
return this.createPromise('GET', { id: id }, this.populateObjectFromJson, this.handleReject, body);
}
list() {
return new Promise((resolve, reject) => {
let childClass = this.constructor;
let rootElementName = childClass.rootElementName;
let endpoint = childClass.endpoint;
let uri = endpoint;
let response = new base_1.ApiRequest(uri, 'GET');
response.promise.then((result) => {
if (result[rootElementName]) {
resolve(this.populateArrayFromJson(result[rootElementName]));
}
else {
reject('Server returned incorrect format');
}
}).then((data) => {
reject(data);
});
});
list(params = {}) {
return this.createPromise('GET', params, this.populateArrayFromJson, this.handleReject, null);
}
create(params) {
let childClass = this.constructor;
let endpoint = childClass.endpoint;
let uri = endpoint;
return new Promise((resolve, reject) => {
let response = new base_1.ApiRequest(uri, 'POST', params);
response.promise.then((result) => {
resolve(this.populateObjectFromJson(result));
}).then((data) => {
reject(data);
});
});
create(body, params = {}) {
return this.createPromise('POST', params, this.populateObjectFromJson, this.handleReject, body);
}
update(params) {
let childClass = this.constructor;
let endpoint = childClass.endpoint;
let uri = endpoint;
return new Promise((resolve, reject) => {
let response = new base_1.ApiRequest(uri, 'PUT', params);
response.promise.then((result) => {
resolve(this.populateObjectFromJson(result));
}).then((data) => {
reject(data);
});
});
update(body, params = {}) {
return this.createPromise('PUT', params, this.populateObjectFromJson, this.handleReject, body);
}
composeURI(params) {
let regexp = /{(\!{0,1})(\w*)\}/g;
let childClass = this.constructor;
let matches = childClass.prefixURI.replace(regexp, this.constructURI(entity, isMandaratory, paramName, params));
delete(id, params = {}) {
return this.createPromise('DELETE', { id: id }, this.populateObjectFromJson, this.handleReject, null);
}
constructURI(entity, isMandaratory, paramName, params) {
let str = paramsName;
if (params[paramName]) {
return z;
}
else {
if (isMandaratory == '!') {
throw new Error('Reqeuired params');
}
else {
'';
}
}
}
populateObjectFromJson(json) {

@@ -91,4 +28,6 @@ for (let key in json) {

populateArrayFromJson(json) {
let childClass = this.constructor;
let arr = new Array();
for (let obj of json) {
let jsonArray = json[childClass.rootElementName];
for (let obj of jsonArray) {
arr.push(this.populateObjectFromJson(obj));

@@ -98,2 +37,22 @@ }

}
returnBareJSON(json) {
return json;
}
handleReject(data) {
return data;
}
createPromise(method, params, resolveFn, rejectFn = this.handleReject, body = null, uri = null) {
let childClass = this.constructor;
if (uri == null) {
uri = childClass.prefixURI;
}
return new Promise((resolve, reject) => {
let response = new base_1.ApiRequest(uri, method, body, params);
response.promise.then((result) => {
resolve(resolveFn.call(this, result));
}).then((data) => {
reject(rejectFn.call(this, data));
});
});
}
}

@@ -100,0 +59,0 @@ BaseModel.rootElementName = null;

{
"name": "@lokalise/node-api",
"version": "0.0.1",
"version": "0.0.2",
"description": "Node lokalise api",

@@ -17,2 +17,3 @@ "license": "MIT",

"@types/mocha": "^5.2.5",
"@types/node": "^10.12.18",
"eslint": "^3.19.0",

@@ -25,4 +26,3 @@ "eslint-config-airbnb-base": "^13.1.0",

"typedoc": "^0.14.2",
"typedoc-plugin-markdown": "^1.1.22",
"typings": "^2.1.1"
"typedoc-plugin-markdown": "^1.1.22"
},

@@ -33,3 +33,4 @@ "dependencies": {

"request": "^2.88.0",
"ts-node": "^7.0.1"
"ts-node": "^7.0.1",
"typescript": "^3.2.4"
},

@@ -36,0 +37,0 @@ "bugs": {

@@ -1,2 +0,1 @@

import { Comments } from '../endpoints/comments';
import * as Models from '../models/index';

@@ -3,0 +2,0 @@

@@ -37,4 +37,6 @@ import { ApiRequest } from '../http_client/base';

protected populateArrayFromJson(json: Array<any>): this[] {
let childClass = <typeof BaseModel>this.constructor;
let arr: this[] = new Array();
for (let obj of json) {
let jsonArray = json[childClass.rootElementName];
for (let obj of jsonArray) {
arr.push(this.populateObjectFromJson(obj));

@@ -61,5 +63,5 @@ }

response.promise.then((result) => {
resolve(resolveFn.call(result));
resolve(resolveFn.call(this, result));
}).then((data) => {
reject(rejectFn.call(data));
reject(rejectFn.call(this, data));
});

@@ -66,0 +68,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

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