@jogolabs/billing-sdk-v2 0.0.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/.eslintignore +1 -0
- package/.eslintrc.js +18 -0
- package/dist/billing/src/__generated__/Billing.d.ts +20 -0
- package/dist/billing/src/__generated__/Billing.js +39 -0
- package/dist/billing/src/__generated__/core/ApiError.d.ts +10 -0
- package/dist/billing/src/__generated__/core/ApiError.js +20 -0
- package/dist/billing/src/__generated__/core/ApiRequestOptions.d.ts +13 -0
- package/dist/billing/src/__generated__/core/ApiRequestOptions.js +2 -0
- package/dist/billing/src/__generated__/core/ApiResult.d.ts +7 -0
- package/dist/billing/src/__generated__/core/ApiResult.js +2 -0
- package/dist/billing/src/__generated__/core/AxiosHttpRequest.d.ts +14 -0
- package/dist/billing/src/__generated__/core/AxiosHttpRequest.js +20 -0
- package/dist/billing/src/__generated__/core/BaseHttpRequest.d.ts +8 -0
- package/dist/billing/src/__generated__/core/BaseHttpRequest.js +10 -0
- package/dist/billing/src/__generated__/core/CancelablePromise.d.ts +20 -0
- package/dist/billing/src/__generated__/core/CancelablePromise.js +104 -0
- package/dist/billing/src/__generated__/core/OpenAPI.d.ts +16 -0
- package/dist/billing/src/__generated__/core/OpenAPI.js +14 -0
- package/dist/billing/src/__generated__/core/request.d.ts +34 -0
- package/dist/billing/src/__generated__/core/request.js +292 -0
- package/dist/billing/src/__generated__/index.d.ts +42 -0
- package/dist/billing/src/__generated__/index.js +74 -0
- package/dist/billing/src/__generated__/models/ConsumeClassResponse.d.ts +5 -0
- package/dist/billing/src/__generated__/models/ConsumeClassResponse.js +2 -0
- package/dist/billing/src/__generated__/models/CreateMerchantRequest.d.ts +23 -0
- package/dist/billing/src/__generated__/models/CreateMerchantRequest.js +15 -0
- package/dist/billing/src/__generated__/models/CreatePackageRequest.d.ts +8 -0
- package/dist/billing/src/__generated__/models/CreatePackageRequest.js +2 -0
- package/dist/billing/src/__generated__/models/CreateSubscriptionRequest.d.ts +25 -0
- package/dist/billing/src/__generated__/models/CreateSubscriptionRequest.js +2 -0
- package/dist/billing/src/__generated__/models/CreateSubscriptionResponse.d.ts +8 -0
- package/dist/billing/src/__generated__/models/CreateSubscriptionResponse.js +2 -0
- package/dist/billing/src/__generated__/models/Error.d.ts +3 -0
- package/dist/billing/src/__generated__/models/Error.js +2 -0
- package/dist/billing/src/__generated__/models/Merchant.d.ts +20 -0
- package/dist/billing/src/__generated__/models/Merchant.js +10 -0
- package/dist/billing/src/__generated__/models/MerchantProviderConfig.d.ts +15 -0
- package/dist/billing/src/__generated__/models/MerchantProviderConfig.js +11 -0
- package/dist/billing/src/__generated__/models/Package.d.ts +14 -0
- package/dist/billing/src/__generated__/models/Package.js +2 -0
- package/dist/billing/src/__generated__/models/Payment.d.ts +32 -0
- package/dist/billing/src/__generated__/models/Payment.js +22 -0
- package/dist/billing/src/__generated__/models/SavedCard.d.ts +18 -0
- package/dist/billing/src/__generated__/models/SavedCard.js +10 -0
- package/dist/billing/src/__generated__/models/Subscription.d.ts +33 -0
- package/dist/billing/src/__generated__/models/Subscription.js +14 -0
- package/dist/billing/src/__generated__/models/TokenizeCardRequest.d.ts +8 -0
- package/dist/billing/src/__generated__/models/TokenizeCardRequest.js +2 -0
- package/dist/billing/src/__generated__/models/UpdateMerchantRequest.d.ts +16 -0
- package/dist/billing/src/__generated__/models/UpdateMerchantRequest.js +11 -0
- package/dist/billing/src/__generated__/models/UpdatePackageRequest.d.ts +9 -0
- package/dist/billing/src/__generated__/models/UpdatePackageRequest.js +2 -0
- package/dist/billing/src/__generated__/schemas/$ConsumeClassResponse.d.ts +10 -0
- package/dist/billing/src/__generated__/schemas/$ConsumeClassResponse.js +17 -0
- package/dist/billing/src/__generated__/schemas/$CreateMerchantRequest.d.ts +39 -0
- package/dist/billing/src/__generated__/schemas/$CreateMerchantRequest.js +46 -0
- package/dist/billing/src/__generated__/schemas/$CreatePackageRequest.d.ts +28 -0
- package/dist/billing/src/__generated__/schemas/$CreatePackageRequest.js +35 -0
- package/dist/billing/src/__generated__/schemas/$CreateSubscriptionRequest.d.ts +57 -0
- package/dist/billing/src/__generated__/schemas/$CreateSubscriptionRequest.js +64 -0
- package/dist/billing/src/__generated__/schemas/$CreateSubscriptionResponse.d.ts +13 -0
- package/dist/billing/src/__generated__/schemas/$CreateSubscriptionResponse.js +20 -0
- package/dist/billing/src/__generated__/schemas/$Error.d.ts +7 -0
- package/dist/billing/src/__generated__/schemas/$Error.js +14 -0
- package/dist/billing/src/__generated__/schemas/$Merchant.d.ts +35 -0
- package/dist/billing/src/__generated__/schemas/$Merchant.js +42 -0
- package/dist/billing/src/__generated__/schemas/$MerchantProviderConfig.d.ts +19 -0
- package/dist/billing/src/__generated__/schemas/$MerchantProviderConfig.js +26 -0
- package/dist/billing/src/__generated__/schemas/$Package.d.ts +43 -0
- package/dist/billing/src/__generated__/schemas/$Package.js +50 -0
- package/dist/billing/src/__generated__/schemas/$Payment.d.ts +43 -0
- package/dist/billing/src/__generated__/schemas/$Payment.js +50 -0
- package/dist/billing/src/__generated__/schemas/$SavedCard.d.ts +39 -0
- package/dist/billing/src/__generated__/schemas/$SavedCard.js +46 -0
- package/dist/billing/src/__generated__/schemas/$Subscription.d.ts +63 -0
- package/dist/billing/src/__generated__/schemas/$Subscription.js +70 -0
- package/dist/billing/src/__generated__/schemas/$TokenizeCardRequest.d.ts +29 -0
- package/dist/billing/src/__generated__/schemas/$TokenizeCardRequest.js +36 -0
- package/dist/billing/src/__generated__/schemas/$UpdateMerchantRequest.d.ts +31 -0
- package/dist/billing/src/__generated__/schemas/$UpdateMerchantRequest.js +38 -0
- package/dist/billing/src/__generated__/schemas/$UpdatePackageRequest.d.ts +27 -0
- package/dist/billing/src/__generated__/schemas/$UpdatePackageRequest.js +34 -0
- package/dist/billing/src/__generated__/services/CardsService.d.ts +54 -0
- package/dist/billing/src/__generated__/services/CardsService.js +89 -0
- package/dist/billing/src/__generated__/services/HealthService.d.ts +16 -0
- package/dist/billing/src/__generated__/services/HealthService.js +22 -0
- package/dist/billing/src/__generated__/services/MerchantsService.d.ts +43 -0
- package/dist/billing/src/__generated__/services/MerchantsService.js +71 -0
- package/dist/billing/src/__generated__/services/PackagesService.d.ts +66 -0
- package/dist/billing/src/__generated__/services/PackagesService.js +110 -0
- package/dist/billing/src/__generated__/services/PaymentsService.d.ts +53 -0
- package/dist/billing/src/__generated__/services/PaymentsService.js +66 -0
- package/dist/billing/src/__generated__/services/SubscriptionsService.d.ts +86 -0
- package/dist/billing/src/__generated__/services/SubscriptionsService.js +148 -0
- package/dist/billing/src/index.d.ts +1 -0
- package/dist/billing/src/index.js +17 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +54 -0
- package/package.json +36 -0
- package/scripts/generate-api-sdk.js +86 -0
- package/scripts/publish.js +72 -0
- package/src/billing/src/__generated__/Billing.ts +43 -0
- package/src/billing/src/__generated__/core/ApiError.ts +25 -0
- package/src/billing/src/__generated__/core/ApiRequestOptions.ts +17 -0
- package/src/billing/src/__generated__/core/ApiResult.ts +11 -0
- package/src/billing/src/__generated__/core/AxiosHttpRequest.ts +26 -0
- package/src/billing/src/__generated__/core/BaseHttpRequest.ts +14 -0
- package/src/billing/src/__generated__/core/CancelablePromise.ts +131 -0
- package/src/billing/src/__generated__/core/OpenAPI.ts +32 -0
- package/src/billing/src/__generated__/core/request.ts +323 -0
- package/src/billing/src/__generated__/index.ts +50 -0
- package/src/billing/src/__generated__/models/ConsumeClassResponse.ts +10 -0
- package/src/billing/src/__generated__/models/CreateMerchantRequest.ts +28 -0
- package/src/billing/src/__generated__/models/CreatePackageRequest.ts +13 -0
- package/src/billing/src/__generated__/models/CreateSubscriptionRequest.ts +30 -0
- package/src/billing/src/__generated__/models/CreateSubscriptionResponse.ts +13 -0
- package/src/billing/src/__generated__/models/Error.ts +8 -0
- package/src/billing/src/__generated__/models/Merchant.ts +25 -0
- package/src/billing/src/__generated__/models/MerchantProviderConfig.ts +20 -0
- package/src/billing/src/__generated__/models/Package.ts +19 -0
- package/src/billing/src/__generated__/models/Payment.ts +37 -0
- package/src/billing/src/__generated__/models/SavedCard.ts +23 -0
- package/src/billing/src/__generated__/models/Subscription.ts +38 -0
- package/src/billing/src/__generated__/models/TokenizeCardRequest.ts +13 -0
- package/src/billing/src/__generated__/models/UpdateMerchantRequest.ts +21 -0
- package/src/billing/src/__generated__/models/UpdatePackageRequest.ts +14 -0
- package/src/billing/src/__generated__/schemas/$ConsumeClassResponse.ts +14 -0
- package/src/billing/src/__generated__/schemas/$CreateMerchantRequest.ts +43 -0
- package/src/billing/src/__generated__/schemas/$CreatePackageRequest.ts +32 -0
- package/src/billing/src/__generated__/schemas/$CreateSubscriptionRequest.ts +61 -0
- package/src/billing/src/__generated__/schemas/$CreateSubscriptionResponse.ts +17 -0
- package/src/billing/src/__generated__/schemas/$Error.ts +11 -0
- package/src/billing/src/__generated__/schemas/$Merchant.ts +39 -0
- package/src/billing/src/__generated__/schemas/$MerchantProviderConfig.ts +23 -0
- package/src/billing/src/__generated__/schemas/$Package.ts +47 -0
- package/src/billing/src/__generated__/schemas/$Payment.ts +47 -0
- package/src/billing/src/__generated__/schemas/$SavedCard.ts +43 -0
- package/src/billing/src/__generated__/schemas/$Subscription.ts +67 -0
- package/src/billing/src/__generated__/schemas/$TokenizeCardRequest.ts +33 -0
- package/src/billing/src/__generated__/schemas/$UpdateMerchantRequest.ts +35 -0
- package/src/billing/src/__generated__/schemas/$UpdatePackageRequest.ts +31 -0
- package/src/billing/src/__generated__/services/CardsService.ts +115 -0
- package/src/billing/src/__generated__/services/HealthService.ts +24 -0
- package/src/billing/src/__generated__/services/MerchantsService.ts +90 -0
- package/src/billing/src/__generated__/services/PackagesService.ts +150 -0
- package/src/billing/src/__generated__/services/PaymentsService.ts +96 -0
- package/src/billing/src/__generated__/services/SubscriptionsService.ts +185 -0
- package/src/billing/src/index.ts +1 -0
- package/src/index.ts +49 -0
- package/tsconfig.json +18 -0
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/* generated using openapi-typescript-codegen -- do not edit */
|
|
2
|
+
/* istanbul ignore file */
|
|
3
|
+
/* tslint:disable */
|
|
4
|
+
/* eslint-disable */
|
|
5
|
+
export class CancelError extends Error {
|
|
6
|
+
|
|
7
|
+
constructor(message: string) {
|
|
8
|
+
super(message);
|
|
9
|
+
this.name = 'CancelError';
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
public get isCancelled(): boolean {
|
|
13
|
+
return true;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface OnCancel {
|
|
18
|
+
readonly isResolved: boolean;
|
|
19
|
+
readonly isRejected: boolean;
|
|
20
|
+
readonly isCancelled: boolean;
|
|
21
|
+
|
|
22
|
+
(cancelHandler: () => void): void;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export class CancelablePromise<T> implements Promise<T> {
|
|
26
|
+
#isResolved: boolean;
|
|
27
|
+
#isRejected: boolean;
|
|
28
|
+
#isCancelled: boolean;
|
|
29
|
+
readonly #cancelHandlers: (() => void)[];
|
|
30
|
+
readonly #promise: Promise<T>;
|
|
31
|
+
#resolve?: (value: T | PromiseLike<T>) => void;
|
|
32
|
+
#reject?: (reason?: any) => void;
|
|
33
|
+
|
|
34
|
+
constructor(
|
|
35
|
+
executor: (
|
|
36
|
+
resolve: (value: T | PromiseLike<T>) => void,
|
|
37
|
+
reject: (reason?: any) => void,
|
|
38
|
+
onCancel: OnCancel
|
|
39
|
+
) => void
|
|
40
|
+
) {
|
|
41
|
+
this.#isResolved = false;
|
|
42
|
+
this.#isRejected = false;
|
|
43
|
+
this.#isCancelled = false;
|
|
44
|
+
this.#cancelHandlers = [];
|
|
45
|
+
this.#promise = new Promise<T>((resolve, reject) => {
|
|
46
|
+
this.#resolve = resolve;
|
|
47
|
+
this.#reject = reject;
|
|
48
|
+
|
|
49
|
+
const onResolve = (value: T | PromiseLike<T>): void => {
|
|
50
|
+
if (this.#isResolved || this.#isRejected || this.#isCancelled) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
this.#isResolved = true;
|
|
54
|
+
if (this.#resolve) this.#resolve(value);
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const onReject = (reason?: any): void => {
|
|
58
|
+
if (this.#isResolved || this.#isRejected || this.#isCancelled) {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
this.#isRejected = true;
|
|
62
|
+
if (this.#reject) this.#reject(reason);
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
const onCancel = (cancelHandler: () => void): void => {
|
|
66
|
+
if (this.#isResolved || this.#isRejected || this.#isCancelled) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
this.#cancelHandlers.push(cancelHandler);
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
Object.defineProperty(onCancel, 'isResolved', {
|
|
73
|
+
get: (): boolean => this.#isResolved,
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
Object.defineProperty(onCancel, 'isRejected', {
|
|
77
|
+
get: (): boolean => this.#isRejected,
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
Object.defineProperty(onCancel, 'isCancelled', {
|
|
81
|
+
get: (): boolean => this.#isCancelled,
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
return executor(onResolve, onReject, onCancel as OnCancel);
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
get [Symbol.toStringTag]() {
|
|
89
|
+
return "Cancellable Promise";
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
public then<TResult1 = T, TResult2 = never>(
|
|
93
|
+
onFulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | null,
|
|
94
|
+
onRejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null
|
|
95
|
+
): Promise<TResult1 | TResult2> {
|
|
96
|
+
return this.#promise.then(onFulfilled, onRejected);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
public catch<TResult = never>(
|
|
100
|
+
onRejected?: ((reason: any) => TResult | PromiseLike<TResult>) | null
|
|
101
|
+
): Promise<T | TResult> {
|
|
102
|
+
return this.#promise.catch(onRejected);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
public finally(onFinally?: (() => void) | null): Promise<T> {
|
|
106
|
+
return this.#promise.finally(onFinally);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
public cancel(): void {
|
|
110
|
+
if (this.#isResolved || this.#isRejected || this.#isCancelled) {
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
this.#isCancelled = true;
|
|
114
|
+
if (this.#cancelHandlers.length) {
|
|
115
|
+
try {
|
|
116
|
+
for (const cancelHandler of this.#cancelHandlers) {
|
|
117
|
+
cancelHandler();
|
|
118
|
+
}
|
|
119
|
+
} catch (error) {
|
|
120
|
+
console.warn('Cancellation threw an error', error);
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
this.#cancelHandlers.length = 0;
|
|
125
|
+
if (this.#reject) this.#reject(new CancelError('Request aborted'));
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
public get isCancelled(): boolean {
|
|
129
|
+
return this.#isCancelled;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/* generated using openapi-typescript-codegen -- do not edit */
|
|
2
|
+
/* istanbul ignore file */
|
|
3
|
+
/* tslint:disable */
|
|
4
|
+
/* eslint-disable */
|
|
5
|
+
import type { ApiRequestOptions } from './ApiRequestOptions';
|
|
6
|
+
|
|
7
|
+
type Resolver<T> = (options: ApiRequestOptions) => Promise<T>;
|
|
8
|
+
type Headers = Record<string, string>;
|
|
9
|
+
|
|
10
|
+
export type OpenAPIConfig = {
|
|
11
|
+
BASE: string;
|
|
12
|
+
VERSION: string;
|
|
13
|
+
WITH_CREDENTIALS: boolean;
|
|
14
|
+
CREDENTIALS: 'include' | 'omit' | 'same-origin';
|
|
15
|
+
TOKEN?: string | Resolver<string> | undefined;
|
|
16
|
+
USERNAME?: string | Resolver<string> | undefined;
|
|
17
|
+
PASSWORD?: string | Resolver<string> | undefined;
|
|
18
|
+
HEADERS?: Headers | Resolver<Headers> | undefined;
|
|
19
|
+
ENCODE_PATH?: ((path: string) => string) | undefined;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export const OpenAPI: OpenAPIConfig = {
|
|
23
|
+
BASE: 'http://localhost:3003',
|
|
24
|
+
VERSION: '1.0.0',
|
|
25
|
+
WITH_CREDENTIALS: false,
|
|
26
|
+
CREDENTIALS: 'include',
|
|
27
|
+
TOKEN: undefined,
|
|
28
|
+
USERNAME: undefined,
|
|
29
|
+
PASSWORD: undefined,
|
|
30
|
+
HEADERS: undefined,
|
|
31
|
+
ENCODE_PATH: undefined,
|
|
32
|
+
};
|
|
@@ -0,0 +1,323 @@
|
|
|
1
|
+
/* generated using openapi-typescript-codegen -- do not edit */
|
|
2
|
+
/* istanbul ignore file */
|
|
3
|
+
/* tslint:disable */
|
|
4
|
+
/* eslint-disable */
|
|
5
|
+
import axios from 'axios';
|
|
6
|
+
import type { AxiosError, AxiosRequestConfig, AxiosResponse, AxiosInstance } from 'axios';
|
|
7
|
+
import FormData from 'form-data';
|
|
8
|
+
|
|
9
|
+
import { ApiError } from './ApiError';
|
|
10
|
+
import type { ApiRequestOptions } from './ApiRequestOptions';
|
|
11
|
+
import type { ApiResult } from './ApiResult';
|
|
12
|
+
import { CancelablePromise } from './CancelablePromise';
|
|
13
|
+
import type { OnCancel } from './CancelablePromise';
|
|
14
|
+
import type { OpenAPIConfig } from './OpenAPI';
|
|
15
|
+
|
|
16
|
+
export const isDefined = <T>(value: T | null | undefined): value is Exclude<T, null | undefined> => {
|
|
17
|
+
return value !== undefined && value !== null;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export const isString = (value: any): value is string => {
|
|
21
|
+
return typeof value === 'string';
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export const isStringWithValue = (value: any): value is string => {
|
|
25
|
+
return isString(value) && value !== '';
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export const isBlob = (value: any): value is Blob => {
|
|
29
|
+
return (
|
|
30
|
+
typeof value === 'object' &&
|
|
31
|
+
typeof value.type === 'string' &&
|
|
32
|
+
typeof value.stream === 'function' &&
|
|
33
|
+
typeof value.arrayBuffer === 'function' &&
|
|
34
|
+
typeof value.constructor === 'function' &&
|
|
35
|
+
typeof value.constructor.name === 'string' &&
|
|
36
|
+
/^(Blob|File)$/.test(value.constructor.name) &&
|
|
37
|
+
/^(Blob|File)$/.test(value[Symbol.toStringTag])
|
|
38
|
+
);
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export const isFormData = (value: any): value is FormData => {
|
|
42
|
+
return value instanceof FormData;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export const isSuccess = (status: number): boolean => {
|
|
46
|
+
return status >= 200 && status < 300;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export const base64 = (str: string): string => {
|
|
50
|
+
try {
|
|
51
|
+
return btoa(str);
|
|
52
|
+
} catch (err) {
|
|
53
|
+
// @ts-ignore
|
|
54
|
+
return Buffer.from(str).toString('base64');
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
export const getQueryString = (params: Record<string, any>): string => {
|
|
59
|
+
const qs: string[] = [];
|
|
60
|
+
|
|
61
|
+
const append = (key: string, value: any) => {
|
|
62
|
+
qs.push(`${encodeURIComponent(key)}=${encodeURIComponent(String(value))}`);
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
const process = (key: string, value: any) => {
|
|
66
|
+
if (isDefined(value)) {
|
|
67
|
+
if (Array.isArray(value)) {
|
|
68
|
+
value.forEach(v => {
|
|
69
|
+
process(key, v);
|
|
70
|
+
});
|
|
71
|
+
} else if (typeof value === 'object') {
|
|
72
|
+
Object.entries(value).forEach(([k, v]) => {
|
|
73
|
+
process(`${key}[${k}]`, v);
|
|
74
|
+
});
|
|
75
|
+
} else {
|
|
76
|
+
append(key, value);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
Object.entries(params).forEach(([key, value]) => {
|
|
82
|
+
process(key, value);
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
if (qs.length > 0) {
|
|
86
|
+
return `?${qs.join('&')}`;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return '';
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
const getUrl = (config: OpenAPIConfig, options: ApiRequestOptions): string => {
|
|
93
|
+
const encoder = config.ENCODE_PATH || encodeURI;
|
|
94
|
+
|
|
95
|
+
const path = options.url
|
|
96
|
+
.replace('{api-version}', config.VERSION)
|
|
97
|
+
.replace(/{(.*?)}/g, (substring: string, group: string) => {
|
|
98
|
+
if (options.path?.hasOwnProperty(group)) {
|
|
99
|
+
return encoder(String(options.path[group]));
|
|
100
|
+
}
|
|
101
|
+
return substring;
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
const url = `${config.BASE}${path}`;
|
|
105
|
+
if (options.query) {
|
|
106
|
+
return `${url}${getQueryString(options.query)}`;
|
|
107
|
+
}
|
|
108
|
+
return url;
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
export const getFormData = (options: ApiRequestOptions): FormData | undefined => {
|
|
112
|
+
if (options.formData) {
|
|
113
|
+
const formData = new FormData();
|
|
114
|
+
|
|
115
|
+
const process = (key: string, value: any) => {
|
|
116
|
+
if (isString(value) || isBlob(value)) {
|
|
117
|
+
formData.append(key, value);
|
|
118
|
+
} else {
|
|
119
|
+
formData.append(key, JSON.stringify(value));
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
Object.entries(options.formData)
|
|
124
|
+
.filter(([_, value]) => isDefined(value))
|
|
125
|
+
.forEach(([key, value]) => {
|
|
126
|
+
if (Array.isArray(value)) {
|
|
127
|
+
value.forEach(v => process(key, v));
|
|
128
|
+
} else {
|
|
129
|
+
process(key, value);
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
return formData;
|
|
134
|
+
}
|
|
135
|
+
return undefined;
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
type Resolver<T> = (options: ApiRequestOptions) => Promise<T>;
|
|
139
|
+
|
|
140
|
+
export const resolve = async <T>(options: ApiRequestOptions, resolver?: T | Resolver<T>): Promise<T | undefined> => {
|
|
141
|
+
if (typeof resolver === 'function') {
|
|
142
|
+
return (resolver as Resolver<T>)(options);
|
|
143
|
+
}
|
|
144
|
+
return resolver;
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
export const getHeaders = async (config: OpenAPIConfig, options: ApiRequestOptions, formData?: FormData): Promise<Record<string, string>> => {
|
|
148
|
+
const [token, username, password, additionalHeaders] = await Promise.all([
|
|
149
|
+
resolve(options, config.TOKEN),
|
|
150
|
+
resolve(options, config.USERNAME),
|
|
151
|
+
resolve(options, config.PASSWORD),
|
|
152
|
+
resolve(options, config.HEADERS),
|
|
153
|
+
]);
|
|
154
|
+
|
|
155
|
+
const formHeaders = typeof formData?.getHeaders === 'function' && formData?.getHeaders() || {}
|
|
156
|
+
|
|
157
|
+
const headers = Object.entries({
|
|
158
|
+
Accept: 'application/json',
|
|
159
|
+
...additionalHeaders,
|
|
160
|
+
...options.headers,
|
|
161
|
+
...formHeaders,
|
|
162
|
+
})
|
|
163
|
+
.filter(([_, value]) => isDefined(value))
|
|
164
|
+
.reduce((headers, [key, value]) => ({
|
|
165
|
+
...headers,
|
|
166
|
+
[key]: String(value),
|
|
167
|
+
}), {} as Record<string, string>);
|
|
168
|
+
|
|
169
|
+
if (isStringWithValue(token)) {
|
|
170
|
+
headers['Authorization'] = `Bearer ${token}`;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
if (isStringWithValue(username) && isStringWithValue(password)) {
|
|
174
|
+
const credentials = base64(`${username}:${password}`);
|
|
175
|
+
headers['Authorization'] = `Basic ${credentials}`;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
if (options.body !== undefined) {
|
|
179
|
+
if (options.mediaType) {
|
|
180
|
+
headers['Content-Type'] = options.mediaType;
|
|
181
|
+
} else if (isBlob(options.body)) {
|
|
182
|
+
headers['Content-Type'] = options.body.type || 'application/octet-stream';
|
|
183
|
+
} else if (isString(options.body)) {
|
|
184
|
+
headers['Content-Type'] = 'text/plain';
|
|
185
|
+
} else if (!isFormData(options.body)) {
|
|
186
|
+
headers['Content-Type'] = 'application/json';
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
return headers;
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
export const getRequestBody = (options: ApiRequestOptions): any => {
|
|
194
|
+
if (options.body) {
|
|
195
|
+
return options.body;
|
|
196
|
+
}
|
|
197
|
+
return undefined;
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
export const sendRequest = async <T>(
|
|
201
|
+
config: OpenAPIConfig,
|
|
202
|
+
options: ApiRequestOptions,
|
|
203
|
+
url: string,
|
|
204
|
+
body: any,
|
|
205
|
+
formData: FormData | undefined,
|
|
206
|
+
headers: Record<string, string>,
|
|
207
|
+
onCancel: OnCancel,
|
|
208
|
+
axiosClient: AxiosInstance
|
|
209
|
+
): Promise<AxiosResponse<T>> => {
|
|
210
|
+
const source = axios.CancelToken.source();
|
|
211
|
+
|
|
212
|
+
const requestConfig: AxiosRequestConfig = {
|
|
213
|
+
url,
|
|
214
|
+
headers,
|
|
215
|
+
data: body ?? formData,
|
|
216
|
+
method: options.method,
|
|
217
|
+
withCredentials: config.WITH_CREDENTIALS,
|
|
218
|
+
withXSRFToken: config.CREDENTIALS === 'include' ? config.WITH_CREDENTIALS : false,
|
|
219
|
+
cancelToken: source.token,
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
onCancel(() => source.cancel('The user aborted a request.'));
|
|
223
|
+
|
|
224
|
+
try {
|
|
225
|
+
return await axiosClient.request(requestConfig);
|
|
226
|
+
} catch (error) {
|
|
227
|
+
const axiosError = error as AxiosError<T>;
|
|
228
|
+
if (axiosError.response) {
|
|
229
|
+
return axiosError.response;
|
|
230
|
+
}
|
|
231
|
+
throw error;
|
|
232
|
+
}
|
|
233
|
+
};
|
|
234
|
+
|
|
235
|
+
export const getResponseHeader = (response: AxiosResponse<any>, responseHeader?: string): string | undefined => {
|
|
236
|
+
if (responseHeader) {
|
|
237
|
+
const content = response.headers[responseHeader];
|
|
238
|
+
if (isString(content)) {
|
|
239
|
+
return content;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
return undefined;
|
|
243
|
+
};
|
|
244
|
+
|
|
245
|
+
export const getResponseBody = (response: AxiosResponse<any>): any => {
|
|
246
|
+
if (response.status !== 204) {
|
|
247
|
+
return response.data;
|
|
248
|
+
}
|
|
249
|
+
return undefined;
|
|
250
|
+
};
|
|
251
|
+
|
|
252
|
+
export const catchErrorCodes = (options: ApiRequestOptions, result: ApiResult): void => {
|
|
253
|
+
const errors: Record<number, string> = {
|
|
254
|
+
400: 'Bad Request',
|
|
255
|
+
401: 'Unauthorized',
|
|
256
|
+
403: 'Forbidden',
|
|
257
|
+
404: 'Not Found',
|
|
258
|
+
500: 'Internal Server Error',
|
|
259
|
+
502: 'Bad Gateway',
|
|
260
|
+
503: 'Service Unavailable',
|
|
261
|
+
...options.errors,
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
const error = errors[result.status];
|
|
265
|
+
if (error) {
|
|
266
|
+
throw new ApiError(options, result, error);
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
if (!result.ok) {
|
|
270
|
+
const errorStatus = result.status ?? 'unknown';
|
|
271
|
+
const errorStatusText = result.statusText ?? 'unknown';
|
|
272
|
+
const errorBody = (() => {
|
|
273
|
+
try {
|
|
274
|
+
return JSON.stringify(result.body, null, 2);
|
|
275
|
+
} catch (e) {
|
|
276
|
+
return undefined;
|
|
277
|
+
}
|
|
278
|
+
})();
|
|
279
|
+
|
|
280
|
+
throw new ApiError(options, result,
|
|
281
|
+
`Generic Error: status: ${errorStatus}; status text: ${errorStatusText}; body: ${errorBody}`
|
|
282
|
+
);
|
|
283
|
+
}
|
|
284
|
+
};
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* Request method
|
|
288
|
+
* @param config The OpenAPI configuration object
|
|
289
|
+
* @param options The request options from the service
|
|
290
|
+
* @param axiosClient The axios client instance to use
|
|
291
|
+
* @returns CancelablePromise<T>
|
|
292
|
+
* @throws ApiError
|
|
293
|
+
*/
|
|
294
|
+
export const request = <T>(config: OpenAPIConfig, options: ApiRequestOptions, axiosClient: AxiosInstance = axios): CancelablePromise<T> => {
|
|
295
|
+
return new CancelablePromise(async (resolve, reject, onCancel) => {
|
|
296
|
+
try {
|
|
297
|
+
const url = getUrl(config, options);
|
|
298
|
+
const formData = getFormData(options);
|
|
299
|
+
const body = getRequestBody(options);
|
|
300
|
+
const headers = await getHeaders(config, options, formData);
|
|
301
|
+
|
|
302
|
+
if (!onCancel.isCancelled) {
|
|
303
|
+
const response = await sendRequest<T>(config, options, url, body, formData, headers, onCancel, axiosClient);
|
|
304
|
+
const responseBody = getResponseBody(response);
|
|
305
|
+
const responseHeader = getResponseHeader(response, options.responseHeader);
|
|
306
|
+
|
|
307
|
+
const result: ApiResult = {
|
|
308
|
+
url,
|
|
309
|
+
ok: isSuccess(response.status),
|
|
310
|
+
status: response.status,
|
|
311
|
+
statusText: response.statusText,
|
|
312
|
+
body: responseHeader ?? responseBody,
|
|
313
|
+
};
|
|
314
|
+
|
|
315
|
+
catchErrorCodes(options, result);
|
|
316
|
+
|
|
317
|
+
resolve(result.body);
|
|
318
|
+
}
|
|
319
|
+
} catch (error) {
|
|
320
|
+
reject(error);
|
|
321
|
+
}
|
|
322
|
+
});
|
|
323
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/* generated using openapi-typescript-codegen -- do not edit */
|
|
2
|
+
/* istanbul ignore file */
|
|
3
|
+
/* tslint:disable */
|
|
4
|
+
/* eslint-disable */
|
|
5
|
+
export { Billing } from './Billing';
|
|
6
|
+
|
|
7
|
+
export { ApiError } from './core/ApiError';
|
|
8
|
+
export { BaseHttpRequest } from './core/BaseHttpRequest';
|
|
9
|
+
export { CancelablePromise, CancelError } from './core/CancelablePromise';
|
|
10
|
+
export { OpenAPI } from './core/OpenAPI';
|
|
11
|
+
export type { OpenAPIConfig } from './core/OpenAPI';
|
|
12
|
+
|
|
13
|
+
export type { ConsumeClassResponse } from './models/ConsumeClassResponse';
|
|
14
|
+
export { CreateMerchantRequest } from './models/CreateMerchantRequest';
|
|
15
|
+
export type { CreatePackageRequest } from './models/CreatePackageRequest';
|
|
16
|
+
export type { CreateSubscriptionRequest } from './models/CreateSubscriptionRequest';
|
|
17
|
+
export type { CreateSubscriptionResponse } from './models/CreateSubscriptionResponse';
|
|
18
|
+
export type { Error } from './models/Error';
|
|
19
|
+
export { Merchant } from './models/Merchant';
|
|
20
|
+
export { MerchantProviderConfig } from './models/MerchantProviderConfig';
|
|
21
|
+
export type { Package } from './models/Package';
|
|
22
|
+
export { Payment } from './models/Payment';
|
|
23
|
+
export { SavedCard } from './models/SavedCard';
|
|
24
|
+
export { Subscription } from './models/Subscription';
|
|
25
|
+
export type { TokenizeCardRequest } from './models/TokenizeCardRequest';
|
|
26
|
+
export { UpdateMerchantRequest } from './models/UpdateMerchantRequest';
|
|
27
|
+
export type { UpdatePackageRequest } from './models/UpdatePackageRequest';
|
|
28
|
+
|
|
29
|
+
export { $ConsumeClassResponse } from './schemas/$ConsumeClassResponse';
|
|
30
|
+
export { $CreateMerchantRequest } from './schemas/$CreateMerchantRequest';
|
|
31
|
+
export { $CreatePackageRequest } from './schemas/$CreatePackageRequest';
|
|
32
|
+
export { $CreateSubscriptionRequest } from './schemas/$CreateSubscriptionRequest';
|
|
33
|
+
export { $CreateSubscriptionResponse } from './schemas/$CreateSubscriptionResponse';
|
|
34
|
+
export { $Error } from './schemas/$Error';
|
|
35
|
+
export { $Merchant } from './schemas/$Merchant';
|
|
36
|
+
export { $MerchantProviderConfig } from './schemas/$MerchantProviderConfig';
|
|
37
|
+
export { $Package } from './schemas/$Package';
|
|
38
|
+
export { $Payment } from './schemas/$Payment';
|
|
39
|
+
export { $SavedCard } from './schemas/$SavedCard';
|
|
40
|
+
export { $Subscription } from './schemas/$Subscription';
|
|
41
|
+
export { $TokenizeCardRequest } from './schemas/$TokenizeCardRequest';
|
|
42
|
+
export { $UpdateMerchantRequest } from './schemas/$UpdateMerchantRequest';
|
|
43
|
+
export { $UpdatePackageRequest } from './schemas/$UpdatePackageRequest';
|
|
44
|
+
|
|
45
|
+
export { CardsService } from './services/CardsService';
|
|
46
|
+
export { HealthService } from './services/HealthService';
|
|
47
|
+
export { MerchantsService } from './services/MerchantsService';
|
|
48
|
+
export { PackagesService } from './services/PackagesService';
|
|
49
|
+
export { PaymentsService } from './services/PaymentsService';
|
|
50
|
+
export { SubscriptionsService } from './services/SubscriptionsService';
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/* generated using openapi-typescript-codegen -- do not edit */
|
|
2
|
+
/* istanbul ignore file */
|
|
3
|
+
/* tslint:disable */
|
|
4
|
+
/* eslint-disable */
|
|
5
|
+
import type { Subscription } from './Subscription';
|
|
6
|
+
export type ConsumeClassResponse = {
|
|
7
|
+
subscription?: Subscription;
|
|
8
|
+
classesRemaining?: number;
|
|
9
|
+
};
|
|
10
|
+
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/* generated using openapi-typescript-codegen -- do not edit */
|
|
2
|
+
/* istanbul ignore file */
|
|
3
|
+
/* tslint:disable */
|
|
4
|
+
/* eslint-disable */
|
|
5
|
+
export type CreateMerchantRequest = {
|
|
6
|
+
businessId: string;
|
|
7
|
+
name: string;
|
|
8
|
+
email: string;
|
|
9
|
+
paymentProvider?: CreateMerchantRequest.paymentProvider;
|
|
10
|
+
/**
|
|
11
|
+
* API Key de Wompi (se encripta antes de guardar)
|
|
12
|
+
*/
|
|
13
|
+
apiKey: string;
|
|
14
|
+
environment?: CreateMerchantRequest.environment;
|
|
15
|
+
webhookUrl?: string;
|
|
16
|
+
redirectUrl?: string;
|
|
17
|
+
cardGroupId?: string;
|
|
18
|
+
};
|
|
19
|
+
export namespace CreateMerchantRequest {
|
|
20
|
+
export enum paymentProvider {
|
|
21
|
+
WOMPI = 'wompi',
|
|
22
|
+
}
|
|
23
|
+
export enum environment {
|
|
24
|
+
SANDBOX = 'sandbox',
|
|
25
|
+
PRODUCTION = 'production',
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/* generated using openapi-typescript-codegen -- do not edit */
|
|
2
|
+
/* istanbul ignore file */
|
|
3
|
+
/* tslint:disable */
|
|
4
|
+
/* eslint-disable */
|
|
5
|
+
export type CreatePackageRequest = {
|
|
6
|
+
name: string;
|
|
7
|
+
description?: string;
|
|
8
|
+
numberOfClasses: number;
|
|
9
|
+
durationDays: number;
|
|
10
|
+
price: number;
|
|
11
|
+
autoRenewDefault?: boolean;
|
|
12
|
+
};
|
|
13
|
+
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/* generated using openapi-typescript-codegen -- do not edit */
|
|
2
|
+
/* istanbul ignore file */
|
|
3
|
+
/* tslint:disable */
|
|
4
|
+
/* eslint-disable */
|
|
5
|
+
export type CreateSubscriptionRequest = {
|
|
6
|
+
merchantId: string;
|
|
7
|
+
packageId: string;
|
|
8
|
+
autoRenew?: boolean;
|
|
9
|
+
customerEmail: string;
|
|
10
|
+
customerName: string;
|
|
11
|
+
customerLastName: string;
|
|
12
|
+
customerPhone?: string;
|
|
13
|
+
city?: string;
|
|
14
|
+
address?: string;
|
|
15
|
+
/**
|
|
16
|
+
* ID de tarjeta guardada. Requerido si no se envía cardNumber.
|
|
17
|
+
*/
|
|
18
|
+
savedCardId?: string;
|
|
19
|
+
/**
|
|
20
|
+
* CVV requerido siempre (con tarjeta guardada o nueva)
|
|
21
|
+
*/
|
|
22
|
+
cvv?: string;
|
|
23
|
+
/**
|
|
24
|
+
* Número de tarjeta. Requerido si no se envía savedCardId.
|
|
25
|
+
*/
|
|
26
|
+
cardNumber?: string;
|
|
27
|
+
expirationMonth?: number;
|
|
28
|
+
expirationYear?: number;
|
|
29
|
+
};
|
|
30
|
+
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/* generated using openapi-typescript-codegen -- do not edit */
|
|
2
|
+
/* istanbul ignore file */
|
|
3
|
+
/* tslint:disable */
|
|
4
|
+
/* eslint-disable */
|
|
5
|
+
import type { Subscription } from './Subscription';
|
|
6
|
+
export type CreateSubscriptionResponse = {
|
|
7
|
+
subscription?: Subscription;
|
|
8
|
+
/**
|
|
9
|
+
* URL de Wompi para completar autenticación 3DS. Si está presente, redirigir al usuario a esta URL. La suscripción se activará cuando Wompi notifique vía webhook.
|
|
10
|
+
*/
|
|
11
|
+
redirectUrl?: string | null;
|
|
12
|
+
};
|
|
13
|
+
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/* generated using openapi-typescript-codegen -- do not edit */
|
|
2
|
+
/* istanbul ignore file */
|
|
3
|
+
/* tslint:disable */
|
|
4
|
+
/* eslint-disable */
|
|
5
|
+
import type { MerchantProviderConfig } from './MerchantProviderConfig';
|
|
6
|
+
export type Merchant = {
|
|
7
|
+
_id?: string;
|
|
8
|
+
/**
|
|
9
|
+
* ID del negocio en jogo-backend
|
|
10
|
+
*/
|
|
11
|
+
businessId?: string;
|
|
12
|
+
name?: string;
|
|
13
|
+
email?: string;
|
|
14
|
+
paymentProvider?: Merchant.paymentProvider;
|
|
15
|
+
providerConfig?: MerchantProviderConfig;
|
|
16
|
+
active?: boolean;
|
|
17
|
+
createdAt?: string;
|
|
18
|
+
updatedAt?: string;
|
|
19
|
+
};
|
|
20
|
+
export namespace Merchant {
|
|
21
|
+
export enum paymentProvider {
|
|
22
|
+
WOMPI = 'wompi',
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/* generated using openapi-typescript-codegen -- do not edit */
|
|
2
|
+
/* istanbul ignore file */
|
|
3
|
+
/* tslint:disable */
|
|
4
|
+
/* eslint-disable */
|
|
5
|
+
export type MerchantProviderConfig = {
|
|
6
|
+
environment?: MerchantProviderConfig.environment;
|
|
7
|
+
webhookUrl?: string;
|
|
8
|
+
redirectUrl?: string;
|
|
9
|
+
/**
|
|
10
|
+
* ID del grupo de tarjetas en Wompi para validación adicional
|
|
11
|
+
*/
|
|
12
|
+
cardGroupId?: string;
|
|
13
|
+
};
|
|
14
|
+
export namespace MerchantProviderConfig {
|
|
15
|
+
export enum environment {
|
|
16
|
+
SANDBOX = 'sandbox',
|
|
17
|
+
PRODUCTION = 'production',
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|