npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

nestjs-amo

v0.1.0

Published

Wrapper over the @shevernitskiy/amo library for interacting with the amoCRM API from a NestJS application.

Downloads

608

Readme

Introduction

This is a simple wrapper of @shevernitskiy/amo library. With this module you can interact with the amoCRM/Kommo API from a NestJS application.

Installation

# npm
npm install nestjs-amo

# yarn
yarn add nestjs-amo

Furthermore, install @shevernitskiy/amo in your NestJS application, if you haven't already.

# npm
npm install @shevernitskiy/amo

# yarn
yarn add @shevernitskiy/amo

Usage

Add AmoModule to the imports section in your AppModule or other modules to gain access to AmoService.

Static import

import { Module } from "@nestjs/common";
import { AmoModule } from "nestjs-amo";

@Module({
	imports: [
		AmoModule.forRoot({
			isGlobal: true,
			amoServiceOptions: {
				widget_settings: {
					client_id: "1111-2222-3333",
					client_secret: "myclientsecret",
					redirect_uri: "https://myredirect.org",
				},
				getCredentials: async (amoId) => {
					// Implement your logic to retrieve a token from your long-term storage facility
					return {
						access_token: "some token",
						expires_at: 86400,
						expires_in: 1693211983,
						refresh_token: "saved token",
						domain: "https://example.ru",
					};
				},
				onTokenUpdate: async (amoId, token) => {
					// Implement your logic for saving authorization keys to long-term storage
					console.log("New token obtained", amoId, token);
				},
			},
		}),
	],
})
export class AppModule {}

Additionally, AmoModule provides a forRootAsync to pass options asynchronously.

Async configuration

import { Module } from "@nestjs/common";
import { AmoModule } from "nestjs-amo";

@Module({
	imports: [
		AmoModule.forRootAync({
			isGlobal: true,
			useFactory: async () => {
				return {
					widget_settings: {
						client_id: "1111-2222-3333",
						client_secret: "myclientsecret",
						redirect_uri: "https://myredirect.org",
					},
					getCredentials: async (amoId) => {
						// Implement your logic to retrieve a token from your long-term storage facility
						return {
							access_token: "some token",
							expires_at: 86400,
							expires_in: 1693211983,
							refresh_token: "saved token",
							domain: "https://example.ru",
						};
					},
					onTokenUpdate: async (amoId, token) => {
						// Implement your logic for saving authorization keys to long-term storage
						console.log("New token obtained", amoId, token);
					},
				};
			},
		}),
	],
})
export class AppModule {}

You can inject dependencies such as ConfigModule to load options from .env files.

import { Module } from "@nestjs/common";
import { ConfigModule, ConfigService } from "@nestjs/config";
import { AmoModule } from "nestjs-amo";

@Module({
	imports: [
		ConfigModule.forRoot({
			isGlobal: true,
		}),
		AmoModule.forRootAync({
			isGlobal: true,
			useFactory: async (configService: ConfigService) => {
				return {
					widget_settings: {
						client_id: configService.get("AMO_CLIENT_ID"),
						client_secret: configService.get("AMO_CLIENT_SECRET"),
						redirect_uri: configService.get("AMO_REDIRECT_URI"),
					},
					getCredentials: async (amoId) => {
						// Implement your logic to retrieve a token from your long-term storage facility
						return {
							access_token: "some token",
							expires_at: 86400,
							expires_in: 1693211983,
							refresh_token: "saved token",
							domain: "https://example.ru",
						};
					},
					onTokenUpdate: async (amoId, token) => {
						// Implement your logic for saving authorization keys to long-term storage
						console.log("New token obtained", amoId, token);
					},
				};
			},
			inject: [ConfigService],
		}),
	],
})
export class AppModule {}

Calling send method

import { AmoService } from "nestjs-amo";

@Injectable()
export class YourService {
	constructor(private amoService: AmoService) {}

	async method() {
		const amoApi = await this.amoService.create(123);
		return amoApi.account.getAccount({ with: ["version"] });
	}
}

Calling custom endpoint

import { AmoService } from "nestjs-amo";

@Injectable()
export class YourService {
	constructor(private amoService: AmoService) {}

	async method() {
		const amoApi = await this.amoService.create(123);
		return amoApi.raw.get({
			url: "/ajax/merge/leads/save",
			headers: {
				"X-Requested-With": "XMLHttpRequest",
			},
			payload: "some payload",
		});
	}
}

Contributing

Contributions welcome! See Contributing.

Notes

This project is not endorsed by or affiliated with AmoCRM.

Author

Yaroslav Tolstoy - GitHub

License

Licensed under the MIT License - see the LICENSE file for details.