Skip to content

Commit

Permalink
Merge pull request #298 from janpaepke/pimm+jan/advanced-ik.
Browse files Browse the repository at this point in the history
Added idempotencyKey property to ApiError.
  • Loading branch information
Pimm authored Dec 1, 2022
2 parents f1d766a + 0e68625 commit 67e7fd9
Show file tree
Hide file tree
Showing 47 changed files with 356 additions and 161 deletions.
4 changes: 3 additions & 1 deletion src/binders/applePay/parameters.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
export interface RequestPaymentSessionParameters {
import { IdempotencyParameter } from '../../types/parameters';

export interface RequestPaymentSessionParameters extends IdempotencyParameter {
/**
* The `validationUrl` you got from the [ApplePayValidateMerchant event](https://developer.apple.com/documentation/apple_pay_on_the_web/applepayvalidatemerchantevent).
*
Expand Down
4 changes: 2 additions & 2 deletions src/binders/chargebacks/parameters.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { ChargebackEmbed } from '../../data/chargebacks/Chargeback';
import { PaginationParameters, ThrottlingParameters } from '../../types/parameters';
import { PaginationParameters, ThrottlingParameter } from '../../types/parameters';

export type ListParameters = PaginationParameters & {
profileId?: string;
embed?: ChargebackEmbed[];
};

export type IterateParameters = Omit<ListParameters, 'limit'> & ThrottlingParameters;
export type IterateParameters = Omit<ListParameters, 'limit'> & ThrottlingParameter;
8 changes: 4 additions & 4 deletions src/binders/customers/mandates/parameters.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { MandateData } from '../../../data/customers/mandates/data';
import { PaginationParameters, ThrottlingParameters } from '../../../types/parameters';
import { IdempotencyParameter, PaginationParameters, ThrottlingParameter } from '../../../types/parameters';

interface ContextParameters {
customerId: string;
Expand Down Expand Up @@ -50,12 +50,12 @@ export type CreateParameters = ContextParameters &
* @see https://docs.mollie.com/reference/v2/mandates-api/create-mandate?path=paypalBillingAgreementId#parameters
*/
paypalBillingAgreementId?: string;
};
} & IdempotencyParameter;

export type GetParameters = ContextParameters;

export type ListParameters = ContextParameters & PaginationParameters;

export type IterateParameters = Omit<ListParameters, 'limit'> & ThrottlingParameters;
export type IterateParameters = Omit<ListParameters, 'limit'> & ThrottlingParameter;

export type RevokeParameters = ContextParameters;
export type RevokeParameters = ContextParameters & IdempotencyParameter;
16 changes: 8 additions & 8 deletions src/binders/customers/parameters.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import { CustomerData } from '../../data/customers/Customer';
import { PaginationParameters, ThrottlingParameters } from '../../types/parameters';
import { IdempotencyParameter, PaginationParameters, ThrottlingParameter } from '../../types/parameters';
import PickOptional from '../../types/PickOptional';

interface ContextParameters {
interface ContextParameter {
testmode?: boolean;
}

export type CreateParameters = ContextParameters & PickOptional<CustomerData, 'name' | 'email' | 'locale' | 'metadata'>;
export type CreateParameters = ContextParameter & PickOptional<CustomerData, 'name' | 'email' | 'locale' | 'metadata'> & IdempotencyParameter;

export type GetParameters = ContextParameters;
export type GetParameters = ContextParameter;

export type ListParameters = ContextParameters & PaginationParameters;
export type ListParameters = ContextParameter & PaginationParameters;

export type IterateParameters = Omit<ListParameters, 'limit'> & ThrottlingParameters;
export type IterateParameters = Omit<ListParameters, 'limit'> & ThrottlingParameter;

export type UpdateParameters = ContextParameters & PickOptional<CustomerData, 'name' | 'email' | 'locale' | 'metadata'>;
export type UpdateParameters = ContextParameter & PickOptional<CustomerData, 'name' | 'email' | 'locale' | 'metadata'>;

export type DeleteParameters = ContextParameters;
export type DeleteParameters = ContextParameter & IdempotencyParameter;
6 changes: 3 additions & 3 deletions src/binders/customers/payments/parameters.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { PaymentMethod } from '../../../data/global';
import { PaymentData } from '../../../data/payments/data';
import { PaginationParameters, ThrottlingParameters } from '../../../types/parameters';
import { IdempotencyParameter, PaginationParameters, ThrottlingParameter } from '../../../types/parameters';
import PickOptional from '../../../types/PickOptional';

interface ContextParameters {
Expand All @@ -22,8 +22,8 @@ export type CreateParameters = ContextParameters &
* @see https://docs.mollie.com/reference/v2/payments-api/create-payment?path=method#parameters
*/
method?: PaymentMethod | PaymentMethod[];
};
} & IdempotencyParameter;

