@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,148 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SubscriptionsService = void 0;
|
|
4
|
+
class SubscriptionsService {
|
|
5
|
+
httpRequest;
|
|
6
|
+
constructor(httpRequest) {
|
|
7
|
+
this.httpRequest = httpRequest;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Crear y pagar una suscripción
|
|
11
|
+
* Crea una suscripción para el cliente autenticado y ejecuta el cobro al proveedor de pago configurado para el negocio.
|
|
12
|
+
* **Flujo con tarjeta guardada (recomendado para renovaciones):** Enviar `savedCardId` + `cvv`. Si el pago completa de inmediato, retorna `201` con la suscripción activa.
|
|
13
|
+
* **Flujo con tarjeta nueva (3DS):** Enviar datos de tarjeta directamente. Wompi puede requerir autenticación 3DS, en cuyo caso retorna `202` con un `redirectUrl`. Redirigir al cliente a esa URL. La suscripción se activará automáticamente cuando Wompi envíe el webhook de confirmación.
|
|
14
|
+
*
|
|
15
|
+
* @returns CreateSubscriptionResponse Suscripción creada y activa (pago completado sin 3DS)
|
|
16
|
+
* @throws ApiError
|
|
17
|
+
*/
|
|
18
|
+
postApiV1Subscriptions({ requestBody, }) {
|
|
19
|
+
return this.httpRequest.request({
|
|
20
|
+
method: 'POST',
|
|
21
|
+
url: '/api/v1/subscriptions',
|
|
22
|
+
body: requestBody,
|
|
23
|
+
mediaType: 'application/json',
|
|
24
|
+
errors: {
|
|
25
|
+
400: `Datos de pago incompletos`,
|
|
26
|
+
401: `Token JWT ausente o inválido`,
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Mis suscripciones
|
|
32
|
+
* Retorna todas las suscripciones del cliente autenticado.
|
|
33
|
+
* @returns Subscription Lista de suscripciones del cliente
|
|
34
|
+
* @throws ApiError
|
|
35
|
+
*/
|
|
36
|
+
getApiV1SubscriptionsMe() {
|
|
37
|
+
return this.httpRequest.request({
|
|
38
|
+
method: 'GET',
|
|
39
|
+
url: '/api/v1/subscriptions/me',
|
|
40
|
+
errors: {
|
|
41
|
+
401: `Token JWT ausente o inválido`,
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Suscripciones de un cliente (admin)
|
|
47
|
+
* Retorna las suscripciones de un cliente específico. Uso interno/admin — el negocio puede consultar el estado de sus clientes.
|
|
48
|
+
*
|
|
49
|
+
* @returns Subscription Lista de suscripciones
|
|
50
|
+
* @throws ApiError
|
|
51
|
+
*/
|
|
52
|
+
getApiV1SubscriptionsCustomer({ customerId, }) {
|
|
53
|
+
return this.httpRequest.request({
|
|
54
|
+
method: 'GET',
|
|
55
|
+
url: '/api/v1/subscriptions/customer/{customerId}',
|
|
56
|
+
path: {
|
|
57
|
+
'customerId': customerId,
|
|
58
|
+
},
|
|
59
|
+
errors: {
|
|
60
|
+
401: `Token JWT ausente o inválido`,
|
|
61
|
+
},
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Detalle de una suscripción
|
|
66
|
+
* @returns Subscription Detalle de la suscripción con info del paquete populada
|
|
67
|
+
* @throws ApiError
|
|
68
|
+
*/
|
|
69
|
+
getApiV1Subscriptions({ id, }) {
|
|
70
|
+
return this.httpRequest.request({
|
|
71
|
+
method: 'GET',
|
|
72
|
+
url: '/api/v1/subscriptions/{id}',
|
|
73
|
+
path: {
|
|
74
|
+
'id': id,
|
|
75
|
+
},
|
|
76
|
+
errors: {
|
|
77
|
+
401: `Token JWT ausente o inválido`,
|
|
78
|
+
404: `Suscripción no encontrada`,
|
|
79
|
+
},
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Registrar uso de una clase
|
|
84
|
+
* Descuenta una clase del saldo disponible en la suscripción. Solo aplica a suscripciones en estado `active` con clases restantes.
|
|
85
|
+
*
|
|
86
|
+
* @returns ConsumeClassResponse Clase registrada exitosamente
|
|
87
|
+
* @throws ApiError
|
|
88
|
+
*/
|
|
89
|
+
postApiV1SubscriptionsConsume({ id, }) {
|
|
90
|
+
return this.httpRequest.request({
|
|
91
|
+
method: 'POST',
|
|
92
|
+
url: '/api/v1/subscriptions/{id}/consume',
|
|
93
|
+
path: {
|
|
94
|
+
'id': id,
|
|
95
|
+
},
|
|
96
|
+
errors: {
|
|
97
|
+
400: `Sin clases disponibles o suscripción inactiva/vencida`,
|
|
98
|
+
401: `Token JWT ausente o inválido`,
|
|
99
|
+
403: `La suscripción no pertenece al cliente`,
|
|
100
|
+
},
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Cancelar suscripción
|
|
105
|
+
* Cancela la suscripción y desactiva la renovación automática. El cliente mantiene acceso hasta la fecha de vencimiento.
|
|
106
|
+
*
|
|
107
|
+
* @returns Subscription Suscripción cancelada
|
|
108
|
+
* @throws ApiError
|
|
109
|
+
*/
|
|
110
|
+
postApiV1SubscriptionsCancel({ id, }) {
|
|
111
|
+
return this.httpRequest.request({
|
|
112
|
+
method: 'POST',
|
|
113
|
+
url: '/api/v1/subscriptions/{id}/cancel',
|
|
114
|
+
path: {
|
|
115
|
+
'id': id,
|
|
116
|
+
},
|
|
117
|
+
errors: {
|
|
118
|
+
401: `Token JWT ausente o inválido`,
|
|
119
|
+
403: `Forbidden`,
|
|
120
|
+
409: `La suscripción ya está cancelada`,
|
|
121
|
+
},
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Renovar suscripción manualmente
|
|
126
|
+
* Renueva una suscripción usando la tarjeta guardada previamente. Requiere CVV por cumplimiento PCI. Si el pago requiere 3DS, retorna `redirectUrl` para completar la autenticación.
|
|
127
|
+
*
|
|
128
|
+
* @returns CreateSubscriptionResponse Suscripción renovada
|
|
129
|
+
* @throws ApiError
|
|
130
|
+
*/
|
|
131
|
+
postApiV1SubscriptionsRenew({ id, requestBody, }) {
|
|
132
|
+
return this.httpRequest.request({
|
|
133
|
+
method: 'POST',
|
|
134
|
+
url: '/api/v1/subscriptions/{id}/renew',
|
|
135
|
+
path: {
|
|
136
|
+
'id': id,
|
|
137
|
+
},
|
|
138
|
+
body: requestBody,
|
|
139
|
+
mediaType: 'application/json',
|
|
140
|
+
errors: {
|
|
141
|
+
400: `CVV requerido o no hay tarjeta guardada`,
|
|
142
|
+
401: `Token JWT ausente o inválido`,
|
|
143
|
+
403: `Forbidden`,
|
|
144
|
+
},
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
exports.SubscriptionsService = SubscriptionsService;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './__generated__';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./__generated__"), exports);
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { AxiosInstance } from 'axios';
|
|
2
|
+
import { OpenAPIConfig, BaseHttpRequest, Billing, CancelablePromise } from './billing/src';
|
|
3
|
+
import { ApiRequestOptions } from './billing/src/__generated__/core/ApiRequestOptions';
|
|
4
|
+
export * from './billing/src';
|
|
5
|
+
export declare const billingInstance: (baseUrl: string) => AxiosInstance;
|
|
6
|
+
export declare class BillingHttpClient extends BaseHttpRequest {
|
|
7
|
+
axiosInstance: AxiosInstance;
|
|
8
|
+
constructor(config: OpenAPIConfig);
|
|
9
|
+
request<T>(options: ApiRequestOptions): CancelablePromise<T>;
|
|
10
|
+
}
|
|
11
|
+
export declare const createBillingApiClient: (baseUrl: string, tokenProp?: string) => Billing;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
17
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
|
+
};
|
|
19
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
exports.createBillingApiClient = exports.BillingHttpClient = exports.billingInstance = void 0;
|
|
21
|
+
const src_1 = require("./billing/src");
|
|
22
|
+
const axios_1 = __importDefault(require("axios"));
|
|
23
|
+
const request_1 = require("./billing/src/__generated__/core/request");
|
|
24
|
+
// export all sdk
|
|
25
|
+
__exportStar(require("./billing/src"), exports);
|
|
26
|
+
let token = '';
|
|
27
|
+
const billingInstance = (baseUrl) => {
|
|
28
|
+
return axios_1.default.create({
|
|
29
|
+
baseURL: baseUrl,
|
|
30
|
+
headers: {
|
|
31
|
+
'Content-Type': 'application/json',
|
|
32
|
+
Authorization: token ? `Bearer ${token}` : undefined,
|
|
33
|
+
},
|
|
34
|
+
});
|
|
35
|
+
};
|
|
36
|
+
exports.billingInstance = billingInstance;
|
|
37
|
+
class BillingHttpClient extends src_1.BaseHttpRequest {
|
|
38
|
+
axiosInstance;
|
|
39
|
+
constructor(config) {
|
|
40
|
+
super(config);
|
|
41
|
+
this.axiosInstance = (0, exports.billingInstance)(config.BASE);
|
|
42
|
+
}
|
|
43
|
+
request(options) {
|
|
44
|
+
return (0, request_1.request)(this.config, options, this.axiosInstance);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
exports.BillingHttpClient = BillingHttpClient;
|
|
48
|
+
const createBillingApiClient = (baseUrl, tokenProp) => {
|
|
49
|
+
token = tokenProp;
|
|
50
|
+
return new src_1.Billing({
|
|
51
|
+
BASE: baseUrl,
|
|
52
|
+
}, BillingHttpClient);
|
|
53
|
+
};
|
|
54
|
+
exports.createBillingApiClient = createBillingApiClient;
|
package/package.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@jogolabs/billing-sdk-v2",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Billing SDK v2 to Jogo Labs",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"react-native": "dist/index.js",
|
|
8
|
+
"source": "src/index.ts",
|
|
9
|
+
"prepublish": "tsc --composite false",
|
|
10
|
+
"public": true,
|
|
11
|
+
"scripts": {
|
|
12
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
13
|
+
"build": "node scripts/generate-api-sdk.js generate-sdk --url http://localhost:3003 --name 'Billing' -o 'src/billing' && tsc --composite false",
|
|
14
|
+
"deploy": "npm run build && npm publish --access public",
|
|
15
|
+
"publish:package": "node ./scripts/publish.js"
|
|
16
|
+
},
|
|
17
|
+
"author": "rivaslive",
|
|
18
|
+
"license": "ISC",
|
|
19
|
+
"packageManager": "yarn@1.22.22+sha1.ac34549e6aa8e7ead463a7407e1c7390f61a6610",
|
|
20
|
+
"devDependencies": {
|
|
21
|
+
"@typescript-eslint/eslint-plugin": "^8.5.0",
|
|
22
|
+
"@typescript-eslint/parser": "^8.5.0",
|
|
23
|
+
"axios": "^1.7.7",
|
|
24
|
+
"eslint": "^8.57.1",
|
|
25
|
+
"json-schema-ref-parser": "^9.0.9",
|
|
26
|
+
"openapi-typescript-codegen": "^0.29.0",
|
|
27
|
+
"typescript": "^5.6.2",
|
|
28
|
+
"yargs": "^17.7.2"
|
|
29
|
+
},
|
|
30
|
+
"peerDependencies": {
|
|
31
|
+
"axios": "^1.x.x"
|
|
32
|
+
},
|
|
33
|
+
"dependencies": {
|
|
34
|
+
"inquirer": "^13.3.0"
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
const generator = require('openapi-typescript-codegen');
|
|
2
|
+
const $RefParser = require('json-schema-ref-parser');
|
|
3
|
+
const yargs = require('yargs/yargs');
|
|
4
|
+
const { hideBin } = require('yargs/helpers');
|
|
5
|
+
const fs = require('fs');
|
|
6
|
+
|
|
7
|
+
const parseJson = (text) => {
|
|
8
|
+
// Controllers names
|
|
9
|
+
text = text.replace(/[a-zA-Z0-9]+Controller/g, '')
|
|
10
|
+
|
|
11
|
+
return JSON.parse(text)
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const generateClientSdk = async (apiBaseUrl, clientName, outputPath = './') => {
|
|
15
|
+
try {
|
|
16
|
+
console.log(`Fetching Swagger from ${apiBaseUrl}/docs/spec.json...`);
|
|
17
|
+
const jsonSwagger = await fetch(`${apiBaseUrl}/docs/spec.json`)
|
|
18
|
+
.then((r) => r.text())
|
|
19
|
+
.then(parseJson)
|
|
20
|
+
.catch((err) => console.error(err));
|
|
21
|
+
|
|
22
|
+
if (!jsonSwagger) throw new Error('Swagger not found');
|
|
23
|
+
console.log('Swagger Acquired. Generating SDK...');
|
|
24
|
+
|
|
25
|
+
const input = JSON.stringify(jsonSwagger);
|
|
26
|
+
const json = parseJson(input);
|
|
27
|
+
|
|
28
|
+
const parsed = await $RefParser.parse(json);
|
|
29
|
+
await generator.generate({
|
|
30
|
+
input: parsed,
|
|
31
|
+
output: outputPath + '/src/__generated__',
|
|
32
|
+
clientName: clientName,
|
|
33
|
+
useUnionTypes: false,
|
|
34
|
+
httpClient: 'axios',
|
|
35
|
+
useOptions: true,
|
|
36
|
+
exportSchemas: true,
|
|
37
|
+
});
|
|
38
|
+
console.log('SDK Generated. Updating package.json...');
|
|
39
|
+
|
|
40
|
+
fs.writeFileSync(`${outputPath}/src/index.ts`, "export * from './__generated__';\n");
|
|
41
|
+
} catch (error) {
|
|
42
|
+
console.error(error);
|
|
43
|
+
process.exit(1);
|
|
44
|
+
}
|
|
45
|
+
console.log('Done');
|
|
46
|
+
process.exit(0);
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
50
|
+
const argv = yargs(hideBin(process.argv))
|
|
51
|
+
.command(
|
|
52
|
+
'generate-sdk',
|
|
53
|
+
'Generate the SDK',
|
|
54
|
+
(yargs) => {
|
|
55
|
+
yargs
|
|
56
|
+
.option('url', {
|
|
57
|
+
alias: 'u',
|
|
58
|
+
description: 'Url to the App api swagger-json',
|
|
59
|
+
type: 'string',
|
|
60
|
+
demandOption: true,
|
|
61
|
+
})
|
|
62
|
+
.option('name', {
|
|
63
|
+
alias: 'n',
|
|
64
|
+
description: 'Client name',
|
|
65
|
+
type: 'string',
|
|
66
|
+
demandOption: true,
|
|
67
|
+
})
|
|
68
|
+
.option('output', {
|
|
69
|
+
alias: 'o',
|
|
70
|
+
description: 'Output directory for generated SDK',
|
|
71
|
+
type: 'string',
|
|
72
|
+
default: 'generated/rest-client',
|
|
73
|
+
});
|
|
74
|
+
},
|
|
75
|
+
(argv) => {
|
|
76
|
+
generateClientSdk(argv.url, argv.name, argv.output);
|
|
77
|
+
},
|
|
78
|
+
)
|
|
79
|
+
.demandCommand(1, 'You need at least one command before moving on')
|
|
80
|
+
.help()
|
|
81
|
+
.alias('h', 'help').argv;
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* example:
|
|
85
|
+
* node tools/scripts/generateSdkApiClient.js generate-sdk --url $API_URL --name 'AppName' -o './libs/public/<app-name-sdk>/src'"
|
|
86
|
+
*/
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
const fs = require('fs');
|
|
3
|
+
const inquirer = require('inquirer');
|
|
4
|
+
const { hideBin } = require('yargs/helpers');
|
|
5
|
+
const path = require('path');
|
|
6
|
+
const yargs = require('yargs/yargs')(hideBin(process.argv));
|
|
7
|
+
|
|
8
|
+
(async () => {
|
|
9
|
+
// Settings yargs for the command line
|
|
10
|
+
const argv = yargs.option('auto', {
|
|
11
|
+
alias: 'a',
|
|
12
|
+
type: 'boolean',
|
|
13
|
+
description: 'Use the arg in the line command (major, minor, patch)',
|
|
14
|
+
}).argv;
|
|
15
|
+
|
|
16
|
+
const pkgPath = path.resolve(__dirname, '..', './package.json');
|
|
17
|
+
|
|
18
|
+
const packageJson = JSON.parse(fs.readFileSync(pkgPath));
|
|
19
|
+
|
|
20
|
+
const version = packageJson.version;
|
|
21
|
+
|
|
22
|
+
let versionType = argv._[0];
|
|
23
|
+
|
|
24
|
+
if (!versionType || !['major', 'minor', 'patch'].includes(versionType)) {
|
|
25
|
+
const answers = await inquirer.prompt([
|
|
26
|
+
{
|
|
27
|
+
type: 'list',
|
|
28
|
+
name: 'versionType',
|
|
29
|
+
message: 'What type of version do you want to update?',
|
|
30
|
+
choices: ['major', 'minor', 'patch'],
|
|
31
|
+
},
|
|
32
|
+
]);
|
|
33
|
+
versionType = answers.versionType;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const versionArray = version.split('.');
|
|
37
|
+
|
|
38
|
+
switch (versionType) {
|
|
39
|
+
case 'major':
|
|
40
|
+
versionArray[0] = parseInt(versionArray[0]) + 1;
|
|
41
|
+
break;
|
|
42
|
+
case 'minor':
|
|
43
|
+
versionArray[1] = parseInt(versionArray[1]) + 1;
|
|
44
|
+
break;
|
|
45
|
+
case 'patch':
|
|
46
|
+
versionArray[2] = parseInt(versionArray[2]) + 1;
|
|
47
|
+
break;
|
|
48
|
+
default:
|
|
49
|
+
console.error('Invalid version type');
|
|
50
|
+
process.exit(1);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
packageJson.version = versionArray.join('.');
|
|
54
|
+
|
|
55
|
+
fs.writeFileSync(pkgPath, JSON.stringify(packageJson, null, 2));
|
|
56
|
+
|
|
57
|
+
console.log(`Version update to ${packageJson.version}`);
|
|
58
|
+
|
|
59
|
+
try {
|
|
60
|
+
require('child_process').execSync('npm run deploy', {
|
|
61
|
+
cwd: __dirname,
|
|
62
|
+
});
|
|
63
|
+
console.log(`Publish version ${packageJson.version}`);
|
|
64
|
+
} catch (error) {
|
|
65
|
+
console.log('Error on publish >>', error);
|
|
66
|
+
|
|
67
|
+
console.log(`Reverting version to previous version ${version}`);
|
|
68
|
+
packageJson.version = version;
|
|
69
|
+
|
|
70
|
+
fs.writeFileSync(pkgPath, JSON.stringify(packageJson, null, 2));
|
|
71
|
+
}
|
|
72
|
+
})();
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/* generated using openapi-typescript-codegen -- do not edit */
|
|
2
|
+
/* istanbul ignore file */
|
|
3
|
+
/* tslint:disable */
|
|
4
|
+
/* eslint-disable */
|
|
5
|
+
import type { BaseHttpRequest } from './core/BaseHttpRequest';
|
|
6
|
+
import type { OpenAPIConfig } from './core/OpenAPI';
|
|
7
|
+
import { AxiosHttpRequest } from './core/AxiosHttpRequest';
|
|
8
|
+
import { CardsService } from './services/CardsService';
|
|
9
|
+
import { HealthService } from './services/HealthService';
|
|
10
|
+
import { MerchantsService } from './services/MerchantsService';
|
|
11
|
+
import { PackagesService } from './services/PackagesService';
|
|
12
|
+
import { PaymentsService } from './services/PaymentsService';
|
|
13
|
+
import { SubscriptionsService } from './services/SubscriptionsService';
|
|
14
|
+
type HttpRequestConstructor = new (config: OpenAPIConfig) => BaseHttpRequest;
|
|
15
|
+
export class Billing {
|
|
16
|
+
public readonly cards: CardsService;
|
|
17
|
+
public readonly health: HealthService;
|
|
18
|
+
public readonly merchants: MerchantsService;
|
|
19
|
+
public readonly packages: PackagesService;
|
|
20
|
+
public readonly payments: PaymentsService;
|
|
21
|
+
public readonly subscriptions: SubscriptionsService;
|
|
22
|
+
public readonly request: BaseHttpRequest;
|
|
23
|
+
constructor(config?: Partial<OpenAPIConfig>, HttpRequest: HttpRequestConstructor = AxiosHttpRequest) {
|
|
24
|
+
this.request = new HttpRequest({
|
|
25
|
+
BASE: config?.BASE ?? 'http://localhost:3003',
|
|
26
|
+
VERSION: config?.VERSION ?? '1.0.0',
|
|
27
|
+
WITH_CREDENTIALS: config?.WITH_CREDENTIALS ?? false,
|
|
28
|
+
CREDENTIALS: config?.CREDENTIALS ?? 'include',
|
|
29
|
+
TOKEN: config?.TOKEN,
|
|
30
|
+
USERNAME: config?.USERNAME,
|
|
31
|
+
PASSWORD: config?.PASSWORD,
|
|
32
|
+
HEADERS: config?.HEADERS,
|
|
33
|
+
ENCODE_PATH: config?.ENCODE_PATH,
|
|
34
|
+
});
|
|
35
|
+
this.cards = new CardsService(this.request);
|
|
36
|
+
this.health = new HealthService(this.request);
|
|
37
|
+
this.merchants = new MerchantsService(this.request);
|
|
38
|
+
this.packages = new PackagesService(this.request);
|
|
39
|
+
this.payments = new PaymentsService(this.request);
|
|
40
|
+
this.subscriptions = new SubscriptionsService(this.request);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
@@ -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 { ApiRequestOptions } from './ApiRequestOptions';
|
|
6
|
+
import type { ApiResult } from './ApiResult';
|
|
7
|
+
|
|
8
|
+
export class ApiError extends Error {
|
|
9
|
+
public readonly url: string;
|
|
10
|
+
public readonly status: number;
|
|
11
|
+
public readonly statusText: string;
|
|
12
|
+
public readonly body: any;
|
|
13
|
+
public readonly request: ApiRequestOptions;
|
|
14
|
+
|
|
15
|
+
constructor(request: ApiRequestOptions, response: ApiResult, message: string) {
|
|
16
|
+
super(message);
|
|
17
|
+
|
|
18
|
+
this.name = 'ApiError';
|
|
19
|
+
this.url = response.url;
|
|
20
|
+
this.status = response.status;
|
|
21
|
+
this.statusText = response.statusText;
|
|
22
|
+
this.body = response.body;
|
|
23
|
+
this.request = request;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/* generated using openapi-typescript-codegen -- do not edit */
|
|
2
|
+
/* istanbul ignore file */
|
|
3
|
+
/* tslint:disable */
|
|
4
|
+
/* eslint-disable */
|
|
5
|
+
export type ApiRequestOptions = {
|
|
6
|
+
readonly method: 'GET' | 'PUT' | 'POST' | 'DELETE' | 'OPTIONS' | 'HEAD' | 'PATCH';
|
|
7
|
+
readonly url: string;
|
|
8
|
+
readonly path?: Record<string, any>;
|
|
9
|
+
readonly cookies?: Record<string, any>;
|
|
10
|
+
readonly headers?: Record<string, any>;
|
|
11
|
+
readonly query?: Record<string, any>;
|
|
12
|
+
readonly formData?: Record<string, any>;
|
|
13
|
+
readonly body?: any;
|
|
14
|
+
readonly mediaType?: string;
|
|
15
|
+
readonly responseHeader?: string;
|
|
16
|
+
readonly errors?: Record<number, string>;
|
|
17
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/* generated using openapi-typescript-codegen -- do not edit */
|
|
2
|
+
/* istanbul ignore file */
|
|
3
|
+
/* tslint:disable */
|
|
4
|
+
/* eslint-disable */
|
|
5
|
+
export type ApiResult = {
|
|
6
|
+
readonly url: string;
|
|
7
|
+
readonly ok: boolean;
|
|
8
|
+
readonly status: number;
|
|
9
|
+
readonly statusText: string;
|
|
10
|
+
readonly body: any;
|
|
11
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
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
|
+
import { BaseHttpRequest } from './BaseHttpRequest';
|
|
7
|
+
import type { CancelablePromise } from './CancelablePromise';
|
|
8
|
+
import type { OpenAPIConfig } from './OpenAPI';
|
|
9
|
+
import { request as __request } from './request';
|
|
10
|
+
|
|
11
|
+
export class AxiosHttpRequest extends BaseHttpRequest {
|
|
12
|
+
|
|
13
|
+
constructor(config: OpenAPIConfig) {
|
|
14
|
+
super(config);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Request method
|
|
19
|
+
* @param options The request options from the service
|
|
20
|
+
* @returns CancelablePromise<T>
|
|
21
|
+
* @throws ApiError
|
|
22
|
+
*/
|
|
23
|
+
public override request<T>(options: ApiRequestOptions): CancelablePromise<T> {
|
|
24
|
+
return __request(this.config, options);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
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
|
+
import type { CancelablePromise } from './CancelablePromise';
|
|
7
|
+
import type { OpenAPIConfig } from './OpenAPI';
|
|
8
|
+
|
|
9
|
+
export abstract class BaseHttpRequest {
|
|
10
|
+
|
|
11
|
+
constructor(public readonly config: OpenAPIConfig) {}
|
|
12
|
+
|
|
13
|
+
public abstract request<T>(options: ApiRequestOptions): CancelablePromise<T>;
|
|
14
|
+
}
|