@gofynd/fp-signature

中文文档
2.0.1发布于 2025/09/24ISCTypeScriptESM + CJS近 30 天下载 2.1万

Fynd platform's signature logic

原始使用文档
文档目录10 节
  1. Installation
  2. How to Use
  3. For CommonJS
  4. For ES Modules
  5. For Browser
  6. In Postman Prescript
  7. Functionality
  8. sign function
  9. RequestParam Object
  10. Example

FP-Signature

Fynd platform's signature logic

FP-Signature is a versatile npm package that provides signature logic for Fynd platform requests. This package supports both CommonJS and ES modules, and it also comes with a web bundle for direct usage in browsers.

Installation

You can install FP-Signature via npm:

npm install @gofynd/fp-signature

How to Use

For CommonJS

const { sign } = require("@gofynd/fp-signature");

For ES Modules

import { sign } from "@gofynd/fp-signature";

For Browser

<script src="https://cdn.jsdelivr.net/npm/@gofynd/fp-signature@{version}"></script>
<script>
    // FP-Signature library will be attached to the global window object
    FPSignature.sign();
</script>

In Postman Prescript

To use FP-Signature in Postman as a pre-script, include the postman_prescript.js file in the pre-script section of your Postman collection.

Change the FP-Signature package version within the pre-script according to your requirements.

Functionality

sign function

The sign function is used to generate a signature. It takes two parameters: request and options.

It will return the signature string directly.

The library generates a signature for your request. Include the returned signature string in the x-fp-signature header to sign the request.

Note: The x-fp-date timestamp is required for signature generation. You must include it in your request headers or query parameters. This timestamp helps prevent replay attacks and is used in the signature generation process. The timestamp should be in ISO 8601 format without colons, dashes, or milliseconds (e.g., 20240101T120000Z).

type RequestParam = {
  method: string;
  host?: string;
  port?: number;
  path?: string;
  headers?: any;
  body?: any;
  doNotEncodePath?: boolean;
  doNotModifyHeaders?: boolean; 
};

type SigningOptions = {
    secret: string;
}

function sign(request : RequestParam, options: SigningOptions) : string {}

RequestParam Object

The RequestParam object is used to configure the details of the HTTP request that needs to be signed.

Properties:

  • method: (string, required) - HTTP method for the request (e.g., "GET", "POST").

  • host: (string, optional) - The host of the server. Ex: developer.mozilla.org:4097, api.fyndx5.de

  • port: (number, optional) - The port number of the server.

  • path: (string, optional) - The path of the request URL with query parameters(if any).

  • headers: (object, optional) - Custom headers for the request. Exclude default headers like common, delete, get, head, post, put, patch. Note: The x-fp-date header is required for signature generation.

  • body: (any, optional) - The body of the request.

  • doNotEncodePath: (boolean, optional) - If true, the path will not be URL encoded.

  • doNotModifyHeaders: (boolean, optional) - If true, headers will not be modified during signing.

Example:

const requestToSign = {
    method: "GET",
    host: "api.fynd.com",
    path: "/service/application/configuration/v1.0/application?queryParam=value",
    headers: {
      Authorization: "Bearer <authorizationToken>",
      "x-currency-code": "INR",
      "x-fp-date": new Date().toISOString().replace(/[:\-]|\.\d{3}/g, "")
    },
};

Example

// For Common JS
// const {sign} = require("@gofynd/fp-signature")

// For ES Module
import {sign} from "@gofynd/fp-signature";

const requestToSign = {
  method: "GET",
  host: "api.fynd.com",
  path: "/service/application/configuration/v1.0/application",
  headers: {
    Authorization: "Bearer <authorizationToken>",
    "x-currency-code": "INR",
    "x-fp-date": new Date().toISOString().replace(/[:\-]|\.\d{3}/g, "")
  },
};

const signature = sign(requestToSign, { secret: 'your-secret-key' });

// Use the signature as needed - add to headers, query params, etc.
console.log('Generated signature:', signature);

版本与发布记录

@gofynd/fp-signature 共发布 10 个版本,首次发布于 2023/08/16;过去 12 个月发布了 0 个版本。

版本发布日期距今
2.0.1latest2025/09/241.1 年前
2.0.1-beta.02025/09/241.1 年前
2.0.02025/09/211.2 年前
1.0.22025/07/081.4 年前
1.0.12023/12/152 年前
1.0.02023/11/033 年前

关于 @gofynd/fp-signature 的常见问题

@gofynd/fp-signature 是什么?

Fynd platform's signature logic

如何安装 @gofynd/fp-signature?

在项目目录运行 npm install @gofynd/fp-signature,或使用 pnpm add / yarn add / bun add。

@gofynd/fp-signature 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@gofynd/fp-signature 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@gofynd/fp-signature 可以商用吗?

@gofynd/fp-signature 使用 ISC 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@gofynd/fp-signature 的下载量有多少?

根据 npm 官方下载统计,@gofynd/fp-signature 在 2026/10/17 – 2026/11/15 这 30 天内被下载 20,754 次,日均约 692 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@gofynd/fp-signature 还在维护吗?

最新版本 2.0.1 发布于 2025/09/24(1.1 年前);至今共发布 10 个版本,其中过去 12 个月发布了 0 个;首次发布于 2023/08/16。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。