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

oso-cloud

Package Overview
Dependencies
Maintainers
6
Versions
46
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

oso-cloud - npm Package Compare versions

Comparing version 1.0.4 to 1.1.0

7

dist/package.json
{
"name": "oso-cloud",
"version": "1.0.4",
"version": "1.1.0",
"description": "Oso Cloud Node client",

@@ -32,4 +32,5 @@ "keywords": [

"dependencies": {
"fetch-retry-ts": "^1.1.25",
"node-fetch": "^2.6.7"
"@types/isomorphic-fetch": "^0.0.36",
"fetch-retry": "^5.0.5",
"isomorphic-fetch": "^3.0.0"
},

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

@@ -5,2 +5,3 @@ /// <reference types="node" />

import https from "https";
import { ClientOptions } from ".";
export declare type ApiResult = {

@@ -95,9 +96,15 @@ message: string;

userAgent: string;
constructor(url: string, apiKey: string, userAgent?: string);
debug(msg: string): Promise<void>;
_req<B, R>(path: string, method: string, params: Record<string, string>, body: B): Promise<R>;
lastOffset: string | null;
debug?: {
print?: boolean;
file?: string;
};
constructor(url: string, apiKey: string, options: ClientOptions);
printDebugInfo(msg: string): Promise<void>;
_req<B, R>(path: string, method: string, params: Record<string, string>, body: B, isMutation: boolean): Promise<R>;
_get<B, R>(path: string, params: Record<string, string>, _body: B): Promise<R>;
_post<B, R>(path: string, params: Record<string, string>, body: B): Promise<R>;
_post<B, R>(path: string, params: Record<string, string>, body: B, isMutation: boolean): Promise<R>;
_delete<B, R>(path: string, params: Record<string, string>, body: B): Promise<R>;
_headers(): {
OsoOffset?: string | undefined;
"Content-Type": string;

@@ -104,0 +111,0 @@ Authorization: string;

@@ -21,5 +21,5 @@ "use strict";

const fs_1 = require("fs");
const node_fetch_1 = __importDefault(require("node-fetch"));
const fetch_retry_ts_1 = __importDefault(require("fetch-retry-ts"));
const isomorphic_fetch_1 = __importDefault(require("isomorphic-fetch"));
const package_json_1 = require("../package.json");
const fetch_retry_1 = __importDefault(require("fetch-retry"));
const retryOptions = {

@@ -32,13 +32,19 @@ retries: 10,

};
const fetch = (0, fetch_retry_ts_1.default)(node_fetch_1.default, retryOptions);
const fetch = (0, fetch_retry_1.default)(isomorphic_fetch_1.default, retryOptions);
class Api {
constructor(url, apiKey, userAgent) {
constructor(url, apiKey, options) {
if (typeof url !== "string" && url !== undefined)
throw new TypeError(`'url' should be a string`);
this.url = url || "https://cloud.osohq.com";
this.url = url || "https://api.osohq.com";
this.token = apiKey;
this.userAgent = `Oso Cloud (nodejs ${process.version}; rv:${package_json_1.version})`;
if (userAgent) {
this.userAgent = `${this.userAgent} ${userAgent}`;
this.debug = options.debug;
if (options.userAgent) {
this.userAgent = options.userAgent;
}
else if (typeof process === "object") {
this.userAgent = `Oso Cloud (nodejs ${process.version}; rv:${package_json_1.version})`;
}
else {
this.userAgent = `Oso Cloud (browser; rv:${package_json_1.version})`;
}
const parsed = new url_1.URL(this.url);

@@ -54,14 +60,20 @@ if (parsed.protocol === "https:") {

}
this.lastOffset = null;
}
debug(msg) {
printDebugInfo(msg) {
return __awaiter(this, void 0, void 0, function* () {
if (process.env.OSO_DEBUG_PRINT != undefined) {
const debug = this.debug;
if (debug === undefined) {
return;
}
if (debug.print !== undefined) {
console.log(msg);
}
if (process.env.OSO_DEBUG_FILE != undefined) {
const file = debug.file;
if (file !== undefined) {
try {
yield fs_1.promises.appendFile(process.env.OSO_DEBUG_FILE, msg + "\n");
yield fs_1.promises.appendFile(file, msg + "\n");
}
catch (error) {
console.log(error);
console.log("error writing to debug file: ", error);
}

@@ -71,3 +83,3 @@ }

}
_req(path, method, params, body) {
_req(path, method, params, body, isMutation) {
return __awaiter(this, void 0, void 0, function* () {

@@ -95,6 +107,6 @@ let url = `${this.url}/api${path}`;

if (serverMs !== null && Number.isInteger(serverMs)) {
yield this.debug(`[oso] ${path} ${result.status} total: ${totalMs}ms, server: ${serverMs}ms network: ${totalMs - serverMs}ms`);
yield this.printDebugInfo(`[oso] ${path} ${result.status} total: ${totalMs}ms, server: ${serverMs}ms network: ${totalMs - serverMs}ms`);
}
else {
yield this.debug(`[oso] ${path} ${result.status} total: ${totalMs}ms`);
yield this.printDebugInfo(`[oso] ${path} ${result.status} total: ${totalMs}ms`);
}

@@ -105,2 +117,6 @@ if (result.status < 200 || result.status >= 300) {

}
if (isMutation) {
const offset = result.headers.get("OsoOffset");
this.lastOffset = offset;
}
return result.json();

@@ -111,8 +127,8 @@ });

return __awaiter(this, void 0, void 0, function* () {
return this._req(path, "GET", params, null);
return this._req(path, "GET", params, null, false);
});
}
_post(path, params, body) {
_post(path, params, body, isMutation) {
return __awaiter(this, void 0, void 0, function* () {
return this._req(path, "POST", params, body);
return this._req(path, "POST", params, body, isMutation);
});

@@ -122,12 +138,7 @@ }

return __awaiter(this, void 0, void 0, function* () {
return this._req(path, "DELETE", params, body);
return this._req(path, "DELETE", params, body, true);
});
}
_headers() {
return {
"Content-Type": "application/json",
Authorization: `Bearer ${this.token}`,
"User-Agent": this.userAgent,
"X-OsoApiVersion": "0",
};
return Object.assign({ "Content-Type": "application/json", Authorization: `Bearer ${this.token}`, "User-Agent": this.userAgent, "X-OsoApiVersion": "0" }, (this.lastOffset ? { OsoOffset: this.lastOffset } : {}));
}

@@ -142,3 +153,3 @@ getPolicy() {

const params = {};
const result = this._post(`/policy`, params, data);
const result = this._post(`/policy`, params, data, true);
return result;

@@ -148,3 +159,3 @@ }

const params = {};
const result = this._post(`/facts`, params, data);
const result = this._post(`/facts`, params, data, true);
return result;

@@ -159,3 +170,3 @@ }

const params = {};
const result = this._post(`/bulk_load`, params, data);
const result = this._post(`/bulk_load`, params, data, true);
return result;

@@ -165,3 +176,3 @@ }

const params = {};
const result = this._post(`/bulk_delete`, params, data);
const result = this._post(`/bulk_delete`, params, data, true);
return result;

@@ -171,3 +182,3 @@ }

const params = {};
const result = this._post(`/bulk`, params, data);
const result = this._post(`/bulk`, params, data, true);
return result;

@@ -177,3 +188,3 @@ }

const params = {};
const result = this._post(`/authorize`, params, data);
const result = this._post(`/authorize`, params, data, false);
return result;

@@ -183,3 +194,3 @@ }

const params = {};
const result = this._post(`/authorize_resources`, params, data);
const result = this._post(`/authorize_resources`, params, data, false);
return result;

@@ -189,3 +200,3 @@ }

const params = {};
const result = this._post(`/list`, params, data);
const result = this._post(`/list`, params, data, false);
return result;

@@ -195,3 +206,3 @@ }

const params = {};
const result = this._post(`/actions`, params, data);
const result = this._post(`/actions`, params, data, false);
return result;

@@ -201,3 +212,3 @@ }

const params = {};
const result = this._post(`/query`, params, data);
const result = this._post(`/query`, params, data, false);
return result;

@@ -214,3 +225,3 @@ }

const data = null;
const result = this._post(`/clear_data`, params, data);
const result = this._post(`/clear_data`, params, data, true);
return result;

@@ -217,0 +228,0 @@ }

@@ -7,2 +7,9 @@ import { Api } from "./api";

export declare type Fact = [predicate: string, ...args: Instance[]];
export declare type ClientOptions = {
debug?: {
print?: boolean;
file?: string;
};
userAgent?: string;
};
/**

@@ -16,3 +23,3 @@ * Oso Cloud client

api: Api;
constructor(url: string, apiKey: string, userAgent?: string);
constructor(url: string, apiKey: string, options?: ClientOptions);
/**

@@ -19,0 +26,0 @@ * Check a permission.

@@ -22,4 +22,4 @@ "use strict";

class Oso {
constructor(url, apiKey, userAgent) {
this.api = new api_1.Api(url, apiKey, userAgent);
constructor(url, apiKey, options) {
this.api = new api_1.Api(url, apiKey, options || {});
}

@@ -26,0 +26,0 @@ /**

{
"name": "oso-cloud",
"version": "1.0.4",
"version": "1.1.0",
"description": "Oso Cloud Node client",

@@ -32,4 +32,5 @@ "keywords": [

"dependencies": {
"fetch-retry-ts": "^1.1.25",
"node-fetch": "^2.6.7"
"@types/isomorphic-fetch": "^0.0.36",
"fetch-retry": "^5.0.5",
"isomorphic-fetch": "^3.0.0"
},

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

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