export type ListParameters = ContextParameters & PaginationParameters;

export type IterateParameters = Omit<ListParameters, 'limit'> & ThrottlingParameters;
export type IterateParameters = Omit<ListParameters, 'limit'> & ThrottlingParameter;
9 changes: 5 additions & 4 deletions src/binders/customers/subscriptions/parameters.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { SubscriptionData } from '../../../data/subscriptions/data';
import { PaginationParameters, ThrottlingParameters } from '../../../types/parameters';
import { IdempotencyParameter, PaginationParameters, ThrottlingParameter } from '../../../types/parameters';
import PickOptional from '../../../types/PickOptional';

interface ContextParameters {
Expand All @@ -9,16 +9,17 @@ interface ContextParameters {

export type CreateParameters = ContextParameters &
Pick<SubscriptionData, 'amount' | 'interval' | 'description' | 'mandateId'> &
PickOptional<SubscriptionData, 'times' | 'startDate' | 'method' | 'webhookUrl' | 'metadata'>;
PickOptional<SubscriptionData, 'times' | 'startDate' | 'method' | 'webhookUrl' | 'metadata'> &
IdempotencyParameter;

export type GetParameters = ContextParameters;

export type ListParameters = ContextParameters & PaginationParameters;

export type IterateParameters = Omit<ListParameters, 'limit'> & ThrottlingParameters;
export type IterateParameters = Omit<ListParameters, 'limit'> & ThrottlingParameter;

export type UpdateParameters = ContextParameters &
Pick<SubscriptionData, 'mandateId'> &
PickOptional<SubscriptionData, 'amount' | 'description' | 'interval' | 'metadata' | 'startDate' | 'times' | 'webhookUrl'>;

export type CancelParameters = ContextParameters;
export type CancelParameters = ContextParameters & IdempotencyParameter;
2 changes: 1 addition & 1 deletion src/binders/onboarding/OnboardingBinder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export default class OnboardingBinder extends Binder<OnboardingData, Onboarding>
*/
public submit(parameters?: SubmitParameters): Promise<true>;
public submit(parameters: SubmitParameters, callback: Callback<true>): void;
public submit(parameters: SubmitParameters) {
public submit(parameters: SubmitParameters = {}) {
if (renege(this, this.submit, ...arguments)) return;
return this.networkClient.post<OnboardingData, true>(pathSegments, parameters);
}
Expand Down
3 changes: 2 additions & 1 deletion src/binders/onboarding/parameters.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Address } from '../../data/global';
import { IdempotencyParameter } from '../../types/parameters';

export interface SubmitParameters {
export interface SubmitParameters extends IdempotencyParameter {
/**
* Data of the organization you want to provide.
*
Expand Down
3 changes: 2 additions & 1 deletion src/binders/orders/orderlines/parameters.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Amount } from '../../../data/global';
import { OrderLineData } from '../../../data/orders/orderlines/OrderLine';
import { IdempotencyParameter } from '../../../types/parameters';
import PickOptional from '../../../types/PickOptional';

interface ContextParameters {
Expand Down Expand Up @@ -61,4 +62,4 @@ export type CancelParameters = ContextParameters & {
*/
amount?: Amount;
}[];
};
} & IdempotencyParameter;
10 changes: 5 additions & 5 deletions src/binders/orders/parameters.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { PaymentMethod } from '../../data/global';
import { OrderAddress, OrderData, OrderEmbed } from '../../data/orders/data';
import { OrderData, OrderEmbed } from '../../data/orders/data';
import { OrderLineData } from '../../data/orders/orderlines/OrderLine';
import { PaginationParameters, ThrottlingParameters } from '../../types/parameters';
import { IdempotencyParameter, PaginationParameters, ThrottlingParameter } from '../../types/parameters';
import { CreateParameters as PaymentCreateParameters } from '../payments/parameters';
import PickOptional from '../../types/PickOptional';

Expand Down Expand Up @@ -82,7 +82,7 @@ export type CreateParameters = Pick<OrderData, 'amount' | 'orderNumber' | 'consu
embed?: OrderEmbed.payments[];
profileId?: string;
testmode?: boolean;
};
} & IdempotencyParameter;

export interface GetParameters {
testmode?: boolean;
Expand All @@ -99,8 +99,8 @@ export type ListParameters = PaginationParameters & {
testmode?: boolean;
};

export type IterateParameters = Omit<ListParameters, 'limit'> & ThrottlingParameters;
export type IterateParameters = Omit<ListParameters, 'limit'> & ThrottlingParameter;

export interface CancelParameters {
export interface CancelParameters extends IdempotencyParameter {
testmode?: boolean;
}
3 changes: 2 additions & 1 deletion src/binders/orders/shipments/parameters.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Amount } from '../../../data/global';
import { ShipmentData } from '../../../data/orders/shipments/Shipment';
import { IdempotencyParameter } from '../../../types/parameters';
import PickRequired from '../../../types/PickRequired';

interface ContextParameters {
Expand Down Expand Up @@ -46,7 +47,7 @@ export type CreateParameters = ContextParameters &
*/
amount?: Amount;
}[];
};
} & IdempotencyParameter;

