Comparing version 1.4.0 to 1.4.1
{ | ||
"name": "oso-cloud", | ||
"version": "1.4.0", | ||
"version": "1.4.1", | ||
"description": "Oso Cloud Node client", | ||
@@ -23,3 +23,3 @@ "keywords": [ | ||
"lint": "eslint", | ||
"test": "jest", | ||
"test": "jest -i", | ||
"prettier:check": "prettier --check \"**/*.{js,ts,tsx,json}\"", | ||
@@ -33,4 +33,4 @@ "prettier": "prettier --write \"**/*.{js,ts,tsx,json}\"", | ||
"dependencies": { | ||
"fetch-retry": "^5.0.5", | ||
"cross-fetch": "^4.0.0" | ||
"cross-fetch": "^4.0.0", | ||
"fetch-retry": "^5.0.5" | ||
}, | ||
@@ -40,2 +40,3 @@ "devDependencies": { | ||
"@types/node-fetch": "^2.6.2", | ||
"@types/pg": "^8.11.2", | ||
"eslint": "^8.0.1", | ||
@@ -48,2 +49,4 @@ "eslint-config-standard": "^17.0.0", | ||
"jest": "^28.1", | ||
"kysely": "^0.27.2", | ||
"pg": "^8.11.3", | ||
"prettier": "^2.6.2", | ||
@@ -50,0 +53,0 @@ "rimraf": "^3.0.2", |
@@ -90,2 +90,5 @@ /// <reference types="node" /> | ||
}; | ||
export declare type LocalQueryResult = { | ||
sql: string; | ||
}; | ||
export declare type PolicyMetadata = { | ||
@@ -119,2 +122,3 @@ resources: { | ||
}; | ||
dataBindings?: Promise<string>; | ||
constructor(url: string, apiKey: string, options: ClientOptions); | ||
@@ -149,2 +153,4 @@ fallbackEligible(path: string): boolean | "" | undefined; | ||
getStats(): Promise<StatsResult>; | ||
postAuthorizeQuery(query: AuthorizeQuery): Promise<LocalQueryResult>; | ||
postListQuery(query: ListQuery, column: string): Promise<LocalQueryResult>; | ||
clearData(): Promise<ApiResult>; | ||
@@ -151,0 +157,0 @@ getFacts(predicate: string, args: Value[]): Promise<Fact[]>; |
@@ -72,2 +72,5 @@ "use strict"; | ||
} | ||
if (options.dataBindings) { | ||
this.dataBindings = fs_1.promises.readFile(options.dataBindings, "utf-8"); | ||
} | ||
} | ||
@@ -263,2 +266,23 @@ fallbackEligible(path) { | ||
} | ||
postAuthorizeQuery(query) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const params = {}; | ||
const data = { | ||
query, | ||
data_bindings: (yield this.dataBindings) || "", | ||
}; | ||
return this._post(`/authorize_query`, params, data, false); | ||
}); | ||
} | ||
postListQuery(query, column) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const params = {}; | ||
const data = { | ||
query, | ||
column, | ||
data_bindings: (yield this.dataBindings) || "", | ||
}; | ||
return this._post(`/list_query`, params, data, false); | ||
}); | ||
} | ||
clearData() { | ||
@@ -265,0 +289,0 @@ const params = {}; |
@@ -17,3 +17,31 @@ import { Api } from "./api"; | ||
fallbackUrl?: string; | ||
dataBindings?: string; | ||
}; | ||
declare class Experimental { | ||
api: Api; | ||
constructor(api: Api); | ||
/** | ||
* Check a permission depending on data both in Oso Cloud and stored in a local database. | ||
* | ||
* Returns a SQL query to run against the local database. | ||
* | ||
* @param {Instance} actor | ||
* @param {string} action | ||
* @param {Instance} resource | ||
* @returns {Promise<string>} | ||
*/ | ||
authorizeLocal(actor: Instance, action: string, resource: Instance): Promise<string>; | ||
/** | ||
* List authorized resources depending on data both in Oso Cloud and stored in a local database. | ||
* | ||
* Returns a SQL query to run against the local database. | ||
* | ||
* @param {Instance} actor | ||
* @param {string} action | ||
* @param {Instance[]} resourceType | ||
* @param {string} column | ||
* @returns {Promise<string>} | ||
*/ | ||
listLocal(actor: Instance, action: string, resourceType: string, column: string): Promise<string>; | ||
} | ||
/** | ||
@@ -27,2 +55,3 @@ * Oso Cloud client | ||
api: Api; | ||
experimental: Experimental; | ||
constructor(url: string, apiKey: string, options?: ClientOptions); | ||
@@ -166,2 +195,3 @@ /** | ||
} | ||
export {}; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -15,2 +15,70 @@ "use strict"; | ||
const api_1 = require("./api"); | ||
class Experimental { | ||
constructor(api) { | ||
this.api = api; | ||
} | ||
/** | ||
* Check a permission depending on data both in Oso Cloud and stored in a local database. | ||
* | ||
* Returns a SQL query to run against the local database. | ||
* | ||
* @param {Instance} actor | ||
* @param {string} action | ||
* @param {Instance} resource | ||
* @returns {Promise<string>} | ||
*/ | ||
authorizeLocal(actor, action, resource) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (typeof action !== "string") { | ||
throw new TypeError(`'action' should be a string: ${action}`); | ||
} | ||
const { type: actor_type, id: actor_id } = (0, helpers_1.toValue)(actor); | ||
const { type: resource_type, id: resource_id } = (0, helpers_1.toValue)(resource); | ||
if (actor_type == null || actor_id == null) { | ||
throw new TypeError(`'actor' can not be a wildcard: ${actor}`); | ||
} | ||
if (resource_type == null || resource_id == null) { | ||
throw new TypeError(`'resource' can not be a wildcard: ${resource}`); | ||
} | ||
const result = yield this.api.postAuthorizeQuery({ | ||
actor_type, | ||
actor_id, | ||
action, | ||
resource_type, | ||
resource_id, | ||
context_facts: [], | ||
}); | ||
return result.sql; | ||
}); | ||
} | ||
/** | ||
* List authorized resources depending on data both in Oso Cloud and stored in a local database. | ||
* | ||
* Returns a SQL query to run against the local database. | ||
* | ||
* @param {Instance} actor | ||
* @param {string} action | ||
* @param {Instance[]} resourceType | ||
* @param {string} column | ||
* @returns {Promise<string>} | ||
*/ | ||
listLocal(actor, action, resourceType, column) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (typeof action !== "string") | ||
throw new TypeError(`'action' should be a string: ${action}`); | ||
const { type: actor_type, id: actor_id } = (0, helpers_1.toValue)(actor); | ||
if (actor_type == null || actor_id == null) { | ||
throw new TypeError(`'actor' can not be a wildcard: ${actor}`); | ||
} | ||
const result = yield this.api.postListQuery({ | ||
actor_type, | ||
actor_id, | ||
action, | ||
resource_type: resourceType, | ||
context_facts: [], | ||
}, column); | ||
return result.sql; | ||
}); | ||
} | ||
} | ||
/** | ||
@@ -25,2 +93,3 @@ * Oso Cloud client | ||
this.api = new api_1.Api(url, apiKey, options || {}); | ||
this.experimental = new Experimental(this.api); | ||
} | ||
@@ -47,3 +116,3 @@ /** | ||
if (resource_type == null || resource_id == null) { | ||
throw new TypeError(`'actor' can not be a wildcard: ${actor}`); | ||
throw new TypeError(`'resource' can not be a wildcard: ${resource}`); | ||
} | ||
@@ -50,0 +119,0 @@ let result = yield this.api.postAuthorize({ |
{ | ||
"name": "oso-cloud", | ||
"version": "1.4.0", | ||
"version": "1.4.1", | ||
"description": "Oso Cloud Node client", | ||
@@ -23,3 +23,3 @@ "keywords": [ | ||
"lint": "eslint", | ||
"test": "jest", | ||
"test": "jest -i", | ||
"prettier:check": "prettier --check \"**/*.{js,ts,tsx,json}\"", | ||
@@ -33,4 +33,4 @@ "prettier": "prettier --write \"**/*.{js,ts,tsx,json}\"", | ||
"dependencies": { | ||
"fetch-retry": "^5.0.5", | ||
"cross-fetch": "^4.0.0" | ||
"cross-fetch": "^4.0.0", | ||
"fetch-retry": "^5.0.5" | ||
}, | ||
@@ -40,2 +40,3 @@ "devDependencies": { | ||
"@types/node-fetch": "^2.6.2", | ||
"@types/pg": "^8.11.2", | ||
"eslint": "^8.0.1", | ||
@@ -48,2 +49,4 @@ "eslint-config-standard": "^17.0.0", | ||
"jest": "^28.1", | ||
"kysely": "^0.27.2", | ||
"pg": "^8.11.3", | ||
"prettier": "^2.6.2", | ||
@@ -50,0 +53,0 @@ "rimraf": "^3.0.2", |
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
123409
24
1760
16
3