@plattar/plattar-api
Advanced tools
Comparing version 1.91.8 to 1.91.9
@@ -51,3 +51,4 @@ "use strict"; | ||
const Tag = require("./types/misc/tag.js"); | ||
const ApplicationBuild = require('./types/misc/application-build.js'); | ||
const ApplicationBuild = require("./types/misc/application-build.js"); | ||
const AsyncJob = require("./types/misc/async-job.js"); | ||
@@ -111,2 +112,3 @@ // base types | ||
ApplicationBuild, | ||
AsyncJob, | ||
// base types | ||
@@ -116,2 +118,2 @@ SceneObject, | ||
ProductObject | ||
} | ||
}; |
{ | ||
"name": "@plattar/plattar-api", | ||
"version": "1.91.8", | ||
"version": "1.91.9", | ||
"description": "Module for interfacing with the Plattar API (https://www.plattar.com)", | ||
@@ -9,5 +9,6 @@ "main": "index.js", | ||
"test": "echo \"Error: no test specified\" && exit 1", | ||
"clean": "rm -rf build", | ||
"build": "rm -rf build && browserify --standalone Plattar index.js -o build/plattar-api.js && uglifyjs build/plattar-api.js --output build/plattar-api-min.js", | ||
"build-es2015": "babel build/plattar-api.js --presets=@babel/env > build/plattar-api-es2015.js && uglifyjs build/plattar-api-es2015.js --output build/plattar-api-es2015-min.js" | ||
"clean": "rm -rf build node_modules", | ||
"build": "npm run clean && npm install && npm run build-es2019 && npm run build-es2015", | ||
"build-es2019": "rm -rf build/es2019 && mkdir -p build/es2019 && browserify --standalone Plattar index.js -o build/es2019/plattar-api.js && uglifyjs build/es2019/plattar-api.js --output build/es2019/plattar-api-min.js", | ||
"build-es2015": "rm -rf build/es2015 && mkdir -p build/es2015 && babel build/es2019/plattar-api.js --presets=@babel/env > build/es2015/plattar-api.js && uglifyjs build/es2015/plattar-api.js --output build/es2015/plattar-api-min.js" | ||
}, | ||
@@ -14,0 +15,0 @@ "repository": { |
@@ -15,2 +15,3 @@ const fetch = require("node-fetch"); | ||
this._server = server; | ||
this._params = []; | ||
this._getIncludeQuery = []; | ||
@@ -61,2 +62,3 @@ } | ||
const includeQuery = this._IncludeQuery; | ||
const params = this._ParamFor("get"); | ||
@@ -69,2 +71,12 @@ let endpoint = origin + target.type() + "/" + target.id; | ||
if (params) { | ||
let appender = includeQuery ? "&" : "?"; | ||
params.forEach((param) => { | ||
endpoint = endpoint + appender + param.key + "=" + param.value; | ||
appender = "&"; | ||
}); | ||
} | ||
fetch(endpoint, reqopts) | ||
@@ -100,3 +112,74 @@ .then((res) => { | ||
return new Promise((resolve, reject) => { | ||
reject(new Error("PlattarQuery." + this.target.type() + ".update(" + this.target.id + ") - not implemented")); | ||
const target = this.target; | ||
const server = this.server; | ||
// we cannot perform a GET request without an ID | ||
if (!target.id) { | ||
reject(new Error("PlattarQuery." + target.type() + ".update() - object id is missing")); | ||
return; | ||
} | ||
// otherwise, proceed with the fetching op | ||
const origin = server.originLocation.api; | ||
const auth = server.authToken; | ||
const headers = { | ||
'Accept': 'application/json', | ||
'Content-Type': 'application/json' | ||
}; | ||
Object.assign(headers, auth); | ||
const reqopts = { | ||
method: "PATCH", | ||
headers: headers, | ||
body: JSON.stringify( | ||
{ | ||
data: { | ||
id: target.id, | ||
attributes: target.attributes | ||
} | ||
} | ||
) | ||
}; | ||
const params = this._ParamFor("update"); | ||
let endpoint = origin + target.type() + "/" + target.id; | ||
if (params) { | ||
let appender = "?"; | ||
params.forEach((param) => { | ||
endpoint = endpoint + appender + param.key + "=" + param.value; | ||
appender = "&"; | ||
}); | ||
} | ||
fetch(endpoint, reqopts) | ||
.then((res) => { | ||
if (res.ok) { | ||
try { | ||
return res.json(); | ||
} | ||
catch (err) { | ||
return new Error("PlattarQuery." + target.type() + ".update(" + target.id + ") - critical error occured, cannot proceed"); | ||
} | ||
} | ||
return new Error("PlattarQuery." + target.type() + ".update(" + target.id + ") - unexpected error occured, cannot proceed. error message is " + res.statusText); | ||
}) | ||
.then((json) => { | ||
if (json instanceof Error) { | ||
reject(json); | ||
} | ||
else { | ||
const PlattarUtil = require("../util/plattar-util.js"); | ||
PlattarUtil.reconstruct(target, json, { cache: true }); | ||
resolve(target); | ||
} | ||
}); | ||
}); | ||
@@ -118,2 +201,15 @@ } | ||
/** | ||
* Adds a specific request parameter | ||
*/ | ||
_addParameter(key, value, type) { | ||
type = type || "all"; | ||
this._params.push({ | ||
key: key, | ||
value: value, | ||
type: type.toLowerCase() | ||
}); | ||
} | ||
/** | ||
* Includes this query with the next GET operation | ||
@@ -159,2 +255,20 @@ */ | ||
/** | ||
* Filters and returns all request parameters for a particular | ||
* request type | ||
*/ | ||
_ParamFor(type) { | ||
type = type || "all"; | ||
const list = this._params.filter((objcheck) => { | ||
return objcheck.type === type || objcheck.type === "all"; | ||
}); | ||
if (list.length > 0) { | ||
return list; | ||
} | ||
return undefined; | ||
} | ||
/** | ||
* Performs a combination of all include queries | ||
@@ -161,0 +275,0 @@ */ |
@@ -139,2 +139,6 @@ const fetch = require("node-fetch"); | ||
PlattarServer.disableTLS = () => { | ||
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0"; | ||
}; | ||
PlattarServer.default = () => { | ||
@@ -141,0 +145,0 @@ return PlattarServer._default; |
@@ -45,2 +45,11 @@ const PlattarQuery = require("../../server/plattar-query.js"); | ||
/** | ||
* This can be used to override the current internal attributes | ||
* with new Data. Upon next request, the override attributes will | ||
* be used | ||
*/ | ||
set overrideAttributes(attributes) { | ||
this._attributes = Object.assign({}, attributes); | ||
} | ||
get relationships() { | ||
@@ -115,4 +124,13 @@ return this._relationships; | ||
} | ||
/** | ||
* Adds a parameter for a particular request | ||
*/ | ||
addParameter(key, value, type) { | ||
this._query._addParameter(key, value, type); | ||
return this; | ||
} | ||
} | ||
module.exports = PlattarObject; |
@@ -49,2 +49,3 @@ const Application = require("../types/application.js"); | ||
const ApplicationBuild = require("../types/misc/application-build.js"); | ||
const AsyncJob = require("../types/misc/async-job.js"); | ||
@@ -190,2 +191,3 @@ class PlattarUtil { } | ||
case ApplicationBuild.type(): return ApplicationBuild; | ||
case AsyncJob.type(): return AsyncJob; | ||
default: throw new Error("PlattarUtil.match(type) - provided type of \"" + type + "\" does not exist and cannot be created"); | ||
@@ -192,0 +194,0 @@ } |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
1
1
5
51709
53
1198