export type GetParameters = ContextParameters;

Expand Down
6 changes: 3 additions & 3 deletions src/binders/paymentLinks/parameters.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { PaymentLinkData } from '../../data/paymentLinks/data';
import { PaginationParameters, ThrottlingParameters } from '../../types/parameters';
import { IdempotencyParameter, PaginationParameters, ThrottlingParameter } from '../../types/parameters';

export type CreateParameters = Pick<PaymentLinkData, 'description' | 'amount' | 'redirectUrl' | 'webhookUrl' | 'expiresAt'> & {
profileId?: string;
testmode?: boolean;
};
} & IdempotencyParameter;

export interface GetParameters {
testmode?: boolean;
Expand All @@ -15,4 +15,4 @@ export type ListParameters = PaginationParameters & {
testmode?: boolean;
};

export type IterateParameters = Omit<ListParameters, 'limit'> & ThrottlingParameters;
export type IterateParameters = Omit<ListParameters, 'limit'> & ThrottlingParameter;
4 changes: 2 additions & 2 deletions src/binders/payments/captures/parameters.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CaptureEmbed } from '../../../data/payments/captures/data';
import { PaginationParameters, ThrottlingParameters } from '../../../types/parameters';
import { PaginationParameters, ThrottlingParameter } from '../../../types/parameters';

interface ContextParameters {
paymentId: string;
Expand All @@ -15,4 +15,4 @@ export type ListParameters = ContextParameters &
embed?: CaptureEmbed[];
};

export type IterateParameters = Omit<ListParameters, 'limit'> & ThrottlingParameters;
export type IterateParameters = Omit<ListParameters, 'limit'> & ThrottlingParameter;
4 changes: 2 additions & 2 deletions src/binders/payments/chargebacks/parameters.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ChargebackEmbed } from '../../../data/chargebacks/Chargeback';
import { PaginationParameters, ThrottlingParameters } from '../../../types/parameters';
import { PaginationParameters, ThrottlingParameter } from '../../../types/parameters';

interface ContextParameters {
paymentId: string;
Expand All @@ -14,4 +14,4 @@ export type ListParameters = ContextParameters &
embed?: ChargebackEmbed[];
};

export type IterateParameters = Omit<ListParameters, 'limit'> & ThrottlingParameters;
export type IterateParameters = Omit<ListParameters, 'limit'> & ThrottlingParameter;
3 changes: 2 additions & 1 deletion src/binders/payments/orders/parameters.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { PaymentMethod } from '../../../data/global';
import { PaymentData } from '../../../data/payments/data';
import { IdempotencyParameter } from '../../../types/parameters';

interface ContextParameters {
orderId: string;
Expand Down Expand Up @@ -27,4 +28,4 @@ export type CreateParameters = ContextParameters &
* @see https://docs.mollie.com/reference/v2/orders-api/create-order-payment?path=customerId#parameters
*/
customerId?: string;
};
} & IdempotencyParameter;
8 changes: 4 additions & 4 deletions src/binders/payments/parameters.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Address, Amount, PaymentMethod } from '../../data/global';
import { Issuer } from '../../data/Issuer';
import { PaymentData, PaymentEmbed, PaymentInclude } from '../../data/payments/data';
import { PaginationParameters, ThrottlingParameters } from '../../types/parameters';
import { IdempotencyParameter, PaginationParameters, ThrottlingParameter } from '../../types/parameters';
import PickOptional from '../../types/PickOptional';

export type CreateParameters = Pick<PaymentData, 'amount' | 'description' | 'redirectUrl' | 'webhookUrl' | 'customerId' | 'mandateId'> &
Expand Down Expand Up @@ -157,7 +157,7 @@ export type CreateParameters = Pick<PaymentData, 'amount' | 'description' | 'red
*/
description: string;
};
};
} & IdempotencyParameter;

