UNPKG

@fgiova/aws-signature

Version:

[![NPM version](https://img.shields.io/npm/v/@fgiova/aws-signature.svg?style=flat)](https://www.npmjs.com/package/@fgiova/aws-signature) ![CI workflow](https://github.com/fgiova/aws-signature/actions/workflows/node.js.yml/badge.svg) [![TypeScript](https:/

31 lines (30 loc) 1.1 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getCanonicalQuery = getCanonicalQuery; const constants_1 = require("./constants"); const utils_1 = require("./utils"); function getCanonicalQuery({ query = {} }) { const keys = []; const serialized = {}; for (const key of Object.keys(query).sort()) { if (key.toLowerCase() === constants_1.SIGNATURE_HEADER) { continue; } keys.push(key); const value = query[key]; if (typeof value === "string") { serialized[key] = `${(0, utils_1.escapeUri)(key)}=${(0, utils_1.escapeUri)(value)}`; } else if (Array.isArray(value)) { serialized[key] = value .slice(0) .reduce((encoded, value) => encoded.concat([`${(0, utils_1.escapeUri)(key)}=${(0, utils_1.escapeUri)(value)}`]), []) .sort() .join("&"); } } return keys .map((key) => serialized[key]) .filter((serialized) => serialized) // omit any falsy values .join("&"); }