Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@
"axios": "^0.21.2"
},
"devDependencies": {
"@warrantdev/warrant-node": "^3.0.0",
"clean-webpack-plugin": "^4.0.0-alpha.0",
"mocha": "^10.2.0",
"ts-loader": "^9.2.3",
"typescript": "^4.3.4",
"webpack": "^5.41.1",
"webpack-cli": "^4.7.2",
"xmlhttprequest": "^1.8.0"
"xmlhttprequest": "^1.8.0",
"@warrantdev/warrant-node": "^3.2.0"
}
}
9 changes: 5 additions & 4 deletions src/WarrantClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Check, {
} from "./types/Check";
import Permission from "./types/Permission";
import ApiClient from "./HttpClient";
import { isWarrantObject } from "./types/WarrantObject";

export default class WarrantClient {
private readonly config: Config;
Expand All @@ -29,8 +30,8 @@ export default class WarrantClient {
data: {
op: CheckOp.AnyOf,
warrants: [{
objectType: check.object.getObjectType(),
objectId: check.object.getObjectId(),
objectType: isWarrantObject(check.object) ? check.object.getObjectType() : check.object.objectType,
objectId: isWarrantObject(check.object) ? check.object.getObjectId() : check.object.objectId,
relation: check.relation,
context: check.context,
}],
Expand All @@ -47,8 +48,8 @@ export default class WarrantClient {
data: {
op: check.op,
warrants: check.warrants.map((warrant: CheckWarrant) => ({
objectType: warrant.object.getObjectType(),
objectId: warrant.object.getObjectId(),
objectType: isWarrantObject(warrant.object) ? warrant.object.getObjectType() : warrant.object.objectType,
objectId: isWarrantObject(warrant.object) ? warrant.object.getObjectId() : warrant.object.objectId,
relation: warrant.relation,
context: warrant.context,
})),
Expand Down
4 changes: 2 additions & 2 deletions src/types/Check.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import Context from "./Context";
import WarrantObject from "./WarrantObject";
import WarrantObject, { WarrantObjectLiteral } from "./WarrantObject";

export enum CheckOp {
AllOf = "allOf",
AnyOf = "anyOf",
}

export interface CheckWarrant {
object: WarrantObject;
object: WarrantObject | WarrantObjectLiteral;
relation: string;
context?: Context;
}
Expand Down
9 changes: 9 additions & 0 deletions src/types/WarrantObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,12 @@ export default interface WarrantObject {
getObjectType(): string;
getObjectId(): string;
}

export interface WarrantObjectLiteral {
objectType: string;
objectId: string;
}

export function isWarrantObject(object: any): object is WarrantObject {
return object.getObjectType !== undefined && object.getObjectId !== undefined;
}
10 changes: 8 additions & 2 deletions test/LiveTest.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,20 @@ describe.skip('Live Test', function () {

it('check', async function () {
let authorized = await this.warrant.check({
object: this.role,
object: {
objectType: this.role.getObjectType(),
objectId: this.role.roleId,
},
relation: "member",
subject: this.user,
});
assert(authorized);

authorized = await this.warrant.check({
object: this.role,
object: {
objectType: this.role.getObjectType(),
objectId: this.role.roleId,
},
relation: "owner",
subject: this.user,
});
Expand Down