export interface GetParameters {
include?: PaymentInclude;
Expand All @@ -170,7 +170,7 @@ export type ListParameters = PaginationParameters & {
testmode?: boolean;
};

export type IterateParameters = Omit<ListParameters, 'limit'> & ThrottlingParameters;
export type IterateParameters = Omit<ListParameters, 'limit'> & ThrottlingParameter;

export type UpdateParameters = Pick<PaymentData, 'redirectUrl' | 'webhookUrl'> &
PickOptional<PaymentData, 'description' | 'metadata'> & {
Expand All @@ -187,6 +187,6 @@ export type UpdateParameters = Pick<PaymentData, 'redirectUrl' | 'webhookUrl'> &
restrictPaymentMethodsToCountry?: string;
};

export interface CancelParameters {
export interface CancelParameters extends IdempotencyParameter {
testmode?: boolean;
}
8 changes: 4 additions & 4 deletions src/binders/payments/refunds/parameters.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { RefundData, RefundEmbed } from '../../../data/refunds/data';
import { PaginationParameters, ThrottlingParameters } from '../../../types/parameters';
import { IdempotencyParameter, PaginationParameters, ThrottlingParameter } from '../../../types/parameters';
import PickOptional from '../../../types/PickOptional';

interface ContextParameters {
paymentId: string;
testmode?: boolean;
}

export type CreateParameters = ContextParameters & Pick<RefundData, 'amount' | 'metadata'> & PickOptional<RefundData, 'description'>;
export type CreateParameters = ContextParameters & Pick<RefundData, 'amount' | 'metadata'> & PickOptional<RefundData, 'description'> & IdempotencyParameter;

export type GetParameters = ContextParameters & {
embed?: RefundEmbed[];
Expand All @@ -18,6 +18,6 @@ export type ListParameters = ContextParameters &
embed?: RefundEmbed[];
};

export type IterateParameters = Omit<ListParameters, 'limit'> & ThrottlingParameters;
export type IterateParameters = Omit<ListParameters, 'limit'> & ThrottlingParameter;

export type CancelParameters = ContextParameters;
export type CancelParameters = ContextParameters & IdempotencyParameter;
10 changes: 5 additions & 5 deletions src/binders/profiles/ProfilesBinder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import checkId from '../../plumbing/checkId';
import renege from '../../plumbing/renege';
import Callback from '../../types/Callback';
import Binder from '../Binder';
import { CreateParameters, IterateParameters, ListParameters, UpdateParameters } from './parameters';
import { CreateParameters, DeleteParameters, IterateParameters, ListParameters, UpdateParameters } from './parameters';

const pathSegment = 'profiles';

Expand Down Expand Up @@ -124,13 +124,13 @@ export default class ProfilesBinder extends Binder<ProfileData, Profile> {
* @since 3.2.0
* @see https://docs.mollie.com/reference/v2/profiles-api/delete-profile
*/
public delete(id: string): Promise<true>;
public delete(id: string, callback: Callback<List<true>>): void;
public delete(id: string) {
public delete(id: string, parameters?: DeleteParameters): Promise<true>;
public delete(id: string, parameters: DeleteParameters, callback: Callback<true>): void;
public delete(id: string, parameters?: DeleteParameters) {
if (renege(this, this.delete, ...arguments)) return;
if (!checkId(id, 'profile')) {
throw new ApiError('The profile id is invalid');
}
return this.networkClient.delete<ProfileData, true>(`${pathSegment}/${id}`);
return this.networkClient.delete<ProfileData, true>(`${pathSegment}/${id}`, parameters);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ export default class ProfileGiftcardIssuersBinder extends Binder<IssuerData, Iss
public enable(parameters: Parameters, callback: Callback<IssuerModel>): void;
public enable(parameters: Parameters) {
if (renege(this, this.enable, ...arguments)) return;
if (!checkId(parameters.profileId, 'profile')) {
const { id, profileId, ...data } = parameters;
if (!checkId(profileId, 'profile')) {
throw new ApiError('The profile id is invalid');
}
return this.networkClient.post(`${getPathSegments(parameters.profileId)}/${parameters.id}`, undefined);
return this.networkClient.post(`${getPathSegments(profileId)}/${id}`, data);
}

/**
Expand All @@ -41,10 +42,11 @@ export default class ProfileGiftcardIssuersBinder extends Binder<IssuerData, Iss
public disable(parameters: Parameters): Promise<true>;
public disable(parameters: Parameters, callback: Callback<true>): void;
public disable(parameters: Parameters) {
if (renege(this, this.enable, ...arguments)) return;
if (!checkId(parameters.profileId, 'profile')) {
if (renege(this, this.disable, ...arguments)) return;
const { id, profileId, ...context } = parameters;
if (!checkId(profileId, 'profile')) {
throw new ApiError('The profile id is invalid');
}
return this.networkClient.delete<IssuerData, true>(`${getPathSegments(parameters.profileId)}/${parameters.id}`);
return this.networkClient.delete<IssuerData, true>(`${getPathSegments(profileId)}/${id}`, context);
}
}
4 changes: 3 additions & 1 deletion src/binders/profiles/giftcardIssuers/parameters.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
export interface Parameters {
import { IdempotencyParameter } from '../../../types/parameters';

export interface Parameters extends IdempotencyParameter {
/**
* The ID of the profile, for example `pfl_v9hTwCvYqw`.
*/
Expand Down
Loading

0 comments on commit 67e7fd9

Please sign in to comment.