UNPKG

1.18 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.getCanonicalQuery = void 0;
4const util_uri_escape_1 = require("@aws-sdk/util-uri-escape");
5const constants_1 = require("./constants");
6const getCanonicalQuery = ({ query = {} }) => {
7 const keys = [];
8 const serialized = {};
9 for (const key of Object.keys(query).sort()) {
10 if (key.toLowerCase() === constants_1.SIGNATURE_HEADER) {
11 continue;
12 }
13 keys.push(key);
14 const value = query[key];
15 if (typeof value === "string") {
16 serialized[key] = `${(0, util_uri_escape_1.escapeUri)(key)}=${(0, util_uri_escape_1.escapeUri)(value)}`;
17 }
18 else if (Array.isArray(value)) {
19 serialized[key] = value
20 .slice(0)
21 .sort()
22 .reduce((encoded, value) => encoded.concat([`${(0, util_uri_escape_1.escapeUri)(key)}=${(0, util_uri_escape_1.escapeUri)(value)}`]), [])
23 .join("&");
24 }
25 }
26 return keys
27 .map((key) => serialized[key])
28 .filter((serialized) => serialized)
29 .join("&");
30};
31exports.getCanonicalQuery = getCanonicalQuery;