2.12.4 • Published 4 months ago

itlab-internal-services v2.12.4

Weekly downloads
-
License
-
Repository
-
Last release
4 months ago

IT Lab Internal Services

Diese Library funktioniert nur mit NestJs

npm version install size npm downloads jsdelivr

Internal module

Axios is richly featured HTTP client package that is widely used. This package wraps Axios and exposes it via the built-in InternalModule. The InternalModule exports the CommentService, ContentService & SearchService classes, which exposes methods to perform HTTP requests to IT Labs internal services.

Installation

To begin using it, we first install the required dependency.

yarn add itlab-internal-services

Getting started

Once the installation process is complete, to use the InternalServices, first import InternalModule.

@Module({
  imports: [InternalModule],
  providers: [NewsService],
})
export class NewsModule {}

Next, inject CommentService, ContentService or SearchService using normal constructor injection.

Hint InternalModule, CommentService, ContentService & SearchService are imported from itlab-internal-services package.

@Injectable()
export class NewsService {
  constructor(
    private readonly commentService: CommentService,
    private readonly contentService: ContentService,
    private readonly searchService: SearchService,
  ) {}
}

Comment Service

async post(targetId: string, authorId: string, comment: Comment): Promise<Comment>
async delete(targetId: string): Promise<void>

Content Service

async verify(content: Content): Promise<void>
async post(targetId: string, content: Content): Promise<void>
async delete(targetId: string): Promise<void>

Pipes

@Controller("news")
export class NewsController {

  @ApiTarget("target")
  @Get(":target")
  getNews(@Target("target") target: string) {}

}
@Controller("news")
export class NewsController {

  @ApiHid("hid")
  @Get(":hid")
  getNews(@Hid("hid") hid: string) {}

}
@Controller("news")
export class NewsController {

  @ApiId("id")
  @Get(":id")
  getNews(@Id("id") id: string) {}

}

Guards

@Internal()
@Controller()
export class NewsController {}
@Jwt()
@Controller()
export class NewsController {
  @Get("")
  getNews(@Account() account: LAccount) {}

  @Get("")
  getNews(@AccountId() accountId: string) {}

  @Perms("perms.get", "perms.list")
  @Get("")
  getNews(@AccountId() accountId: string, @AccountPerms() accountPerms: string[]) {}
}

Configuration

To configure the underlying service instance, pass an optional options object to the register() method of InternalModule when importing it. This options object will be passed directly to the underlying service constructor.

@Module({
  imports: [
    InternalModule.register({
      target: Targets.NEWSROOM,
      token: 'itlab token',
      jwt_secret: 'secret',
    }),
  ],
  providers: [NewsService],
})
export class NewsModule {}

Async configuration

When you need to pass module options asynchronously instead of statically, use the registerAsync() method. As with most dynamic modules, this package provides several techniques to deal with async configuration.

One technique is to use a factory function:

InternalModule.registerAsync({
  useFactory: () => ({
    target: Targets.NEWSROOM,
    token: 'itlab token',
    jwt_secret: 'secret',
  }),
});

Like other factory providers, our factory function can be async and can inject dependencies through inject.

InternalModule.registerAsync({
  imports: [ConfigModule],
  useFactory: (configService: ConfigService) => ({
    target: Targets.NEWSROOM,
    token: configService.get<string>('K8S_TOKEN'),
    jwt_secret: configService.get<string>('JWT_SECRET'),
  }),
  inject: [ConfigService],
});

Alternatively, you can configure the InternalModule using a class instead of a factory, as shown below.

InternalModule.registerAsync({
  useClass: InternalConfigService,
});

The construction above instantiates InternalConfigService inside InternalModule, using it to create an options object. Note that in this example, the InternalConfigService has to implement InternalModuleOptionsFactory interface as shown below. The InternalModule will call the createInternalOptions() method on the instantiated object of the supplied class.

@Injectable()
class InternalConfigService implements InternalModuleOptionsFactory {
  createInternalOptions(): InternalModuleOptions {
    return {
      target: Targets.NEWSROOM,
      token: 'itlab token',
      jwt_secret: 'secret',
    };
  }
}

If you want to reuse an existing options provider instead of creating a private copy inside the InternalModule, use the useExisting syntax.

InternalModule.registerAsync({
  imports: [ConfigModule],
  useExisting: InternalConfigService,
});
2.11.0

6 months ago

2.11.1

6 months ago

2.9.2

8 months ago

2.11.4

5 months ago

2.11.2

6 months ago

2.11.3

5 months ago

2.10.1

8 months ago

2.10.2

8 months ago

2.10.10

6 months ago

2.10.0

8 months ago

2.10.9

6 months ago

2.10.7

6 months ago

2.10.8

6 months ago

2.10.5

7 months ago

2.10.6

7 months ago

2.10.3

7 months ago

2.10.4

7 months ago

2.12.0

5 months ago

2.12.3

4 months ago

2.12.4

4 months ago

2.12.1

5 months ago

2.12.2

4 months ago

2.9.1

8 months ago

2.8.1

9 months ago

2.8.0

9 months ago

2.7.0

11 months ago

2.9.0

9 months ago

2.7.1

9 months ago

2.6.7

11 months ago

2.6.1

12 months ago

2.6.0

12 months ago

2.6.3

12 months ago

2.6.2

12 months ago

2.5.2

1 year ago

2.5.1

1 year ago

2.5.3

1 year ago

2.6.5

11 months ago

2.6.4

11 months ago

2.4.6

1 year ago

2.6.6

11 months ago

2.4.5

1 year ago

2.4.3

1 year ago

2.4.4

1 year ago

2.4.2

1 year ago

2.4.1

1 year ago

2.4.0

1 year ago

2.3.0

1 year ago

2.2.1

1 year ago

2.2.0

1 year ago

2.2.2

1 year ago

2.1.2

1 year ago

2.1.1

1 year ago

2.1.0

1 year ago

2.0.2

2 years ago

2.0.1

2 years ago

2.0.0

2 years ago

1.13.6

2 years ago

1.13.5

2 years ago

1.13.4

2 years ago

1.13.3

2 years ago

1.13.8

2 years ago

1.13.7

2 years ago

1.12.2

2 years ago

1.12.1

2 years ago

1.12.0

2 years ago

1.9.5

2 years ago

1.9.4

2 years ago

1.9.3

2 years ago

1.9.2

2 years ago

1.11.0

2 years ago

1.13.2

2 years ago

1.13.1

2 years ago

1.13.0

2 years ago

1.11.2

2 years ago

1.11.1

2 years ago

1.9.1

2 years ago

1.9.0

2 years ago

1.10.1

2 years ago

1.10.0

2 years ago

1.8.1

2 years ago

1.6.3

2 years ago

1.8.0

2 years ago

1.6.2

2 years ago

1.7.0

2 years ago

1.6.1

2 years ago

1.6.0

2 years ago

1.2.0

2 years ago

1.5.3

2 years ago

1.4.4

2 years ago

1.5.2

2 years ago

1.4.3

2 years ago

1.5.1

2 years ago

1.4.2

2 years ago

1.5.0

2 years ago

1.4.1

2 years ago

1.4.0

2 years ago

1.3.1

2 years ago

1.2.2

2 years ago

1.3.0

2 years ago

1.2.1

2 years ago

1.1.4

3 years ago

1.1.3

3 years ago

1.1.2

3 years ago

1.1.1

3 years ago

1.1.0

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago

0.0.4

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago