curved-florist-98287
11/13/2023, 2:41 PMchilly-king-10285
11/13/2023, 2:41 PMchilly-king-10285
11/13/2023, 2:42 PMtypescript import { Namespace, Context } from "@ory/keto-namespace-types" class User implements Namespace {} class Group implements Namespace { related: { members: User[] } } class Merchant implements Namespace { related: { systemAdmins: Group[] } permits = { createMerchant: (ctx: Context): boolean => this.related.systemAdmins.includes(ctx.subject), } }
In this code, we have defined three namespaces: User
, Group
, and Merchant
. The Group
namespace has a relationship members
which is an array of User
. The Merchant
namespace has a relationship systemAdmins
which is an array of Group
. The Merchant
namespace also has a permits
property which defines the permissions for this namespace. In this case, we have a createMerchant
permission which is a function that takes a context containing the subject and returns a boolean value indicating whether the subject has this permission. The function checks if the subject is included in the systemAdmins
relationship of the Merchant
namespace. Please note that this is a basic example and you might need to adjust it according to your specific requirements and the actual structure of your application. For more information on how to use the Ory Permission Language (OPL), you can refer to the [Ory Documentation](https://www.ory.sh/docs/keto/reference/ory-permission-language).curved-florist-98287
11/13/2023, 2:46 PM