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

@gofynd/fp-signature

v1.0.1

Published

Fynd platform's signature logic

Downloads

8,707

Readme

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 Signature object with x-fp-date and x-fp-signature.

Include the generated x-fp-date and x-fp-signature in the request headers or query parameters to sign the request.

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

type SigningOptions = {
    secret?: string;
    signQuery?: boolean;
}

type Signature = {
    "x-fp-signature": string;
    "x-fp-date": string;
}

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

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.

  • 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"
    },
};

Signature Placement

The placement of the signature (x-fp-signature) in the request is determined by the options.signQuery property:

  • If options.signQuery is true, the x-fp-signature will be generated to use in query parameter.
  • If options.signQuery is false, the x-fp-signature will be generated to use in headers.

Example

Signature to add in header

// 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"
  },
};

const signature = sign(requestToSign);

const res = axios.get("http://api.fynd.com/service/application/configuration/v1.0/application", {
  headers: {
    Authorization: "Bearer <authorizationToken>",
    "x-currency-code": "INR",
    "x-fp-signature": signature["x-fp-signature"],
    "x-fp-date": signature["x-fp-date"]
  }
});

Signature to add in query

// 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"
  },
};

const signature = sign(requestToSign, {
  signQuery: true
});

const res = axios.get("http://api.fynd.com/service/application/configuration/v1.0/application", {
  params: {
    "x-fp-signature": signature["x-fp-signature"],
    "x-fp-date": signature["x-fp-date"]
  },
  headers: {
    Authorization: "Bearer <authorizationToken>",
    "x-currency-code": "INR"
  }
});