0.0.4 • Published 12 months ago

ww-gtmp-wallet v0.0.4

Weekly downloads
-
License
UNLICENSED
Repository
-
Last release
12 months ago

Digital-Wallet is a SDK help connect db and process action related wallet, items, currency,..

Update package and publish

npm login
npm run build
cd ./dist
npm publish

Note

  • Node version: >= 16. Recommended 18.20.2

Features

  • checkHealth(): Promise
  • createCurrency(data: ICurrencyCreate): Promise
  • updateCurrency(data: ICurrencyUpdate): Promise
  • queryCurrency(data: ICurrencyQuery): Promise
  • getCurrency(payload: ICurrencyDetail): Promise
  • createExchangeConfig(data: IExchangeConfigCreate): Promise
  • updateExchangeConfig(data: IExchangeConfigUpdate): Promise
  • queryExchangeConfig(data: IExchangeConfigQuery): Promise
  • getDetailExchangeConfig(payload: IExchangeConfigDetail): Promise
  • createItem(data: IItemCreate): Promise
  • updateItem(data: IItemUpdate): Promise
  • getDetailItem(payload: IItemDetail): Promise
  • queryItem(data: IItemQuery): Promise
  • consumeItem(data: IItemConsume): Promise
  • createUserItem(data: IUserItemCreate): Promise
  • updateUserItem(data: IUserItemUpdate): Promise
  • queryUserItem(data: IUserItemQuery): Promise
  • createWalletTransaction(data: ITransactionCreate): Promise
  • rollbackWalletTransaction(data: ITransactionRollback): Promise
  • exchangeCurrencyTransaction(data: IExchangeCurrency): Promise
  • getUserBalanceByCurrency(data: IGetBalanceUserCurrency): Promise
  • getUserBalance(payload: IGetAllBalanceUser): Promise
  • queryTransaction(payload: ITransactionQuery): Promise
  • createItemPrice(data: IItemPriceCreate): Promise
  • updateItemPrice(data: IItemPriceUpdate): Promise And more...

Install

add dependency in package.json file

Usage in NestJS

import { DigitalWalletModule } from "packageName";

@Module({
  imports: [
    DigitalWalletModule.forRoot({
      // config when use inapp-purchase
      // optional
      sequelizeConfigs: {
        // "mysql" | "postgres" | "sqlite" | "mariadb" |..
        dialect: "postgres",
        host: "host",
        port: "port",
        username: "username",
        password: "password",
        database: "database",
        logging: false,
        timezone: "+07:00",
      },

      // config when use inapp-purchase
      // optional
      googleCloudServiceConfigs: {
        clientEmail: "string",
        privateKey: "string",
      },
      // optional
      googlePlayConfigs: {
        googlePublicKeyPath: "string",
        googlePublicKeyStrSandBox: "string",
        googlePublicKeyStrLive: "string",
      },
      // optional
      appleStoreConfigs: {
        password: "string",
      },
    }),
  ],
  controllers: [],
  providers: [],
})
export class AppModule {}

And using, inject your service:

import { DigitalWalletService } from "packageName";

@Injectable()
export class AppService {
  constructor(private readonly digitalWalletService: DigitalWalletService) {}

  async checkHealth() {
    return await this.digitalWalletService.checkHealth();
  }
}

Configuration

export interface AppleStoreConfigs {
  password: string;
}

export interface GoogleCloudSericeConfigs {
  clientEmail: string;
  privateKey: string;
}

export interface GooglePlayConfigs {
  googlePublicKeyPath: string;
  googlePublicKeyStrSandBox?: string;
  googlePublicKeyStrLive?: string;
}

export interface DigitalWalletConfigOptions {
  sequelizeConfigs: SequelizeConfigOptions;
  googleCloudServiceConfigs?: GoogleCloudSericeConfigs;
  googlePlayConfigs?: GooglePlayConfigs;
  appleStoreConfigs?: AppleStoreConfigs;
}

export type Dialect =
  | "mysql"
  | "postgres"
  | "sqlite"
  | "mariadb"
  | "mssql"
  | "mariadb";

export interface SequelizeConfigOptions {
  /**
   * The dialect of the database you are connecting to. One of mysql, postgres, sqlite, mariadb and mssql.
   *
   * @default 'mysql'
   */
  dialect?: Dialect;

  /**
   * The name of the database
   */
  database?: string;

  /**
   * The username which is used to authenticate against the database.
   */
  username?: string;

  /**
   * The password which is used to authenticate against the database.
   */
  password?: string;

  /**
   * The host of the relational database.
   *
   * @default 'localhost'
   */
  host?: string;

  /**
   * The port of the relational database.
   */
  port?: number;

  /**
   * The timezone used when converting a date from the database into a JavaScript date. The timezone is also
   * used to SET TIMEZONE when connecting to the server, to ensure that the result of NOW, CURRENT_TIMESTAMP
   * and other time related functions have in the right timezone. For best cross platform performance use the
   * format
   * +/-HH:MM. Will also accept string versions of timezones used by moment.js (e.g. 'America/Los_Angeles');
   * this is useful to capture daylight savings time changes.
   *
   * @default '+00:00'
   */
  timezone?: string;

  /**
   * A function that gets executed while running the query to log the sql.
   */
  logging?: boolean | ((sql: string, timing?: number) => void);
}