0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2025-03-17 22:31:28 -05:00

fix(aliyun): skip undefined fields (#208)

This commit is contained in:
Wang Sijie 2022-01-29 17:11:57 +08:00 committed by GitHub
parent 30ce91810f
commit 3cb1cae486
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -3,8 +3,6 @@ import { createHmac } from 'crypto';
import { has } from '@silverhand/essentials';
import got from 'got';
import { ConnectorError } from '../types';
// Aliyun has special excape rules.
// https://help.aliyun.com/document_detail/29442.html
const escaper = (string_: string) =>
@ -28,12 +26,13 @@ export const getSignature = (
.map((key) => {
const value = parameters[key];
if (typeof value !== 'string') {
throw new ConnectorError('Invalid value');
if (value === undefined || value === null) {
return null;
}
return `${escaper(key)}=${escaper(value)}`;
})
.filter(Boolean)
.join('&');
const stringToSign = `${method.toUpperCase()}&${escaper('/')}&${escaper(canonicalizedQuery)}`;
@ -71,8 +70,8 @@ export const request = async <T>(
if (has(finalParameters, key)) {
const value = finalParameters[key];
if (typeof value !== 'string') {
throw new ConnectorError('Invalid value');
if (value === undefined || value === null) {
continue;
}
payload.append(key, value);