open-index/open-npm huggingface dataset:
npm package: @getlarge/hydra-client-wrapper
Description: NestJS Module wrapper for the Ory Hydra API
Author: Edouard Maleix
Latest version: 0.4.0

# hydra-client-wrapper

[![npm][npm-image]][npm-url]

[npm-image]: https://img.shields.io/npm/v/@getlarge/hydra-client-wrapper.svg?style=flat
[npm-url]: https://npmjs.org/package/@getlarge/hydra-client-wrapper

This library is a wrapper around the [Ory Hydra](https://www.ory.sh/hydra/docs/) client - [@ory/client](https://github.com/ory/client-js). It provides :

- `OryOidcModule`: a module to interact with the Ory Hydra Oidc (public) API
- `OryOAuth2Module`: a module to interact with the Ory Hydra OAuth2 (admin) API

## Install

```sh
npm install @getlarge/hydra-client-wrapper
```

## Usage

Import the module in your app:

```ts
import {
  OryIdentitiesModule,
  OryFrontendModule,
} from '@getlarge/kratos-client-wrapper';
import { Module } from '@nestjs/common';

@Module({
  imports: [
    OryIdentitiesModule.forRoot({
      basePath: 'http://localhost:4434',
      accessToken: 'my-access-token',
    }),
    OryFrontendModule.forRootAsync({
      useFactory: () => ({
        baseUrl: 'http://localhost:4433',
      }),
    }),
  ],
})
export class YourModule {}
```

Inject the service in your provider:

```ts
import { OryOAuth2Service } from '@getlarge/hydra-client-wrapper';
import { Injectable } from '@nestjs/common';

@Injectable()
export class YourService {
  constructor(private readonly oryOAuth2Service: OryOAuth2Service) {}

  async createClient(ownerId: string, scope = 'offline') {
    return this.oryOAuth2Service.createOAuth2Client({
      oAuth2Client: {
        grant_types: ['client_credentials'],
        access_token_strategy: 'opaque',
        owner: ownerId,
        scope,
      },
    });
  }
}
```

Use the Guard to protect your routes:

```ts
import { OryOAuth2AuthenticationGuard } from '@getlarge/hydra-client-wrapper';
import { Controller, Get, Logger, UseGuards } from '@nestjs/common';

@Controller()
export class YourController {
  @UseGuards(
    OryOAuth2AuthenticationGuard({
      async postValidationHook(ctx, token) {
        const req = ctx.switchToHttp().getRequest();
        if (!token.client_id) {
          throw new Error('Client ID not found in token');
        }
        const { data: client } = await this.oryService.getOAuth2Client({
          id: token.client_id,
        });
        req.client = client;
      },
      accessTokenResolver: (ctx) =>
        ctx
          .switchToHttp()
          .getRequest()
          ?.headers?.authorization?.replace('Bearer ', ''),
    })
  )
  @Get()
  async get() {
    return 'Hello World';
  }
}
```

## Development

### Building

Run `nx build hydra-client-wrapper` to build the library.

### Running unit tests

Run `nx test hydra-client-wrapper` to execute the unit tests via [Jest](https://jestjs.io).
npm package: @getlarge/keto-cli
Description: CLI wrapper for the Ory Keto API
Author: Edouard Maleix
Latest version: 0.2.13

# keto-cli

[![npm][npm-image]][npm-url]

[npm-image]: https://img.shields.io/npm/v/@getlarge/keto-cli.svg?style=flat
[npm-url]: https://npmjs.org/package/@getlarge/keto-cli

This CLI interacts with the [Ory Keto](https://www.ory.sh/keto/docs/) API.

## Install

```sh
npm install @getlarge/keto-cli
```

## Usage

### To check if a permission is granted

```sh
# base path is the Ory Keto Public API URL - it can be passed via ORY_KETO_PUBLIC_URL environment variable
npx @getlarge/keto-cli check --tuple Group:admin#members@User:1 \
--basePath http://localhost:4466
```

### To create a relationship

```sh
# base path is the Ory Keto Admin API URL - it can be passed via ORY_KETO_PUBLIC_URL environment variable
# access token is the Ory Keto Admin API access token - it should be passed via ORY_KETO_API_KEY environment variable
npx @getlarge/keto-cli create --tuple Group:admin#members@User:1 \
--basePath http://localhost:4467 --accessToken my-access-token
```

### To delete a relationship

```sh
# base path is the Ory Keto Admin API URL - it can be passed via ORY_KETO_PUBLIC_URL environment variable
# access token is the Ory Keto Admin API access token - it should be passed via ORY_KETO_API_KEY environment variable
npx @getlarge/keto-cli delete --tuple Group:admin#members@User:1 \
--basePath http://localhost:4467 --accessToken my-access-token
```

### To expand a relation tuple

```sh
npx @getlarge/keto-cli expand --tuple Group:admin#members --depth 2 \
--basePath http://localhost:4466
```

### To list all relationships

```sh
# base path is the Ory Keto Admin API URL - it can be passed via ORY_KETO_PUBLIC_URL environment variable
# access token is the Ory Keto Admin API access token - it should be passed via ORY_KETO_API_KEY environment variable
npx @getlarge/keto-cli get --namespace Group --object admin \
--basePath http://localhost:4467 --accessToken my-access-token
```

## Development

### Building

Run `nx build keto-cli` to build the library.

### Running unit tests

Run `nx test keto-cli` to execute the unit tests via [Jest](https://jestjs.io).
npm package: @getlarge/keto-client-wrapper
Description: NestJS Module wrapper for the Ory Keto API
Author: Edouard Maleix
Latest version: 0.7.0

# keto-client-wrapper

[![npm][npm-image]][npm-url]

[npm-image]: https://img.shields.io/npm/v/@getlarge/keto-client-wrapper.svg?style=flat
[npm-url]: https://npmjs.org/package/@getlarge/keto-client-wrapper

This library is a wrapper around the [Ory Keto](https://www.ory.sh/keto/docs/) client - [@ory/client](https://github.com/ory/client-js). It provides :

- `OryRelationshipsModule`: a module to interact with the Ory Keto Relationships API
- `OryPermissionsModule`: a module to interact with the Ory Keto Permissions API
- `OryAuthorizationGuard`: a guard to protect your routes based on the Ory Keto permissions

## Install

```sh
npm install @getlarge/keto-client-wrapper
```

## Usage

Import the module in your app:

```ts
import {
  OryRelationshipsModule,
  OryPermissionsModule,
} from '@getlarge/keto-client-wrapper';
import { Module } from '@nestjs/common';

@Module({
   imports: [
    OryRelationshipsModule.forRoot({
      basePath: 'http://localhost:4467',
      accessToken: 'my-access-token',
    }),
    OryPermissionsModule.forRootAsync({
      useFactory: () => ({
        baseUrl: 'http://localhost:4466',
      }),
    }),
  ],
})

```

Inject the service in your provider:

```ts
import { OryRelationshipsService } from '@getlarge/keto-client-wrapper';
import { Injectable } from '@nestjs/common';

@Injectable()
export class YourService {
  constructor(
    private readonly oryRelationshipsService: OryRelationshipsService
  ) {}
}
```

Use the Guard to protect your routes:

```ts
import {
  OryAuthorizationGuard,
  OryPermissionChecks,
} from '@getlarge/keto-client-wrapper';
import { RelationTupleBuilder } from '@getlarge/keto-relations-parser';
import { Controller, Get, Logger, UseGuards } from '@nestjs/common';

@Controller()
export class YourController {
  @OryPermissionChecks((ctx) => {
    const req = ctx.switchToHttp().getRequest();
    const currentUserId = req.headers['x-current-user-id'] as string;
    const resourceId = req.params.id;
    return new RelationTupleBuilder()
      .subject('User', currentUserId)
      .isIn('owners')
      .of('Toy', resourceId)
      .toString();
  })
  @UseGuards(
    OryAuthorizationGuard({
      postCheck(relationTuple, isPermitted) {
        Logger.log('relationTuple', relationTuple);
        Logger.log('isPermitted', isPermitted);
      },
    })
  )
  @Get()
  getArticles() {
    return 'Articles';
  }
}
```

## Development

### Building

Run `nx build keto-client-wrapper` to build the library.

### Running unit tests

Run `nx test keto-client-wrapper` to execute the unit tests via [Jest](https://jestjs.io).
npm package: @getlarge/keto-relations-parser
Description: A parser for Ory Keto relation policies
Author: Edouard Maleix
Latest version: 0.0.13

# keto-relations-parser

[![npm][npm-image]][npm-url]

[npm-image]: https://img.shields.io/npm/v/@getlarge/keto-relations-parser.svg?style=flat
[npm-url]: https://npmjs.org/package/@getlarge/keto-relations-parser

This library can parse a string representation of a Relation tuple to an object structure in typescript.
It is a fork of the [relation-tuple-parser](https://github.com/nidomiro/relation-tuple-parser/tree/main) library which uses Regular Expressions to parse the string instead of Antlr4 and provides a fluent API to create a Relation tuple.

Relation tuples are used to evaluate permissions in "Zanzibar: Google's Consistent, Global Authorization System".

The BNF of a valid Relation tuple is as follows:

```bnf
<relation-tuple> ::= <object>'#'relation'@'<subject> | <object>'#'relation'@('<subject>')'
<object> ::= namespace':'object_id
<subject> ::= subject_id | <subject_set>
<subject_set> ::= <object>'#'relation
```

## Examples of valid strings

```text
Project:123#owners@User:321
Project:123#editors@Group:admin#members
Group:admin#members@321
```

Which can be verbalized as :

```text
User:123 is owner of Project:123
members of Group:admin are editors of Project:123
321 is member of Group:admin
```

Which can be parsed to the following object structure:

```json
{
  "namespace": "Project",
  "objecy": "123",
  "relation": "owners",
  "subject": {
    "namespace": "User",
    "object": "321"
  }
}
```

```json
{
  "namespace": "Project",
  "id": "123",
  "relation": "editors",
  "subject": {
    "namespace": "Group",
    "object": "admin",
    "relation": "members"
  }
}
```

```json
{
  "namespace": "Group",
  "id": "admin",
  "relation": "members",
  "subject": "321"
}
```

## Install

```sh
npm install @getlarge/keto-relations-parser
```

## Usage

Parse a string to a RelationTuple object:

```ts
import { RelationTupleBuilder } from '@getlarge/keto-relations-parser';

const relationTuple = RelationTupleBuilder.fromString(
  'Project:123#owners@User:321'
);
```

Parse a relation tuple object to a string:

```ts
import { RelationTuple } from '@getlarge/keto-relations-parser';

const relationTuple = new RelationTuple('Project', '123', 'owners', {
  namespace: 'User',
  object: '321',
}).toString();
```

Create a relation tuple using Fluent API:

```ts
import { RelationTupleBuilder } from '@getlarge/keto-relations-parser';

new RelationTupleBuilder()
  .subject('User', '321')
  .isIn('owners')
  .of('Project', '321')
  .toString();
```

## Development

### Building

Run `nx build keto-relations-parser` to build the library.

### Running unit tests

Run `nx test keto-relations-parser` to execute the unit tests via [Jest](https://jestjs.io).
npm package: @getlarge/kratos-cli
Description: CLI wrapper for the Ory Kratos API
Author: Edouard Maleix
Latest version: 0.3.6

# kratos-cli

[![npm][npm-image]][npm-url]

[npm-image]: https://img.shields.io/npm/v/@getlarge/keto-cli.svg?style=flat
[npm-url]: https://npmjs.org/package/@getlarge/keto-cli

This CLI interacts with the [Ory Kratos](https://www.ory.sh/kratos/docs/) self-service API.

## Install

```sh
npm install @getlarge/kratos-cli
```

## Usage

### To register a new identity

```sh
# base path is the Ory Kratos Public API URL - it can be passed via ORY_KRATOS_PUBLIC_URL environment variable
# the CLI will prompt for the password
npx @getlarge/kratos-cli register --email test@test.it \
--basePath http://localhost:4433
```

### To log in

```sh
# base path is the Ory Kratos Public API URL - it can be passed via ORY_KRATOS_PUBLIC_URL environment variable
# the CLI will prompt for the password
npx @getlarge/kratos-cli login --email test@test.it \
--basePath http://localhost:4433
```

## Development

### Building

Run `nx build kratos-cli` to build the library.

### Running unit tests

Run `nx test kratos-cli` to execute the unit tests via [Jest](https://jestjs.io).
npm package: @getlarge/kratos-client-wrapper
Description: NestJS Module wrapper for the Ory Kratos API
Author: Edouard Maleix
Latest version: 0.3.0

# kratos-client-wrapper

[![npm][npm-image]][npm-url]

[npm-image]: https://img.shields.io/npm/v/@getlarge/kratos-client-wrapper.svg?style=flat
[npm-url]: https://npmjs.org/package/@getlarge/kratos-client-wrapper

This library is a wrapper around the [Ory Kratos](https://www.ory.sh/kratos/docs/) client - [@ory/client](https://github.com/ory/client-js). It provides :

- `OryIdentitiesModule`: a module to interact with the Ory Kratos Identities API
- `OryFrontendModule`: a module to interact with the Ory Kratos Frontend API
- `OryAuthenticationGuard`: a guard to protect your routes based on the Ory Kratos session

## Install

```sh
npm install @getlarge/kratos-client-wrapper
```

## Usage

Import the module in your app:

```ts
import {
  OryIdentitiesModule,
  OryFrontendModule,
} from '@getlarge/kratos-client-wrapper';
import { Module } from '@nestjs/common';

@Module({
  imports: [
    OryIdentitiesModule.forRoot({
      basePath: 'http://localhost:4434',
      accessToken: 'my-access-token',
    }),
    OryFrontendModule.forRootAsync({
      useFactory: () => ({
        baseUrl: 'http://localhost:4433',
      }),
    }),
  ],
})
export class YourModule {}
```

Inject the service in your provider:

```ts
import { OryIdentitiesService } from '@getlarge/kratos-client-wrapper';
import { Injectable } from '@nestjs/common';

@Injectable()
export class YourService {
  constructor(private readonly oryIdentitiesService: OryIdentitiesService) {}
}
```

Use the Guard to protect your routes:

```ts
import { OryAuthenticationGuard } from '@getlarge/kratos-client-wrapper';
import { Controller, Get, Logger, UseGuards } from '@nestjs/common';

@Controller()
export class YourController {
  @UseGuards(
    OryAuthenticationGuard({
      postValidationHook: (ctx, session) => {
        const req = ctx.switchToHttp().getRequest();
        req.session = session;
        req.user = session.identity;
      },
      isValidSession(session): boolean {
        return !!session.active;
      },
      sessionTokenResolver: (ctx) =>
        ctx
          .switchToHttp()
          .getRequest()
          ?.headers?.authorization?.replace('Bearer ', ''),
    })
  )
  @Get()
  async get() {
    return 'Hello World';
  }
}
```

## Development

### Building

Run `nx build kratos-client-wrapper` to build the library.

### Running unit tests

Run `nx test kratos-client-wrapper` to execute the unit tests via [Jest](https://jestjs.io).