diff --git a/src/Options.ts b/src/Options.ts index 5db0f951..2b4b73d5 100644 --- a/src/Options.ts +++ b/src/Options.ts @@ -1,3 +1,4 @@ +import type MaybeArray from './types/MaybeArray'; import type Xor from './types/Xor'; type Options = Xor< @@ -17,7 +18,7 @@ type Options = Xor< /** * One or an array of version strings of the software you are using, such as `'RockenbergCommerce/3.1.12'`. */ - versionStrings?: string | string[]; + versionStrings?: MaybeArray; /** * The headers set in the requests sent to the Mollie API. `Authorization`, `User-Agent`, `Accept`, * `Accept-Encoding`, and `Content-Type` are set by this library directly. Setting them here has no effect. diff --git a/src/binders/customers/payments/parameters.ts b/src/binders/customers/payments/parameters.ts index 5a2d4fa0..08b93499 100644 --- a/src/binders/customers/payments/parameters.ts +++ b/src/binders/customers/payments/parameters.ts @@ -1,5 +1,6 @@ import { type PaymentMethod } from '../../../data/global'; import { type PaymentData } from '../../../data/payments/data'; +import type MaybeArray from '../../../types/MaybeArray'; import { type IdempotencyParameter, type PaginationParameters, type ThrottlingParameter } from '../../../types/parameters'; import type PickOptional from '../../../types/PickOptional'; @@ -21,7 +22,7 @@ export type CreateParameters = ContextParameters & * * @see https://docs.mollie.com/reference/v2/payments-api/create-payment?path=method#parameters */ - method?: PaymentMethod | PaymentMethod[]; + method?: MaybeArray; } & IdempotencyParameter; export type PageParameters = ContextParameters & PaginationParameters; diff --git a/src/binders/methods/parameters.ts b/src/binders/methods/parameters.ts index bbff0cf5..d0ba7a10 100644 --- a/src/binders/methods/parameters.ts +++ b/src/binders/methods/parameters.ts @@ -1,5 +1,6 @@ import { type Amount, type Locale, type SequenceType } from '../../data/global'; import { type MethodInclude } from '../../data/methods/data'; +import type MaybeArray from '../../types/MaybeArray'; export interface GetParameters { /** @@ -10,7 +11,7 @@ export interface GetParameters { * @see https://docs.mollie.com/reference/v2/methods-api/get-method?path=locale#parameters */ locale?: Locale; - include?: MethodInclude[] | MethodInclude; + include?: MaybeArray; profileId?: string; testmode?: boolean; /** @@ -103,7 +104,7 @@ export interface ListParameters { * @see https://docs.mollie.com/reference/v2/methods-api/list-methods?path=orderLineCategories#parameters */ orderLineCategories?: string[]; - include?: MethodInclude[] | MethodInclude; + include?: MaybeArray; profileId?: string; testmode?: boolean; } diff --git a/src/binders/orders/parameters.ts b/src/binders/orders/parameters.ts index 46e1d22f..da0068bc 100644 --- a/src/binders/orders/parameters.ts +++ b/src/binders/orders/parameters.ts @@ -4,6 +4,7 @@ import { type OrderLineData } from '../../data/orders/orderlines/OrderLine'; import { type IdempotencyParameter, type PaginationParameters, type ThrottlingParameter } from '../../types/parameters'; import { type CreateParameters as PaymentCreateParameters } from '../payments/parameters'; import type PickOptional from '../../types/PickOptional'; +import type MaybeArray from '../../types/MaybeArray'; export type CreateParameters = Pick & PickOptional & { @@ -49,7 +50,7 @@ export type CreateParameters = Pick; /** * Any payment specific properties (for example, the `dueDate` for bank transfer payments) can be passed here. See payment-parameters for the possible fields. * diff --git a/src/binders/payments/orders/parameters.ts b/src/binders/payments/orders/parameters.ts index 274b049a..8c1b35e5 100644 --- a/src/binders/payments/orders/parameters.ts +++ b/src/binders/payments/orders/parameters.ts @@ -1,5 +1,6 @@ import { type PaymentMethod } from '../../../data/global'; import { type PaymentData } from '../../../data/payments/data'; +import type MaybeArray from '../../../types/MaybeArray'; import { type IdempotencyParameter } from '../../../types/parameters'; interface ContextParameters { @@ -21,7 +22,7 @@ export type CreateParameters = ContextParameters & * * @see https://docs.mollie.com/reference/v2/orders-api/create-order-payment?path=method#parameters */ - method?: PaymentMethod | PaymentMethod[]; + method?: MaybeArray; /** * The ID of the customer for whom the payment is being created. This is used for recurring payments and single-click payments. * diff --git a/src/binders/payments/parameters.ts b/src/binders/payments/parameters.ts index 54c4b029..9581438b 100644 --- a/src/binders/payments/parameters.ts +++ b/src/binders/payments/parameters.ts @@ -1,6 +1,7 @@ import { type Address, type Amount, type PaymentMethod } from '../../data/global'; import { type Issuer } from '../../data/Issuer'; import { type PaymentData, type PaymentEmbed, type PaymentInclude } from '../../data/payments/data'; +import type MaybeArray from '../../types/MaybeArray'; import { type IdempotencyParameter, type PaginationParameters, type ThrottlingParameter } from '../../types/parameters'; import type PickOptional from '../../types/PickOptional'; @@ -17,7 +18,7 @@ export type CreateParameters = Pick; /** * For digital goods in most jurisdictions, you must apply the VAT rate from your customer's country. Choose the VAT rates you have used for the order to ensure your customer's country matches the * VAT country. @@ -132,7 +133,7 @@ export type CreateParameters = Pick; profileId?: string; testmode?: boolean; /** @@ -163,7 +164,7 @@ export type CreateParameters = Pick; testmode?: boolean; } diff --git a/src/communication/NetworkClient.ts b/src/communication/NetworkClient.ts index a3976cda..223226f1 100644 --- a/src/communication/NetworkClient.ts +++ b/src/communication/NetworkClient.ts @@ -11,6 +11,7 @@ import DemandingIterator from '../plumbing/iteration/DemandingIterator'; import HelpfulIterator from '../plumbing/iteration/HelpfulIterator'; import Throttler from '../plumbing/Throttler'; import type Maybe from '../types/Maybe'; +import type MaybeArray from '../types/MaybeArray'; import { type IdempotencyParameter } from '../types/parameters'; import breakUrl from './breakUrl'; import buildUrl, { type SearchParameters } from './buildUrl'; @@ -23,7 +24,7 @@ import { URL } from 'url'; * Like `[].map` but with support for non-array inputs, in which case this function behaves as if an array was passed * with the input as its sole element. */ -function map(input: Maybe, callback: (value: T, index: number) => U, context?: any): U[] { +function map(input: Maybe>, callback: (value: T, index: number) => U, context?: any): U[] { if (Array.isArray(input)) { return input.map(callback, context); } diff --git a/src/communication/buildUrl.ts b/src/communication/buildUrl.ts index 3cb79354..fc93fe6a 100644 --- a/src/communication/buildUrl.ts +++ b/src/communication/buildUrl.ts @@ -2,7 +2,9 @@ import { URLSearchParams } from 'url'; import { apply, runIf } from 'ruply'; + import type Maybe from '../types/Maybe'; +import type MaybeArray from '../types/MaybeArray'; export type SearchParameters = Record; @@ -25,7 +27,7 @@ export default function buildUrl(originAndPathname: string, searchParameters?: S return originAndPathname; } return `${originAndPathname}?${new URLSearchParams( - apply({} as Record, flattenedEntries => { + apply({} as Record>, flattenedEntries => { for (const [key, value] of searchEntries) { if (value == undefined) { continue; diff --git a/src/types/MaybeArray.ts b/src/types/MaybeArray.ts new file mode 100644 index 00000000..61f92d46 --- /dev/null +++ b/src/types/MaybeArray.ts @@ -0,0 +1,3 @@ +type MaybeArray = T | T[]; + +export default MaybeArray; \ No newline at end of file