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

prime-sdk

v1.4.1

Published

swiss army knife

Downloads

365

Readme

Instalando pacote

yarn add prime-sdk

or

npm install prime-sdk

Queue (Sqs)

Install the module


@Module({
  imports: [
    QueueModule.forRoot({
      credentials: {
        accessKeyId: '000000000',
        secretAccessKey: '000000000',
      },
      endpoint: 'http://localhost:4566/',
      region: 'us-east-1',
    }),
  ],
  providers: [AppService],
  exports: [],
})
export class AppModule {}

example of usage


@Injectable()
export class AppService implements IConsumer {
  constructor(private readonly queueHandler: Queue) {
    this.queueHandler.handler({
      QueueUrl: `${'teste'}`,
      context: this,
      bulk: 1,
      waitTimeSeconds: 20,
    });
  }

  handleMessage(message: Message | Message[]): Promise<void> {
    console.log(message);
    return;
  }

  handleError(error: unknown): Promise<void> {
    console.log(error);
    return;
  }
}

Events (Sns)

Install the module


@Module({
  imports: [
    EventModule.forRoot({
      credentials: {
        accessKeyId: '000000000',
        secretAccessKey: '000000000',
      },
      endpoint: 'http://localhost:4566/',
      region: 'us-east-1',
    }),
  ],
  providers: [AppService],
  exports: [],
})
export class AppModule {}

example of usage


@Injectable()
export class AppService implements IConsumer {
  constructor(private readonly event: Events) {}

  public async trigger() {
    this.event.triggerEvent({
      topic: "arn:aws:sns:us-east-1:000000000000:teste-topic",
      message: 'teste',
    });
  }
}

Storage (S3)

Install the module


@Module({
  imports: [
    StorageModule.forRoot({
      credentials: {
        accessKeyId: '000000000',
        secretAccessKey: '000000000',
      },
      endpoint: 'http://localhost:4566/sample-bucket',
      region: 'us-east-1',
    })
  ],
  providers: [AppService],
  exports: [],
})
export class AppModule {}

Example of usage


@Injectable()
export class AppService implements IConsumer {
  constructor(private readonly storage: Storage) {}

  public async trigger() {

    const data = JSON.stringify({ teste: new Date().toISOString() });

    const file = Buffer.from(data, 'utf-8');

    this.storage.uploadFile({
      bucket: 'sample-bucket',
      file: file,
      nameFile: 'teste.txt',
      path: 'prime-sdk',
    });
  }
}

Cache (Redis)

  1. Install the module

  2. Define whether you are working with a Redis cluster (e.g., ElasticCache) or a simple Redis (e.g., Docker).

  3. Example of basic configuration :

3.1. Simple Redis:

CacheModule.forRoot({
      type: TypeRedis.SIMPLE,
      connection: {
        host: 'http://redis-service',
        port: 6379,
      },
      redisOptions: {
        password: '000000',
      },
    }),

3.2. Cluster Redis:

    CacheModule.forRoot({
      type: TypeRedis.CLUSTER,
      nodes: [
        {
          host: 'clustercfg.000-00000-cache.0000.use1.cache.amazonaws.com',
          port: 6379,
        },
      ],
      clusterOptions: {
        slotsRefreshTimeout: 3000,
        dnsLookup: (address, callback) => callback(null, address),
        redisOptions: {
          password: '00000',
          showFriendlyErrorStack: true,
          tls: {},
        },
      },
    }),
  1. Interfaces and Types:
enum TypeRedis {
  SIMPLE = 'simple',
  CLUSTER = 'cluster',
}

type Connection = {
  port: number;
  host: string;
};

type SimpleRedisSetup = {
  type: TypeRedis.SIMPLE;
  connection: Connection;
  redisOptions?: RedisOptions;
};

type ClusterRedisSetup = {
  type: TypeRedis.CLUSTER;
  nodes: Connection[];
  clusterOptions?: ClusterOptions;
};

interface ICache {
  set(
    key: string,
    value: Date | number | Buffer | string,
    ttl?: number,
  ): Promise<void>;

  get(key: string): Promise<string>;

  delete(key: string): Promise<void>;
}

For more information about RedisOptions and ClusterOptions, refer to the ioredis documentation:

https://www.npmjs.com/package/ioredis

  1. Example of usage
@Injectable()
export class AppService {
  constructor(@Inject(ICache) private readonly cache: ICache) {}

  async set( key: string,
    value: string | number | Date | Buffer,
    ttl?: number): Promise<void> {
    await this.cache.set(key, value, ttl);
  }

  async get(key: string): Promise<string> {
    return await this.cache.get(key);
  }

  async del(key: string): Promise<void> {
    return await this.cache.delete(key);
  }
}

Next steps

  • Interface for Class to facilite test