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

@hanmotec/flex-service-api

v0.0.4

Published

## 简述

Downloads

33

Readme

服务器端api

简述

FlexServiceAPI 是一个单例类,用于与后端服务进行交互。它提供了获取查询数据的方法,并使用 MD5 进行签名验证。通过 Axios 发送 HTTP 请求与后端通信。
这个库用于使用动态表单和查询的服务器端,通过引入这个库,可以调用动态表单服务,获取指定的动态查询语句,然后在项目中执行查询,获取符合条件的数据并返回给客户端。

安装

通过npm安装

npm i -D @anmed/flex-service-api

用法

初始化

在使用 FlexServiceAPI 之前,必须先进行初始化。调用 initialize 方法并传入端点、项目代码和密钥。


import FlexServiceAPI from "./FlexServiceAPI";


const endpoint = 'https://api.yourservice.com';
const projectCode = 'your_project_code';
const secretKey = 'your_secret_key';

// 初始化 FlexServiceAPI
FlexServiceAPI.initialize(endpoint, projectCode, secretKey);

获取实例

在初始化后,可以通过 getInstance 方法获取 FlexServiceAPI 的实例。

const api = FlexServiceAPI.getInstance();

获取查询数据

使用 getQuery 方法获取查询数据。

const tenantCode = 'your_tenant_code';
const queryCode = 'your_query_code';
const isTrial = true;

let query = api.getQuery(tenantCode, queryCode, isTrial);

方法

static initialize(endpoint: string, projectCode: string, secretKey: string): FlexServiceAPI

  • 初始化 FlexServiceAPI 的实例。
  • 参数:
    • endpoint (string): API 端点。
    • projectCode (string): 项目代码。
    • secretKey (string): 密钥。
  • 返回值:
    • FlexServiceAPI: 已初始化的 FlexServiceAPI 实例。

static getInstance(): FlexServiceAPI

  • 获取已初始化的 FlexServiceAPI 实例。
  • 返回值:
    • FlexServiceAPI: FlexServiceAPI 实例。

async getQuery(tenantCode: string, queryCode: string, isTrial: boolean): Promise

  • 获取查询数据。
  • 参数:
    • tenantCode (string): 租户代码。
    • queryCode (string): 查询代码。
    • isTrial (boolean): 是否为试用。
  • 返回值:
    • Promise: 查询数据。

私有方法

private buildQuery(className: string, query: string): any

  • 构建查询体。
  • 参数:
    • className (string): 类名。
    • query (string): 查询脚本。
  • 返回值:
    • any: 构建后的查询体。

注意事项

  • FlexServiceAPI 类是一个单例类,必须先调用 initialize 方法进行初始化,然后才能调用 getInstance 获取实例。
  • 初始化多次会抛出错误,确保只初始化一次。
  • 在使用任何方法之前,请确保已正确初始化 FlexServiceAPI。

结论

FlexServiceAPI 提供了一种便捷的方法来与后端服务进行交互。通过简单的初始化和方法调用,您可以轻松获取查询数据并确保数据的完整性和安全性。