JSPM

nestjs-admanager

1.0.13
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 4
  • Score
    100M100P100Q38257F
  • License MIT

Package Exports

  • nestjs-admanager
  • nestjs-admanager/dist/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (nestjs-admanager) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Nestjs-AdManager

npm nestjs-admanager

Description

nestjs-admanager is an npm package that facilitates the integration of NestJS projects with the Google Ad Manager API. It provides a simplified interface for authentication, ad unit management, and other functionalities available in the API, allowing you to build robust applications quickly and efficiently.

Installation

You can install the package using npm:

npm install nestjs-admanager

Or using yarn:

yarn add nestjs-admanager

Configuration

Before using nestjs-admanager, you need to configure access credentials for the Google Ad Manager API.

Synchronous Configuration with forRoot

If you have the credentials available at initialization, you can configure the module synchronously:

// app.module.ts

import { Module } from '@nestjs/common';
import { AdManagerModule } from 'nestjs-admanager';

@Module({
  imports: [
    AdManagerModule.forRoot({
      network_code: 'YOUR_NETWORK_CODE',
      application_name: 'YOUR_APPLICATION_NAME',
      keys: {
        web: {
          client_id: 'YOUR_CLIENT_ID',
          client_secret: 'YOUR_CLIENT_SECRET',
          redirect_uris: ['YOUR_REDIRECT_URI'],
        },
      },
    }),
  ],
})
export class AppModule {}

Asynchronous Configuration with forRootAsync

If you need to load the credentials asynchronously, use the forRootAsync method:

// app.module.ts

import { Module } from '@nestjs/common';
import { AdManagerModule } from 'nestjs-admanager';
import { ConfigModule, ConfigService } from '@nestjs/config';

@Module({
  imports: [
    ConfigModule.forRoot(),
    AdManagerModule.forRootAsync({
      imports: [ConfigModule],
      inject: [ConfigService],
      useFactory: async (configService: ConfigService) => {
        return {
          network_code: configService.get<string>('NETWORK_CODE'),
          application_name: configService.get<string>('APPLICATION_NAME'),
          keys: {
            web: {
              client_id: configService.get<string>('CLIENT_ID'),
              client_secret: configService.get<string>('CLIENT_SECRET'),
              redirect_uris: [configService.get<string>('REDIRECT_URI')],
            },
          },
        };
      },
    }),
  ],
})
export class AppModule {}

Usage

After configuring the module, you can inject the AdManagerService into your services or controllers.

Authentication

// auth.service.ts

import { Injectable } from '@nestjs/common';
import { AdManagerService } from 'nestjs-admanager';

@Injectable()
export class AuthService {
  constructor(private readonly adManagerService: AdManagerService) {}

  getAuthUrl(): string {
    return this.adManagerService.generateAuthUrl();
  }

  async authenticate(code: string): Promise<void> {
    const token = await this.adManagerService.getToken(code);
    // Save the token for future use
  }
}

Ad Unit Management

// adunit.service.ts

import { Injectable } from '@nestjs/common';
import { AdManagerService } from 'nestjs-admanager';

@Injectable()
export class AdUnitService {
  constructor(private readonly adManagerService: AdManagerService) {}

  async getAdUnits(): Promise<any> {
    return await this.adManagerService.getAdUnits();
  }
}

License

This project is licensed under the GNU General Public License v3.0 or later. See the LICENSE file for details.

Author

References

Acknowledgments

We would like to thank everyone who contributed to this project and the open-source community for their continued support.

Disclaimer

This project is not affiliated, associated, authorized, endorsed by, or in any way officially connected with Google or any of its subsidiaries or affiliates. The names Google and Google Ad Manager, as well as related names, trademarks, and images, are registered trademarks of their respective owners.