@stancer/stancer 1.0.2 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -1
- package/dist/api-endpoint/http/fetch-http-client.d.ts.map +1 -1
- package/dist/api-endpoint/http/fetch-http-client.js +7 -1
- package/dist/api-endpoint/http/fetch-http-client.js.map +1 -1
- package/dist/core/common/handler/metadata-handler.d.ts +18 -0
- package/dist/core/common/handler/metadata-handler.d.ts.map +1 -0
- package/dist/core/common/handler/metadata-handler.js +19 -0
- package/dist/core/common/handler/metadata-handler.js.map +1 -0
- package/dist/event/model.d.ts +20 -0
- package/dist/event/model.d.ts.map +1 -0
- package/dist/event/model.js +30 -0
- package/dist/event/model.js.map +1 -0
- package/dist/index.d.ts +60 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +57 -0
- package/dist/index.js.map +1 -0
- package/dist/payment-intent/api-endpoint.d.ts +16 -1
- package/dist/payment-intent/api-endpoint.d.ts.map +1 -1
- package/dist/payment-intent/api-endpoint.js +2 -1
- package/dist/payment-intent/api-endpoint.js.map +1 -1
- package/dist/payment-intent/model.d.ts +3 -2
- package/dist/payment-intent/model.d.ts.map +1 -1
- package/dist/payment-intent/model.js +6 -0
- package/dist/payment-intent/model.js.map +1 -1
- package/dist/payment-intent/repository.d.ts +1 -1
- package/dist/payment-intent/repository.d.ts.map +1 -1
- package/dist/webhook/api-endpoint.d.ts +16 -0
- package/dist/webhook/api-endpoint.d.ts.map +1 -0
- package/dist/webhook/api-endpoint.js +33 -0
- package/dist/webhook/api-endpoint.js.map +1 -0
- package/dist/webhook/model.d.ts +35 -0
- package/dist/webhook/model.d.ts.map +1 -0
- package/dist/webhook/model.js +110 -0
- package/dist/webhook/model.js.map +1 -0
- package/dist/webhook/repository.d.ts +7 -0
- package/dist/webhook/repository.d.ts.map +1 -0
- package/dist/webhook/repository.js +10 -0
- package/dist/webhook/repository.js.map +1 -0
- package/dist/webhook/validator.d.ts +4 -0
- package/dist/webhook/validator.d.ts.map +1 -0
- package/dist/webhook/validator.js +16 -0
- package/dist/webhook/validator.js.map +1 -0
- package/package.json +33 -22
- package/dist/main.d.ts +0 -2
- package/dist/main.d.ts.map +0 -1
- package/dist/main.js +0 -2
- package/dist/main.js.map +0 -1
- package/reports/base.css +0 -362
- package/reports/block-navigation.js +0 -75
- package/reports/cobertura-coverage.xml +0 -18
- package/reports/favicon.png +0 -0
- package/reports/index.html +0 -177
- package/reports/junit.xml +0 -25
- package/reports/prettify.css +0 -101
- package/reports/prettify.js +0 -955
- package/reports/sort-arrow-sprite.png +0 -0
- package/reports/sorter.js +0 -205
- package/src/address/api-endpoint.ts +0 -30
- package/src/address/model.ts +0 -79
- package/src/address/repository.ts +0 -18
- package/src/address/validator.ts +0 -34
- package/src/api-endpoint/abstract-api-endpoint.ts +0 -310
- package/src/api-endpoint/configuration.ts +0 -125
- package/src/api-endpoint/http/fetch-http-client.ts +0 -29
- package/src/api-endpoint/http/http.ts +0 -75
- package/src/api-endpoint/http/index.ts +0 -2
- package/src/api-endpoint/version.ts +0 -4
- package/src/card/api-endpoint.ts +0 -39
- package/src/card/enum/funding.ts +0 -11
- package/src/card/enum/nature.ts +0 -7
- package/src/card/enum/network.ts +0 -16
- package/src/card/model.ts +0 -139
- package/src/card/repository.ts +0 -11
- package/src/card/validator.ts +0 -79
- package/src/core/abstract-model.ts +0 -126
- package/src/core/abstract-repository.ts +0 -201
- package/src/core/common/branded-type.ts +0 -15
- package/src/core/common/handler/date-handler.ts +0 -31
- package/src/core/common/handler/enum-handler.ts +0 -18
- package/src/core/common/handler/handler.ts +0 -64
- package/src/core/common/handler/id-handler.ts +0 -27
- package/src/core/common/id-validator.ts +0 -23
- package/src/core/common/mutation-tracked-object.ts +0 -49
- package/src/core/endpoint-interface.ts +0 -43
- package/src/core/error/base-error.ts +0 -1
- package/src/core/error/endpoint/api/api-conflict-error.ts +0 -7
- package/src/core/error/endpoint/api/api-error.ts +0 -10
- package/src/core/error/endpoint/api/api-not-found-error.ts +0 -7
- package/src/core/error/endpoint/api/api-unauthorized-error.ts +0 -7
- package/src/core/error/endpoint/api/api-unknown-error.ts +0 -7
- package/src/core/error/endpoint/api/api-validation-error.ts +0 -13
- package/src/core/error/endpoint/api/index.ts +0 -6
- package/src/core/error/endpoint/route-inaccessible-error.ts +0 -8
- package/src/core/error/unpopulated-error.ts +0 -3
- package/src/core/error/unsendable-error.ts +0 -3
- package/src/core/error/validation-error.ts +0 -3
- package/src/core/validator.ts +0 -129
- package/src/customer/api-endpoint.ts +0 -29
- package/src/customer/model.ts +0 -113
- package/src/customer/repository.ts +0 -14
- package/src/customer/validator.ts +0 -26
- package/src/payment/api-endpoint.ts +0 -118
- package/src/payment/enum/currency.ts +0 -14
- package/src/payment/enum/method.ts +0 -2
- package/src/payment/enum/status.ts +0 -21
- package/src/payment/model.ts +0 -378
- package/src/payment/repository.ts +0 -73
- package/src/payment/validator.ts +0 -96
- package/src/payment-intent/api-endpoint.ts +0 -123
- package/src/payment-intent/enum/status.ts +0 -21
- package/src/payment-intent/enum/threeds.ts +0 -2
- package/src/payment-intent/model.ts +0 -266
- package/src/payment-intent/repository.ts +0 -85
- package/src/payment-intent/validator.ts +0 -45
- package/src/payout/model.ts +0 -8
- package/src/refund/api-endpoint.ts +0 -33
- package/src/refund/enum/refund-status.ts +0 -11
- package/src/refund/model.ts +0 -90
- package/src/refund/repository.ts +0 -14
- package/src/refund/validator.ts +0 -44
- package/src/sepa/api-endpoint.ts +0 -26
- package/src/sepa/model.ts +0 -80
- package/src/sepa/repository.ts +0 -11
- package/src/sepa/validator.ts +0 -56
- package/test/fixtures/endpoint.stub.ts +0 -22
- package/test/fixtures/list-endpoint.stub.ts +0 -33
- package/test/fixtures/list-model.stub.ts +0 -24
- package/test/fixtures/model.stub.ts +0 -12
- package/test/functional/address.test.ts +0 -126
- package/test/functional/card.test.ts +0 -175
- package/test/functional/customer.test.ts +0 -174
- package/test/functional/payment-intent.test.ts +0 -215
- package/test/functional/payment.test.ts +0 -206
- package/test/functional/refund.test.ts +0 -112
- package/test/functional/sepa.test.ts +0 -136
- package/test/integration/stub-integration.test.ts +0 -88
- package/test/stub/stub-endpoint.ts +0 -42
- package/test/stub/stub-model.ts +0 -82
- package/test/stub/stub-repository.ts +0 -11
- package/test/test-helper.ts +0 -133
- package/test/unit/address/api-endpoint.test.ts +0 -134
- package/test/unit/address/fixtures.ts +0 -60
- package/test/unit/address/model.test.ts +0 -75
- package/test/unit/address/repository.test.ts +0 -148
- package/test/unit/address/validator.test.ts +0 -49
- package/test/unit/api-endpoint/http/fetch-http-client.test.ts +0 -44
- package/test/unit/api-endpoint/http/http.test.ts +0 -152
- package/test/unit/card/api-endpoint.test.ts +0 -170
- package/test/unit/card/card-helper.ts +0 -116
- package/test/unit/card/fixtures.ts +0 -87
- package/test/unit/card/model.test.ts +0 -167
- package/test/unit/card/repository.test.ts +0 -146
- package/test/unit/card/validator.test.ts +0 -96
- package/test/unit/core/common/mutation-tracked-object.test.ts +0 -24
- package/test/unit/customer/api-endpoint.test.ts +0 -143
- package/test/unit/customer/fixtures.ts +0 -73
- package/test/unit/customer/model.test.ts +0 -90
- package/test/unit/customer/repository.test.ts +0 -148
- package/test/unit/customer/validator.test.ts +0 -62
- package/test/unit/payment/api-endpoint.test.ts +0 -188
- package/test/unit/payment/fixtures.ts +0 -116
- package/test/unit/payment/model.test.ts +0 -240
- package/test/unit/payment/repository.test.ts +0 -270
- package/test/unit/payment/validator.test.ts +0 -137
- package/test/unit/payment-intent/api-endpoint.test.ts +0 -142
- package/test/unit/payment-intent/fixtures.ts +0 -94
- package/test/unit/payment-intent/model.test.ts +0 -157
- package/test/unit/payment-intent/repository.test.ts +0 -263
- package/test/unit/payment-intent/validator.test.ts +0 -136
- package/test/unit/refund/api-endpoint.test.ts +0 -129
- package/test/unit/refund/fixtures.ts +0 -58
- package/test/unit/refund/model.test.ts +0 -89
- package/test/unit/refund/repository.test.ts +0 -157
- package/test/unit/refund/validator.test.ts +0 -89
- package/test/unit/sepa/api-endpoint.test.ts +0 -170
- package/test/unit/sepa/fixture.ts +0 -62
- package/test/unit/sepa/model.test.ts +0 -86
- package/test/unit/sepa/repository.test.ts +0 -149
- package/test/unit/sepa/sepa-helper.ts +0 -71
- package/test/unit/sepa/validator.test.ts +0 -58
- package/test/unit/stub/stub-endpoint.test.ts +0 -236
- package/test/unit/stub/stub-list-endpoint.test.ts +0 -86
- package/test/unit/stub/stub-model.test.ts +0 -111
- package/test/unit/stub/stub-repository.test.ts +0 -144
package/src/core/validator.ts
DELETED
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
import { Temporal } from 'temporal-polyfill';
|
|
2
|
-
|
|
3
|
-
import { StancerValidationError } from './error/validation-error.js';
|
|
4
|
-
|
|
5
|
-
//#region Types
|
|
6
|
-
|
|
7
|
-
interface ValidatorObject<Property> {
|
|
8
|
-
errorMessage: (value: string) => string;
|
|
9
|
-
validate: (value: Property) => boolean;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Validator configuration mapping each property to either a ValidatorObject or true (pass-through).
|
|
14
|
-
*/
|
|
15
|
-
export type Validator<ValidationData> = {
|
|
16
|
-
[Property in keyof ValidationData]: ValidatorObject<ValidationData[Property]> | true;
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Validation function that validates a single property value.
|
|
21
|
-
* @returns true if valid
|
|
22
|
-
* @throws {StancerValidationError} if invalid
|
|
23
|
-
*/
|
|
24
|
-
export type ValidationFunction<Data> = <Key extends keyof Data>(key: Key, value: Data[Key]) => true | never;
|
|
25
|
-
|
|
26
|
-
interface ExactSize {
|
|
27
|
-
size: number;
|
|
28
|
-
min?: undefined;
|
|
29
|
-
max?: undefined;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
interface BorderedSize {
|
|
33
|
-
min: number;
|
|
34
|
-
max: number;
|
|
35
|
-
size?: undefined;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
type GoldilocksSize = ExactSize | BorderedSize;
|
|
39
|
-
|
|
40
|
-
//#endregion
|
|
41
|
-
|
|
42
|
-
//#region Core Validation Logic
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Creates a validation function from a validator configuration.
|
|
46
|
-
*/
|
|
47
|
-
export const processValidator = <Data>(validator: Validator<Data>): ValidationFunction<Data> => {
|
|
48
|
-
return (key, value) => {
|
|
49
|
-
const rule = validator[key];
|
|
50
|
-
|
|
51
|
-
if (!rule || rule === true) {
|
|
52
|
-
return true;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
if (!rule.validate(value)) {
|
|
56
|
-
throw new StancerValidationError(rule.errorMessage(String(value)));
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
return true;
|
|
60
|
-
};
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
//#endregion
|
|
64
|
-
|
|
65
|
-
//#region Validator Factories
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* Pass-through validator that accepts any value without validation.
|
|
69
|
-
* Use for fields like createdAt that are set server-side.
|
|
70
|
-
*/
|
|
71
|
-
export const createdAtValidator = true;
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* Creates a string length validator with exact size or min/max bounds.
|
|
75
|
-
* @throws {StancerValidationError} At creation time if configuration is invalid
|
|
76
|
-
*/
|
|
77
|
-
export const goldilocksValidator = (propertyName: string, { max, min, size }: GoldilocksSize) => {
|
|
78
|
-
const hasExactSize = size !== undefined || (max !== undefined && max === min);
|
|
79
|
-
const hasBoundedSize = min !== undefined && max !== undefined && min <= max;
|
|
80
|
-
|
|
81
|
-
if (hasExactSize) {
|
|
82
|
-
const exactLength = size ?? max;
|
|
83
|
-
return {
|
|
84
|
-
errorMessage: (value: string) => `${value} of ${propertyName} must be exactly ${exactLength} characters`,
|
|
85
|
-
validate: (value: string) => value.length === exactLength,
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
if (hasBoundedSize) {
|
|
90
|
-
return {
|
|
91
|
-
errorMessage: (value: string) => `${value} of ${propertyName} must be between ${min} and ${max} characters`,
|
|
92
|
-
validate: (value: string) => value.length >= min && value.length <= max,
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
throw new StancerValidationError(
|
|
97
|
-
`goldilocksValidator for ${propertyName} requires either a size parameter or both min and max parameters`,
|
|
98
|
-
);
|
|
99
|
-
};
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* Creates an enum validator for string union types.
|
|
103
|
-
* @param strict - When false and not in DEBUG mode, bypasses validation to prevent SDK crashes
|
|
104
|
-
* when API adds new enum values unknown to the SDK.
|
|
105
|
-
*/
|
|
106
|
-
export const enumValidator = <Enum extends readonly string[]>(values: Enum, strict: boolean = true) => {
|
|
107
|
-
if (!strict && process.env['DEBUG'] !== 'true') {
|
|
108
|
-
return true;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
return {
|
|
112
|
-
validate: (value: unknown): value is (typeof values)[number] =>
|
|
113
|
-
typeof value === 'string' && values.includes(value as (typeof values)[number]),
|
|
114
|
-
errorMessage: (value: string) => `Expected one of ${values.join(', ')}. Got ${value}`,
|
|
115
|
-
};
|
|
116
|
-
};
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
* Creates a PlainDate validator ensuring the date is between 1971 and today.
|
|
120
|
-
*/
|
|
121
|
-
export const plainDateValidator = (field: string) => {
|
|
122
|
-
return {
|
|
123
|
-
validate: (value: Temporal.PlainDate) =>
|
|
124
|
-
value.year > 1970 && Temporal.PlainDate.compare(Temporal.Now.plainDateISO(), value) === 1,
|
|
125
|
-
errorMessage: () => `${field} must be a date between 1971 and now.`,
|
|
126
|
-
};
|
|
127
|
-
};
|
|
128
|
-
|
|
129
|
-
//#endregion
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { AddressModel, type IdAddress } from '#address/model.js';
|
|
2
|
-
import { ApiEndpoint, baseHandler } from '#api/abstract-api-endpoint.js';
|
|
3
|
-
import { RFC9557Handler } from '#core/common/handler/date-handler.js';
|
|
4
|
-
import { defaultHandler } from '#core/common/handler/handler.js';
|
|
5
|
-
import { IdHandler } from '#core/common/handler/id-handler.js';
|
|
6
|
-
|
|
7
|
-
import { type CustomerData, CustomerModel, type IdCustomer } from './model.js';
|
|
8
|
-
|
|
9
|
-
export class CustomerApiEndpoint extends ApiEndpoint<CustomerData> {
|
|
10
|
-
protected _handler = {
|
|
11
|
-
...baseHandler('created'),
|
|
12
|
-
id: IdHandler<IdCustomer>(CustomerModel.regex),
|
|
13
|
-
billingAddress: IdHandler<IdAddress>(AddressModel.regex, { gettable: true, postable: true, patchable: true }),
|
|
14
|
-
country: defaultHandler<CustomerData['country']>('string'),
|
|
15
|
-
dateBirth: RFC9557Handler({}),
|
|
16
|
-
email: defaultHandler<CustomerData['email']>('string', { postRequired: 'partial' }),
|
|
17
|
-
externalId: defaultHandler<CustomerData['externalId']>('string'),
|
|
18
|
-
legalId: defaultHandler<CustomerData['legalId']>('string'),
|
|
19
|
-
mobile: defaultHandler<CustomerData['mobile']>('string', { postRequired: 'partial' }),
|
|
20
|
-
name: defaultHandler<CustomerData['name']>('string'),
|
|
21
|
-
shippingAddress: IdHandler<IdAddress>(AddressModel.regex, { gettable: true, postable: true, patchable: true }),
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
constructor() {
|
|
25
|
-
super({
|
|
26
|
-
name: 'customers',
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
}
|
package/src/customer/model.ts
DELETED
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
import type { IdAddress } from '#address/model.js';
|
|
2
|
-
import { AbstractModel, type ModelType } from '#core/abstract-model.js';
|
|
3
|
-
import type { IdValue } from '#core/common/branded-type.js';
|
|
4
|
-
import { validateID } from '#core/common/id-validator.js';
|
|
5
|
-
|
|
6
|
-
export type IdCustomer = IdValue<`cust_${string}`>;
|
|
7
|
-
export const idCustomer = (id: string) => validateID<IdCustomer>(id, CustomerModel.regex);
|
|
8
|
-
|
|
9
|
-
export interface CustomerData extends ModelType {
|
|
10
|
-
id: IdCustomer;
|
|
11
|
-
country: string;
|
|
12
|
-
dateBirth: Temporal.PlainDate;
|
|
13
|
-
email: string;
|
|
14
|
-
externalId: string;
|
|
15
|
-
legalId: string;
|
|
16
|
-
mobile: string;
|
|
17
|
-
name: string;
|
|
18
|
-
billingAddress: IdAddress;
|
|
19
|
-
shippingAddress: IdAddress;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export class CustomerModel extends AbstractModel<CustomerData> {
|
|
23
|
-
static regex = /^cust_[a-zA-Z0-9]{24}$/;
|
|
24
|
-
|
|
25
|
-
//#region Getters
|
|
26
|
-
|
|
27
|
-
get billingAddress() {
|
|
28
|
-
return this._data.billingAddress;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
get country() {
|
|
32
|
-
return this._data.country;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
get dateBirth() {
|
|
36
|
-
return this._data.dateBirth;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
get email() {
|
|
40
|
-
return this._data.email;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
get externalId() {
|
|
44
|
-
return this._data.externalId;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
get legalId() {
|
|
48
|
-
return this._data.legalId;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
get mobile() {
|
|
52
|
-
return this._data.mobile;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
get name() {
|
|
56
|
-
return this._data.name;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
get shippingAddress() {
|
|
60
|
-
return this._data.shippingAddress;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
//#endregion
|
|
64
|
-
|
|
65
|
-
//#region Setters
|
|
66
|
-
|
|
67
|
-
setBillingAddress(value: IdAddress) {
|
|
68
|
-
this._data.billingAddress = value;
|
|
69
|
-
return this;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
setCountry(value: string) {
|
|
73
|
-
this._data.country = value;
|
|
74
|
-
return this;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
setDateBirth(value: Temporal.PlainDate) {
|
|
78
|
-
this._data.dateBirth = value;
|
|
79
|
-
return this;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
setEmail(value: string) {
|
|
83
|
-
this._data.email = value;
|
|
84
|
-
return this;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
setExternalId(value: string) {
|
|
88
|
-
this._data.externalId = value;
|
|
89
|
-
return this;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
setLegalId(value: string) {
|
|
93
|
-
this._data.legalId = value;
|
|
94
|
-
return this;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
setMobile(value: string) {
|
|
98
|
-
this._data.mobile = value;
|
|
99
|
-
return this;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
setName(value: string) {
|
|
103
|
-
this._data.name = value;
|
|
104
|
-
return this;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
setShippingAddress(value: IdAddress) {
|
|
108
|
-
this._data.shippingAddress = value;
|
|
109
|
-
return this;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
//#endregion
|
|
113
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { AbstractRepository, type Repository } from '#core/abstract-repository.js';
|
|
2
|
-
import type { EndpointInterface } from '#core/endpoint-interface.js';
|
|
3
|
-
import { CustomerApiEndpoint } from '#customer/api-endpoint.js';
|
|
4
|
-
import { type CustomerData, CustomerModel } from '#customer/model.js';
|
|
5
|
-
import { customerValidator } from '#customer/validator.js';
|
|
6
|
-
|
|
7
|
-
export class CustomerRepository
|
|
8
|
-
extends AbstractRepository<CustomerData, CustomerModel>
|
|
9
|
-
implements Repository<CustomerData, CustomerModel>
|
|
10
|
-
{
|
|
11
|
-
constructor(endpoint?: EndpointInterface<CustomerData>) {
|
|
12
|
-
super({ endpoint: endpoint ?? new CustomerApiEndpoint(), validator: customerValidator, model: CustomerModel });
|
|
13
|
-
}
|
|
14
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { Temporal } from 'temporal-polyfill';
|
|
2
|
-
|
|
3
|
-
import { AddressModel, type IdAddress } from '#address/model.js';
|
|
4
|
-
import { IdValidator } from '#core/common/id-validator.js';
|
|
5
|
-
import { type Validator, createdAtValidator, goldilocksValidator } from '#core/validator.js';
|
|
6
|
-
|
|
7
|
-
import { type CustomerData, CustomerModel, type IdCustomer } from './model.js';
|
|
8
|
-
|
|
9
|
-
export const customerValidator: Validator<CustomerData> = {
|
|
10
|
-
id: IdValidator<IdCustomer>(CustomerModel.regex),
|
|
11
|
-
billingAddress: IdValidator<IdAddress>(AddressModel.regex),
|
|
12
|
-
country: goldilocksValidator('country', { size: 2 }),
|
|
13
|
-
createdAt: createdAtValidator,
|
|
14
|
-
dateBirth: {
|
|
15
|
-
validate: (arg0: Temporal.PlainDate) =>
|
|
16
|
-
arg0 instanceof Temporal.PlainDate && Temporal.PlainDate.compare(Temporal.Now.plainDateISO(), arg0) === 1,
|
|
17
|
-
errorMessage: (arg0) => `DateBirth ${arg0.toString()} must be a Temporal.PlainDate set in the past.`,
|
|
18
|
-
},
|
|
19
|
-
deleted: true,
|
|
20
|
-
email: goldilocksValidator('email', { min: 1, max: 64 }),
|
|
21
|
-
externalId: goldilocksValidator('externalId', { min: 1, max: 36 }),
|
|
22
|
-
legalId: goldilocksValidator('legalId', { min: 1, max: 16 }),
|
|
23
|
-
mobile: goldilocksValidator('mobile', { min: 1, max: 16 }),
|
|
24
|
-
name: goldilocksValidator('name', { min: 1, max: 64 }),
|
|
25
|
-
shippingAddress: IdValidator<IdAddress>(AddressModel.regex),
|
|
26
|
-
};
|
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
import { ApiEndpoint, baseHandler } from '#api/abstract-api-endpoint.js';
|
|
2
|
-
import { Http } from '#api/http/index.js';
|
|
3
|
-
import { RFC9557Handler, timestampHandler } from '#core/common/handler/date-handler.js';
|
|
4
|
-
import { enumHandler } from '#core/common/handler/enum-handler.js';
|
|
5
|
-
import { type Handler, defaultHandler, setAccess } from '#core/common/handler/handler.js';
|
|
6
|
-
import { IdHandler } from '#core/common/handler/id-handler.js';
|
|
7
|
-
import { RefundApiEndpoint } from '#refund/api-endpoint.js';
|
|
8
|
-
import { RefundModel } from '#refund/model.js';
|
|
9
|
-
import { refundValidator } from '#refund/validator.js';
|
|
10
|
-
|
|
11
|
-
import { AddressModel, type IdAddress } from '../address/model.js';
|
|
12
|
-
import { CardModel, type IdCard } from '../card/model.js';
|
|
13
|
-
import { CustomerModel, type IdCustomer } from '../customer/model.js';
|
|
14
|
-
import { type IdPaymentIntent, PaymentIntentModel } from '../payment-intent/model.js';
|
|
15
|
-
import { type IdPayout, PayoutModel } from '../payout/model.js';
|
|
16
|
-
import { type IdSepa, SepaModel } from '../sepa/model.js';
|
|
17
|
-
import { CurrencyEnum } from './enum/currency.js';
|
|
18
|
-
import { type Method, MethodEnum } from './enum/method.js';
|
|
19
|
-
import { StatusEnum } from './enum/status.js';
|
|
20
|
-
import { type Device, type IdPayment, type PaymentAmount, type PaymentData, PaymentModel } from './model.js';
|
|
21
|
-
|
|
22
|
-
const authHandler: Handler<boolean> = {
|
|
23
|
-
deserialize: (arg0: unknown): boolean | undefined => {
|
|
24
|
-
if (arg0) {
|
|
25
|
-
return true;
|
|
26
|
-
}
|
|
27
|
-
return undefined;
|
|
28
|
-
},
|
|
29
|
-
serialize: (arg0: boolean) => {
|
|
30
|
-
if (arg0 === false) {
|
|
31
|
-
return undefined;
|
|
32
|
-
}
|
|
33
|
-
return true;
|
|
34
|
-
},
|
|
35
|
-
...setAccess({}),
|
|
36
|
-
};
|
|
37
|
-
export const methodsAllowedHandler: Handler<Method[]> = {
|
|
38
|
-
deserialize: (arg0: unknown) => {
|
|
39
|
-
if (!Array.isArray(arg0)) {
|
|
40
|
-
return undefined;
|
|
41
|
-
}
|
|
42
|
-
return arg0
|
|
43
|
-
.map((value) => (MethodEnum.includes(value) ? value : undefined))
|
|
44
|
-
.filter((value) => value !== undefined) as Method[];
|
|
45
|
-
},
|
|
46
|
-
serialize: (arg0: Method[]) => {
|
|
47
|
-
return arg0;
|
|
48
|
-
},
|
|
49
|
-
...setAccess({}),
|
|
50
|
-
};
|
|
51
|
-
const deviceHandler: Handler<Device> = {
|
|
52
|
-
deserialize: (arg0: unknown) => (arg0 as Device) ?? undefined,
|
|
53
|
-
serialize: (arg0: Device) => arg0,
|
|
54
|
-
...setAccess({}),
|
|
55
|
-
};
|
|
56
|
-
export class PaymentApiEndpoint extends ApiEndpoint<PaymentData> {
|
|
57
|
-
public _handler = {
|
|
58
|
-
...baseHandler('created'),
|
|
59
|
-
id: IdHandler<IdPayment>(PaymentModel.regex),
|
|
60
|
-
amount: defaultHandler<PaymentAmount>('number', { postRequired: true }),
|
|
61
|
-
auth: authHandler,
|
|
62
|
-
billingAddress: IdHandler<IdAddress>(AddressModel.regex, { postable: true }),
|
|
63
|
-
card: IdHandler<IdCard>(CardModel.regex, { postable: true }),
|
|
64
|
-
capture: defaultHandler<PaymentData['capture']>('boolean', {}),
|
|
65
|
-
currency: enumHandler(CurrencyEnum, { postable: true, postRequired: true }),
|
|
66
|
-
customer: IdHandler<IdCustomer>(CustomerModel.regex, { postable: true, patchable: true }),
|
|
67
|
-
dateBank: RFC9557Handler({ postable: false, patchable: false }),
|
|
68
|
-
datePayment: timestampHandler({ postable: false, patchable: false }, 'date_paym'),
|
|
69
|
-
dateSettlement: RFC9557Handler({}),
|
|
70
|
-
description: defaultHandler<PaymentData['description']>('string'),
|
|
71
|
-
device: deviceHandler,
|
|
72
|
-
fee: defaultHandler<PaymentData['fee']>('number', { postable: false, patchable: false }),
|
|
73
|
-
method: enumHandler(MethodEnum, { postable: false, patchable: false }),
|
|
74
|
-
methodsAllowed: methodsAllowedHandler,
|
|
75
|
-
orderId: defaultHandler<PaymentData['orderId']>('string'),
|
|
76
|
-
origin: defaultHandler<PaymentData['origin']>('string', { postable: false, patchable: false }),
|
|
77
|
-
paymentIntent: IdHandler<IdPaymentIntent>(PaymentIntentModel.regex, { postable: false, patchable: false }),
|
|
78
|
-
payout: IdHandler<IdPayout>(PayoutModel.regex, { postable: false, patchable: false }),
|
|
79
|
-
response: defaultHandler<PaymentData['response']>('string', { postable: false, patchable: false }),
|
|
80
|
-
responseAuthor: defaultHandler<PaymentData['responseAuthor']>('string', { postable: false, patchable: false }),
|
|
81
|
-
returnUrl: defaultHandler<PaymentData['returnUrl']>('string'),
|
|
82
|
-
sepa: IdHandler<IdSepa>(SepaModel.regex, { postable: true }),
|
|
83
|
-
shippingAddress: IdHandler<IdAddress>(AddressModel.regex, { postable: true }),
|
|
84
|
-
status: enumHandler(StatusEnum, { postable: false }),
|
|
85
|
-
uniqueId: defaultHandler<PaymentData['uniqueId']>('string', { patchable: false }),
|
|
86
|
-
wallet: defaultHandler<PaymentData['wallet']>('object', { gettable: false }),
|
|
87
|
-
};
|
|
88
|
-
private _refundApiEndpoint?: RefundApiEndpoint;
|
|
89
|
-
constructor(refundApiEndpoint?: RefundApiEndpoint) {
|
|
90
|
-
super({
|
|
91
|
-
name: 'payments',
|
|
92
|
-
});
|
|
93
|
-
if (refundApiEndpoint) {
|
|
94
|
-
this._refundApiEndpoint = refundApiEndpoint;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
async refunds(id: IdPayment): Promise<RefundModel[]> {
|
|
99
|
-
if (this._refundApiEndpoint === undefined) {
|
|
100
|
-
this._refundApiEndpoint = new RefundApiEndpoint();
|
|
101
|
-
}
|
|
102
|
-
const refundEndpoint = this._refundApiEndpoint;
|
|
103
|
-
return this._httpClient
|
|
104
|
-
.makeRequest(
|
|
105
|
-
Http.createRequest({
|
|
106
|
-
url: `${this._getResourceUri(id)}/refunds`,
|
|
107
|
-
method: 'GET',
|
|
108
|
-
authenticated: true,
|
|
109
|
-
}),
|
|
110
|
-
)
|
|
111
|
-
.then(Http.transformResponseToData<Record<string, unknown>[]>)
|
|
112
|
-
.then((refunds) =>
|
|
113
|
-
Object.values(refunds).map(
|
|
114
|
-
(data) => new RefundModel(refundValidator, refundEndpoint.deserializeResource(data)),
|
|
115
|
-
),
|
|
116
|
-
);
|
|
117
|
-
}
|
|
118
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
export const StatusEnum = [
|
|
2
|
-
'refused',
|
|
3
|
-
'authorized',
|
|
4
|
-
'expired',
|
|
5
|
-
'to_capture',
|
|
6
|
-
'capture_sent',
|
|
7
|
-
'captured',
|
|
8
|
-
'disputed',
|
|
9
|
-
'canceled',
|
|
10
|
-
'failed',
|
|
11
|
-
'authorize',
|
|
12
|
-
'capture',
|
|
13
|
-
] as const;
|
|
14
|
-
|
|
15
|
-
export type PaymentStatus = (typeof StatusEnum)[number];
|
|
16
|
-
|
|
17
|
-
export const succeedPaymentStatus = [
|
|
18
|
-
'to_capture',
|
|
19
|
-
'capture_sent',
|
|
20
|
-
'captured',
|
|
21
|
-
];
|