Comparing version 1.5.0 to 1.6.0
{ | ||
"name": "oso-cloud", | ||
"version": "1.5.0", | ||
"version": "1.6.0", | ||
"description": "Oso Cloud Node client", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -10,2 +10,3 @@ import { Api } from "./api"; | ||
}; | ||
export { AuthorizeResult } from "./api"; | ||
export declare type ClientOptions = { | ||
@@ -20,29 +21,2 @@ debug?: { | ||
}; | ||
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>; | ||
} | ||
/** | ||
@@ -56,3 +30,2 @@ * Oso Cloud client | ||
api: Api; | ||
experimental: Experimental; | ||
constructor(url: string, apiKey: string, options?: ClientOptions); | ||
@@ -207,4 +180,26 @@ /** | ||
query_with_context(fact: Fact, { contextFacts }: Context): Promise<Fact[]>; | ||
/** | ||
* 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>; | ||
} | ||
export {}; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -15,70 +15,2 @@ "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; | ||
}); | ||
} | ||
} | ||
/** | ||
@@ -93,3 +25,2 @@ * Oso Cloud client | ||
this.api = new api_1.Api(url, apiKey, options || {}); | ||
this.experimental = new Experimental(this.api); | ||
} | ||
@@ -427,4 +358,67 @@ /** | ||
} | ||
/** | ||
* 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; | ||
}); | ||
} | ||
} | ||
exports.Oso = Oso; | ||
//# sourceMappingURL=index.js.map |
@@ -43,3 +43,3 @@ "use strict"; | ||
test("basic list filtering, all rows", () => __awaiter(void 0, void 0, void 0, function* () { | ||
const filter = yield oso.experimental.listLocal(alice, "read", "Environment", "id::TEXT"); | ||
const filter = yield oso.listLocal(alice, "read", "Environment", "id"); | ||
const results = yield db | ||
@@ -53,3 +53,3 @@ .selectFrom("environment") | ||
test("basic list filtering, some rows", () => __awaiter(void 0, void 0, void 0, function* () { | ||
const filter = yield oso.experimental.listLocal(alice, "create_fact", "Environment", "id::TEXT"); | ||
const filter = yield oso.listLocal(alice, "create_fact", "Environment", "id"); | ||
const results = yield db | ||
@@ -63,3 +63,3 @@ .selectFrom("environment") | ||
test("list filtering, wildcard", () => __awaiter(void 0, void 0, void 0, function* () { | ||
const filter = yield oso.experimental.listLocal(bob, "read", "Environment", "id::TEXT"); | ||
const filter = yield oso.listLocal(bob, "read", "Environment", "id"); | ||
const results = yield db | ||
@@ -73,3 +73,3 @@ .selectFrom("environment") | ||
test("list filtering, no rows", () => __awaiter(void 0, void 0, void 0, function* () { | ||
const filter = yield oso.experimental.listLocal(alice, "frob", "Environment", "id::TEXT"); | ||
const filter = yield oso.listLocal(alice, "frob", "Environment", "id"); | ||
const results = yield db | ||
@@ -83,22 +83,26 @@ .selectFrom("environment") | ||
test("basic authorize, allowed", () => __awaiter(void 0, void 0, void 0, function* () { | ||
const query = yield oso.experimental.authorizeLocal(alice, "create_fact", environment1); | ||
const result = (yield kysely_1.sql.raw(query).execute(db)).rows.length; | ||
expect(result).toBeTruthy(); | ||
const query = yield oso.authorizeLocal(alice, "create_fact", environment1); | ||
const { allowed } = (yield kysely_1.sql.raw(query).execute(db)) | ||
.rows[0]; | ||
expect(allowed).toBe(true); | ||
})); | ||
test("basic authorize, denied", () => __awaiter(void 0, void 0, void 0, function* () { | ||
const query = yield oso.experimental.authorizeLocal(alice, "create_fact", environment2); | ||
const result = (yield kysely_1.sql.raw(query).execute(db)).rows.length; | ||
expect(result).toBeFalsy(); | ||
const query = yield oso.authorizeLocal(alice, "create_fact", environment2); | ||
const { allowed } = (yield kysely_1.sql.raw(query).execute(db)) | ||
.rows[0]; | ||
expect(allowed).toBe(false); | ||
})); | ||
test("authorize wildcard allowed", () => __awaiter(void 0, void 0, void 0, function* () { | ||
const query = yield oso.experimental.authorizeLocal(bob, "read", environmentAny); | ||
const result = (yield kysely_1.sql.raw(query).execute(db)).rows.length; | ||
expect(result).toBeTruthy(); | ||
const query = yield oso.authorizeLocal(bob, "read", environmentAny); | ||
const { allowed } = (yield kysely_1.sql.raw(query).execute(db)) | ||
.rows[0]; | ||
expect(allowed).toBe(true); | ||
})); | ||
test("authorize always denied", () => __awaiter(void 0, void 0, void 0, function* () { | ||
const query = yield oso.experimental.authorizeLocal(bob, "frob", environmentAny); | ||
const result = (yield kysely_1.sql.raw(query).execute(db)).rows.length; | ||
expect(result).toBeFalsy(); | ||
const query = yield oso.authorizeLocal(bob, "frob", environmentAny); | ||
const { allowed } = (yield kysely_1.sql.raw(query).execute(db)) | ||
.rows[0]; | ||
expect(allowed).toBe(false); | ||
})); | ||
}); | ||
//# sourceMappingURL=kysely.test.js.map |
{ | ||
"name": "oso-cloud", | ||
"version": "1.5.0", | ||
"version": "1.6.0", | ||
"description": "Oso Cloud Node client", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
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
131275
1864