@pabilo/sdk 0.1.0
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/dist/index.cjs +264 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +142 -0
- package/dist/index.d.ts +142 -0
- package/dist/index.js +259 -0
- package/dist/index.js.map +1 -0
- package/package.json +39 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/domain/errors.ts
|
|
4
|
+
var PabiloError = class extends Error {
|
|
5
|
+
constructor(opts) {
|
|
6
|
+
super(opts.message);
|
|
7
|
+
this.name = "PabiloError";
|
|
8
|
+
this.code = opts.code;
|
|
9
|
+
this.statusCode = opts.statusCode;
|
|
10
|
+
this.raw = opts.raw;
|
|
11
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
function parsePabiloError(body, statusCode) {
|
|
15
|
+
if (statusCode === 401) {
|
|
16
|
+
return new PabiloError({ message: "Unauthorized", code: "UNAUTHORIZED", statusCode, raw: body });
|
|
17
|
+
}
|
|
18
|
+
if (statusCode === 404) {
|
|
19
|
+
return new PabiloError({ message: "Not found", code: "NOT_FOUND", statusCode, raw: body });
|
|
20
|
+
}
|
|
21
|
+
if (body !== null && typeof body === "object") {
|
|
22
|
+
const b = body;
|
|
23
|
+
const code2 = typeof b["error"] === "string" ? b["error"] : resolveCodeFromStatus(statusCode);
|
|
24
|
+
const message = typeof b["message"] === "string" ? b["message"] : code2;
|
|
25
|
+
return new PabiloError({ message, code: code2, statusCode, raw: body });
|
|
26
|
+
}
|
|
27
|
+
const code = resolveCodeFromStatus(statusCode);
|
|
28
|
+
return new PabiloError({ message: code, code, statusCode, raw: body });
|
|
29
|
+
}
|
|
30
|
+
function resolveCodeFromStatus(statusCode) {
|
|
31
|
+
if (statusCode >= 500) return "INTERNAL_SERVER_ERROR";
|
|
32
|
+
if (statusCode === 400) return "BAD_REQUEST";
|
|
33
|
+
return "REQUEST_FAILED";
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// src/infrastructure/fetch-http-client.ts
|
|
37
|
+
var FetchHttpClient = class {
|
|
38
|
+
constructor(fetchImpl) {
|
|
39
|
+
this.fetchFn = fetchImpl ?? globalThis.fetch.bind(globalThis);
|
|
40
|
+
}
|
|
41
|
+
async request(options) {
|
|
42
|
+
const { method, path, body, headers = {} } = options;
|
|
43
|
+
const init = { method, headers: { ...headers } };
|
|
44
|
+
if (body !== void 0) {
|
|
45
|
+
init.headers["content-type"] = "application/json";
|
|
46
|
+
init.body = JSON.stringify(body);
|
|
47
|
+
}
|
|
48
|
+
let response;
|
|
49
|
+
try {
|
|
50
|
+
response = await this.fetchFn(path, init);
|
|
51
|
+
} catch (cause) {
|
|
52
|
+
throw new PabiloError({
|
|
53
|
+
message: cause instanceof Error ? cause.message : "Network request failed",
|
|
54
|
+
code: "NETWORK_ERROR",
|
|
55
|
+
raw: cause
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
let responseBody;
|
|
59
|
+
try {
|
|
60
|
+
responseBody = await response.json();
|
|
61
|
+
} catch {
|
|
62
|
+
responseBody = null;
|
|
63
|
+
}
|
|
64
|
+
if (!response.ok) {
|
|
65
|
+
throw parsePabiloError(responseBody, response.status);
|
|
66
|
+
}
|
|
67
|
+
return responseBody;
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
// src/infrastructure/pabilo-http-client.ts
|
|
72
|
+
var DEFAULT_BASE_URL = "https://api.pabilo.app";
|
|
73
|
+
var PabiloHttpClient = class {
|
|
74
|
+
constructor(options) {
|
|
75
|
+
this.apiKey = options.apiKey;
|
|
76
|
+
this.baseUrl = (options.baseUrl ?? DEFAULT_BASE_URL).replace(/\/$/, "");
|
|
77
|
+
this.inner = options.httpClient ?? new FetchHttpClient();
|
|
78
|
+
}
|
|
79
|
+
request(options) {
|
|
80
|
+
const url = `${this.baseUrl}${options.path}`;
|
|
81
|
+
return this.inner.request({
|
|
82
|
+
...options,
|
|
83
|
+
path: url,
|
|
84
|
+
headers: {
|
|
85
|
+
...options.headers,
|
|
86
|
+
appKey: this.apiKey
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
// src/resources/bank-accounts.resource.ts
|
|
93
|
+
var BankAccountsResource = class {
|
|
94
|
+
constructor(http) {
|
|
95
|
+
this.http = http;
|
|
96
|
+
}
|
|
97
|
+
async list() {
|
|
98
|
+
const res = await this.http.request({
|
|
99
|
+
method: "GET",
|
|
100
|
+
path: "/me/usersbank"
|
|
101
|
+
});
|
|
102
|
+
const raw = Array.isArray(res["user_banks"]) ? res["user_banks"] : Array.isArray(res["data"]) ? res["data"] : [];
|
|
103
|
+
return raw.map(normalizeUserBank);
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
function normalizeUserBank(raw) {
|
|
107
|
+
const b = raw;
|
|
108
|
+
const bankAccounts = Array.isArray(b["bank_accounts"]) ? b["bank_accounts"].map(normalizeBankAccount) : [];
|
|
109
|
+
return {
|
|
110
|
+
id: String(b["id"] ?? ""),
|
|
111
|
+
description: String(b["description"] ?? ""),
|
|
112
|
+
provider: String(b["provider"] ?? ""),
|
|
113
|
+
bank_accounts: bankAccounts,
|
|
114
|
+
payment_link: typeof b["payment_link"] === "boolean" ? b["payment_link"] : void 0,
|
|
115
|
+
to_trash: typeof b["to_trash"] === "boolean" ? b["to_trash"] : void 0
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
function normalizeBankAccount(raw) {
|
|
119
|
+
const a = raw;
|
|
120
|
+
return {
|
|
121
|
+
account_number: String(a["account_number"] ?? ""),
|
|
122
|
+
account_type: String(a["account_type"] ?? a["type"] ?? "")
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// src/resources/payment-links.resource.ts
|
|
127
|
+
var PaymentLinksResource = class {
|
|
128
|
+
constructor(http) {
|
|
129
|
+
this.http = http;
|
|
130
|
+
}
|
|
131
|
+
async create(req) {
|
|
132
|
+
const body = {
|
|
133
|
+
amount: req.amount,
|
|
134
|
+
description: req.description,
|
|
135
|
+
userBankId: req.userBankId,
|
|
136
|
+
currency: req.currency ?? "VES"
|
|
137
|
+
};
|
|
138
|
+
if (req.redirectUrl !== void 0) body["redirect_url"] = req.redirectUrl;
|
|
139
|
+
if (req.webhookUrl !== void 0) body["webhook_url"] = req.webhookUrl;
|
|
140
|
+
if (req.name !== void 0) body["name"] = req.name;
|
|
141
|
+
if (req.isUsd !== void 0) body["is_usd"] = req.isUsd;
|
|
142
|
+
if (req.metadata !== void 0) body["metadata"] = req.metadata;
|
|
143
|
+
const res = await this.http.request({
|
|
144
|
+
method: "POST",
|
|
145
|
+
path: "/v1/paymentlink",
|
|
146
|
+
body
|
|
147
|
+
});
|
|
148
|
+
return normalizePaymentLink(res);
|
|
149
|
+
}
|
|
150
|
+
async update(id, req) {
|
|
151
|
+
const body = {};
|
|
152
|
+
if (req.amount !== void 0) body["amount"] = req.amount;
|
|
153
|
+
if (req.description !== void 0) body["description"] = req.description;
|
|
154
|
+
if (req.redirectUrl !== void 0) body["redirect_url"] = req.redirectUrl;
|
|
155
|
+
if (req.currency !== void 0) body["currency"] = req.currency;
|
|
156
|
+
const res = await this.http.request({
|
|
157
|
+
method: "PATCH",
|
|
158
|
+
path: `/paymentlink/${id}/patch`,
|
|
159
|
+
body
|
|
160
|
+
});
|
|
161
|
+
return normalizePaymentLink(res);
|
|
162
|
+
}
|
|
163
|
+
async getInfo(id) {
|
|
164
|
+
const res = await this.http.request({
|
|
165
|
+
method: "GET",
|
|
166
|
+
path: `/paymentlink/${id}/info`
|
|
167
|
+
});
|
|
168
|
+
const inner = res["data"]?.["payment_link"] ?? res["data"] ?? res;
|
|
169
|
+
return normalizePaymentLink(inner);
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
function normalizePaymentLink(raw) {
|
|
173
|
+
const src = raw["paymentlink"] ?? raw["data"] ?? raw;
|
|
174
|
+
return {
|
|
175
|
+
id: String(src["id"] ?? ""),
|
|
176
|
+
url: String(src["url"] ?? ""),
|
|
177
|
+
amount: typeof src["amount"] === "number" ? src["amount"] : void 0,
|
|
178
|
+
status: typeof src["status"] === "string" ? src["status"] : void 0,
|
|
179
|
+
userId: typeof src["user_id"] === "string" ? src["user_id"] : typeof src["userId"] === "string" ? src["userId"] : void 0
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
// src/resources/payments.resource.ts
|
|
184
|
+
var PaymentsResource = class {
|
|
185
|
+
constructor(http) {
|
|
186
|
+
this.http = http;
|
|
187
|
+
}
|
|
188
|
+
async verify(userBankId, req) {
|
|
189
|
+
const res = await this.http.request({
|
|
190
|
+
method: "POST",
|
|
191
|
+
path: `/userbankpayment/${userBankId}/betaserio`,
|
|
192
|
+
body: {
|
|
193
|
+
amount: req.amount,
|
|
194
|
+
bank_reference: req.bankReference,
|
|
195
|
+
movement_type: req.movementType ?? "GENERIC"
|
|
196
|
+
}
|
|
197
|
+
});
|
|
198
|
+
if (res["error"] === "BANK_NOT_AVAILABLE") {
|
|
199
|
+
return { found: false, reason: "BANK_NOT_AVAILABLE" };
|
|
200
|
+
}
|
|
201
|
+
if (res["error"] === "PAYMENT_NOT_FOUND") {
|
|
202
|
+
return { found: false, reason: "PAYMENT_NOT_FOUND" };
|
|
203
|
+
}
|
|
204
|
+
const data = res["data"];
|
|
205
|
+
if (data !== void 0) {
|
|
206
|
+
return {
|
|
207
|
+
found: true,
|
|
208
|
+
isNew: data["is_new"] === true,
|
|
209
|
+
data
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
return { found: false, reason: "PAYMENT_NOT_FOUND" };
|
|
213
|
+
}
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
// src/resources/me.resource.ts
|
|
217
|
+
var MeResource = class {
|
|
218
|
+
constructor(http) {
|
|
219
|
+
this.http = http;
|
|
220
|
+
}
|
|
221
|
+
async getMe() {
|
|
222
|
+
const res = await this.http.request({
|
|
223
|
+
method: "GET",
|
|
224
|
+
path: "/me"
|
|
225
|
+
});
|
|
226
|
+
const u = res["user"] ?? res;
|
|
227
|
+
return {
|
|
228
|
+
id: String(u["id"] ?? ""),
|
|
229
|
+
email: typeof u["email"] === "string" ? u["email"] : void 0,
|
|
230
|
+
name: typeof u["name"] === "string" ? u["name"] : void 0
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
async getPlan() {
|
|
234
|
+
const res = await this.http.request({
|
|
235
|
+
method: "GET",
|
|
236
|
+
path: "/me/plan"
|
|
237
|
+
});
|
|
238
|
+
return {
|
|
239
|
+
name: String(res["name"] ?? ""),
|
|
240
|
+
planType: typeof res["planType"] === "string" ? res["planType"] : void 0
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
};
|
|
244
|
+
|
|
245
|
+
// src/client.ts
|
|
246
|
+
var PabiloClient = class {
|
|
247
|
+
constructor(options) {
|
|
248
|
+
const http = options.httpClient ?? new PabiloHttpClient({
|
|
249
|
+
apiKey: options.apiKey,
|
|
250
|
+
...options.baseUrl !== void 0 ? { baseUrl: options.baseUrl } : {}
|
|
251
|
+
});
|
|
252
|
+
this.me = new MeResource(http);
|
|
253
|
+
this.bankAccounts = new BankAccountsResource(http);
|
|
254
|
+
this.paymentLinks = new PaymentLinksResource(http);
|
|
255
|
+
this.payments = new PaymentsResource(http);
|
|
256
|
+
}
|
|
257
|
+
};
|
|
258
|
+
|
|
259
|
+
exports.FetchHttpClient = FetchHttpClient;
|
|
260
|
+
exports.PabiloClient = PabiloClient;
|
|
261
|
+
exports.PabiloError = PabiloError;
|
|
262
|
+
exports.PabiloHttpClient = PabiloHttpClient;
|
|
263
|
+
//# sourceMappingURL=index.cjs.map
|
|
264
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/domain/errors.ts","../src/infrastructure/fetch-http-client.ts","../src/infrastructure/pabilo-http-client.ts","../src/resources/bank-accounts.resource.ts","../src/resources/payment-links.resource.ts","../src/resources/payments.resource.ts","../src/resources/me.resource.ts","../src/client.ts"],"names":["code"],"mappings":";;;AAAO,IAAM,WAAA,GAAN,cAA0B,KAAA,CAAM;AAAA,EAKrC,YAAY,IAAA,EAKT;AACD,IAAA,KAAA,CAAM,KAAK,OAAO,CAAA;AAClB,IAAA,IAAA,CAAK,IAAA,GAAO,aAAA;AACZ,IAAA,IAAA,CAAK,OAAO,IAAA,CAAK,IAAA;AACjB,IAAA,IAAA,CAAK,aAAa,IAAA,CAAK,UAAA;AACvB,IAAA,IAAA,CAAK,MAAM,IAAA,CAAK,GAAA;AAChB,IAAA,MAAA,CAAO,cAAA,CAAe,IAAA,EAAM,GAAA,CAAA,MAAA,CAAW,SAAS,CAAA;AAAA,EAClD;AACF;AAEO,SAAS,gBAAA,CAAiB,MAAe,UAAA,EAAiC;AAC/E,EAAA,IAAI,eAAe,GAAA,EAAK;AACtB,IAAA,OAAO,IAAI,WAAA,CAAY,EAAE,OAAA,EAAS,cAAA,EAAgB,MAAM,cAAA,EAAgB,UAAA,EAAY,GAAA,EAAK,IAAA,EAAM,CAAA;AAAA,EACjG;AACA,EAAA,IAAI,eAAe,GAAA,EAAK;AACtB,IAAA,OAAO,IAAI,WAAA,CAAY,EAAE,OAAA,EAAS,WAAA,EAAa,MAAM,WAAA,EAAa,UAAA,EAAY,GAAA,EAAK,IAAA,EAAM,CAAA;AAAA,EAC3F;AAEA,EAAA,IAAI,IAAA,KAAS,IAAA,IAAQ,OAAO,IAAA,KAAS,QAAA,EAAU;AAC7C,IAAA,MAAM,CAAA,GAAI,IAAA;AACV,IAAA,MAAMA,KAAAA,GAAO,OAAO,CAAA,CAAE,OAAO,CAAA,KAAM,WAAW,CAAA,CAAE,OAAO,CAAA,GAAI,qBAAA,CAAsB,UAAU,CAAA;AAC3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AC7B,IAAA,MAAM,GAAA,GAAM,MAAM,IAAA,CAAK,IAAA,CAAK,OAAA,CAAiC;AAAA,MAC3D,MAAA,EAAQ,KAAA;AAAA,MACR,IAAA,EAAM;AAAA,KACP,CAAA;AACD,IAAA,OAAO;AAAA,MACL,IAAA,EAAM,MAAA,CAAO,GAAA,CAAI,MAAM,KAAK,EAAE,CAAA;AAAA,MAC9B,QAAA,EAAU,OAAO,GAAA,CAAI,UAAU,MAAM,QAAA,GAAW,GAAA,CAAI,UAAU,CAAA,GAAI;AAAA,KACpE;AAAA,EACF;AACF,CAAA;;;ACbO,IAAM,eAAN,MAAmB;AAAA,EAMxB,YAAY,OAAA,EAA8B;AACxC,IAAA,MAAM,IAAA,GAAoB,OAAA,CAAQ,UAAA,IAAc,IAAI,gBAAA,CAAiB;AAAA,MACnE,QAAQ,OAAA,CAAQ,MAAA;AAAA,MAChB,GAAI,QAAQ,OAAA,KAAY,MAAA,GAAY,EAAE,OAAA,EAAS,OAAA,CAAQ,OAAA,EAAQ,GAAI;AAAC,KACrE,CAAA;AAED,IAAA,IAAA,CAAK,EAAA,GAAK,IAAI,UAAA,CAAW,IAAI,CAAA;AAC7B,IAAA,IAAA,CAAK,YAAA,GAAe,IAAI,oBAAA,CAAqB,IAAI,CAAA;AACjD,IAAA,IAAA,CAAK,YAAA,GAAe,IAAI,oBAAA,CAAqB,IAAI,CAAA;AACjD,IAAA,IAAA,CAAK,QAAA,GAAW,IAAI,gBAAA,CAAiB,IAAI,CAAA;AAAA,EAC3C;AACF","file":"index.cjs","sourcesContent":["export class PabiloError extends Error {\n readonly code: string;\n readonly statusCode: number | undefined;\n readonly raw: unknown;\n\n constructor(opts: {\n message: string;\n code: string;\n statusCode?: number;\n raw?: unknown;\n }) {\n super(opts.message);\n this.name = 'PabiloError';\n this.code = opts.code;\n this.statusCode = opts.statusCode;\n this.raw = opts.raw;\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\nexport function parsePabiloError(body: unknown, statusCode: number): PabiloError {\n if (statusCode === 401) {\n return new PabiloError({ message: 'Unauthorized', code: 'UNAUTHORIZED', statusCode, raw: body });\n }\n if (statusCode === 404) {\n return new PabiloError({ message: 'Not found', code: 'NOT_FOUND', statusCode, raw: body });\n }\n\n if (body !== null && typeof body === 'object') {\n const b = body as Record<string, unknown>;\n const code = typeof b['error'] === 'string' ? b['error'] : resolveCodeFromStatus(statusCode);\n const message = typeof b['message'] === 'string' ? b['message'] : code;\n return new PabiloError({ message, code, statusCode, raw: body });\n }\n\n const code = resolveCodeFromStatus(statusCode);\n return new PabiloError({ message: code, code, statusCode, raw: body });\n}\n\nfunction resolveCodeFromStatus(statusCode: number): string {\n if (statusCode >= 500) return 'INTERNAL_SERVER_ERROR';\n if (statusCode === 400) return 'BAD_REQUEST';\n return 'REQUEST_FAILED';\n}\n","import type { IHttpClient, RequestOptions } from '../ports/http.js';\nimport { PabiloError, parsePabiloError } from '../domain/errors.js';\n\ntype FetchFn = typeof globalThis.fetch;\n\nexport class FetchHttpClient implements IHttpClient {\n private readonly fetchFn: FetchFn;\n\n constructor(fetchImpl?: FetchFn) {\n this.fetchFn = fetchImpl ?? globalThis.fetch.bind(globalThis);\n }\n\n async request<T>(options: RequestOptions): Promise<T> {\n const { method, path, body, headers = {} } = options;\n\n const init: RequestInit = { method, headers: { ...headers } };\n\n if (body !== undefined) {\n (init.headers as Record<string, string>)['content-type'] = 'application/json';\n init.body = JSON.stringify(body);\n }\n\n let response: Response;\n try {\n response = await this.fetchFn(path, init);\n } catch (cause) {\n throw new PabiloError({\n message: cause instanceof Error ? cause.message : 'Network request failed',\n code: 'NETWORK_ERROR',\n raw: cause,\n });\n }\n\n let responseBody: unknown;\n try {\n responseBody = await response.json();\n } catch {\n responseBody = null;\n }\n\n if (!response.ok) {\n throw parsePabiloError(responseBody, response.status);\n }\n\n return responseBody as T;\n }\n}\n","import type { IHttpClient, RequestOptions } from '../ports/http.js';\nimport { FetchHttpClient } from './fetch-http-client.js';\n\nexport interface PabiloHttpClientOptions {\n apiKey: string;\n baseUrl?: string;\n httpClient?: IHttpClient;\n}\n\nconst DEFAULT_BASE_URL = 'https://api.pabilo.app';\n\nexport class PabiloHttpClient implements IHttpClient {\n private readonly inner: IHttpClient;\n private readonly baseUrl: string;\n private readonly apiKey: string;\n\n constructor(options: PabiloHttpClientOptions) {\n this.apiKey = options.apiKey;\n this.baseUrl = (options.baseUrl ?? DEFAULT_BASE_URL).replace(/\\/$/, '');\n this.inner = options.httpClient ?? new FetchHttpClient();\n }\n\n request<T>(options: RequestOptions): Promise<T> {\n const url = `${this.baseUrl}${options.path}`;\n return this.inner.request<T>({\n ...options,\n path: url,\n headers: {\n ...options.headers,\n appKey: this.apiKey,\n },\n });\n }\n}\n","import type { IHttpClient } from '../ports/http.js';\nimport type { IBankAccountsPort } from '../ports/bank-accounts.js';\nimport type { UserBank, BankAccountEntry } from '../domain/types.js';\n\nexport class BankAccountsResource implements IBankAccountsPort {\n constructor(private readonly http: IHttpClient) {}\n\n async list(): Promise<UserBank[]> {\n const res = await this.http.request<Record<string, unknown>>({\n method: 'GET',\n path: '/me/usersbank',\n });\n\n const raw =\n Array.isArray(res['user_banks']) ? res['user_banks'] :\n Array.isArray(res['data']) ? res['data'] :\n [];\n\n return (raw as unknown[]).map(normalizeUserBank);\n }\n}\n\nfunction normalizeUserBank(raw: unknown): UserBank {\n const b = raw as Record<string, unknown>;\n const bankAccounts = Array.isArray(b['bank_accounts'])\n ? (b['bank_accounts'] as unknown[]).map(normalizeBankAccount)\n : [];\n\n return {\n id: String(b['id'] ?? ''),\n description: String(b['description'] ?? ''),\n provider: String(b['provider'] ?? ''),\n bank_accounts: bankAccounts,\n payment_link: typeof b['payment_link'] === 'boolean' ? b['payment_link'] : undefined,\n to_trash: typeof b['to_trash'] === 'boolean' ? b['to_trash'] : undefined,\n };\n}\n\nfunction normalizeBankAccount(raw: unknown): BankAccountEntry {\n const a = raw as Record<string, unknown>;\n return {\n account_number: String(a['account_number'] ?? ''),\n account_type: String(a['account_type'] ?? a['type'] ?? ''),\n };\n}\n","import type { IHttpClient } from '../ports/http.js';\nimport type { IPaymentLinksPort } from '../ports/payment-links.js';\nimport type {\n PaymentLink,\n CreatePaymentLinkRequest,\n UpdatePaymentLinkRequest,\n} from '../domain/types.js';\n\nexport class PaymentLinksResource implements IPaymentLinksPort {\n constructor(private readonly http: IHttpClient) {}\n\n async create(req: CreatePaymentLinkRequest): Promise<PaymentLink> {\n const body: Record<string, unknown> = {\n amount: req.amount,\n description: req.description,\n userBankId: req.userBankId,\n currency: req.currency ?? 'VES',\n };\n if (req.redirectUrl !== undefined) body['redirect_url'] = req.redirectUrl;\n if (req.webhookUrl !== undefined) body['webhook_url'] = req.webhookUrl;\n if (req.name !== undefined) body['name'] = req.name;\n if (req.isUsd !== undefined) body['is_usd'] = req.isUsd;\n if (req.metadata !== undefined) body['metadata'] = req.metadata;\n\n const res = await this.http.request<Record<string, unknown>>({\n method: 'POST',\n path: '/v1/paymentlink',\n body,\n });\n\n return normalizePaymentLink(res);\n }\n\n async update(id: string, req: UpdatePaymentLinkRequest): Promise<PaymentLink> {\n const body: Record<string, unknown> = {};\n if (req.amount !== undefined) body['amount'] = req.amount;\n if (req.description !== undefined) body['description'] = req.description;\n if (req.redirectUrl !== undefined) body['redirect_url'] = req.redirectUrl;\n if (req.currency !== undefined) body['currency'] = req.currency;\n\n const res = await this.http.request<Record<string, unknown>>({\n method: 'PATCH',\n path: `/paymentlink/${id}/patch`,\n body,\n });\n\n return normalizePaymentLink(res);\n }\n\n async getInfo(id: string): Promise<PaymentLink> {\n const res = await this.http.request<Record<string, unknown>>({\n method: 'GET',\n path: `/paymentlink/${id}/info`,\n });\n\n // Shape: { data: { payment_link: {...} } } or { data: {...} } or root\n const inner =\n (res['data'] as Record<string, unknown> | undefined)?.['payment_link'] ??\n res['data'] ??\n res;\n\n return normalizePaymentLink(inner as Record<string, unknown>);\n }\n}\n\nfunction normalizePaymentLink(raw: Record<string, unknown>): PaymentLink {\n // Shape: { paymentlink: { id, url } } or { data: { id, url } } or root { id, url }\n const src =\n (raw['paymentlink'] as Record<string, unknown> | undefined) ??\n (raw['data'] as Record<string, unknown> | undefined) ??\n raw;\n\n return {\n id: String(src['id'] ?? ''),\n url: String(src['url'] ?? ''),\n amount: typeof src['amount'] === 'number' ? src['amount'] : undefined,\n status: typeof src['status'] === 'string' ? src['status'] : undefined,\n userId: typeof src['user_id'] === 'string' ? src['user_id'] :\n typeof src['userId'] === 'string' ? src['userId'] : undefined,\n };\n}\n","import type { IHttpClient } from '../ports/http.js';\nimport type { IPaymentsPort } from '../ports/payments.js';\nimport type { VerifyPaymentRequest, VerifyPaymentResult, PaymentData } from '../domain/types.js';\n\nexport class PaymentsResource implements IPaymentsPort {\n constructor(private readonly http: IHttpClient) {}\n\n async verify(userBankId: string, req: VerifyPaymentRequest): Promise<VerifyPaymentResult> {\n // This endpoint returns HTTP 200 even for domain errors (BANK_NOT_AVAILABLE, PAYMENT_NOT_FOUND).\n // We read the raw response and interpret it ourselves instead of letting the HTTP client throw.\n const res = await this.http.request<Record<string, unknown>>({\n method: 'POST',\n path: `/userbankpayment/${userBankId}/betaserio`,\n body: {\n amount: req.amount,\n bank_reference: req.bankReference,\n movement_type: req.movementType ?? 'GENERIC',\n },\n });\n\n if (res['error'] === 'BANK_NOT_AVAILABLE') {\n return { found: false, reason: 'BANK_NOT_AVAILABLE' };\n }\n\n if (res['error'] === 'PAYMENT_NOT_FOUND') {\n return { found: false, reason: 'PAYMENT_NOT_FOUND' };\n }\n\n const data = res['data'] as Record<string, unknown> | undefined;\n if (data !== undefined) {\n return {\n found: true,\n isNew: data['is_new'] === true,\n data: data as PaymentData,\n };\n }\n\n return { found: false, reason: 'PAYMENT_NOT_FOUND' };\n }\n}\n","import type { IHttpClient } from '../ports/http.js';\nimport type { IMePort } from '../ports/me.js';\nimport type { User, Plan } from '../domain/types.js';\n\nexport class MeResource implements IMePort {\n constructor(private readonly http: IHttpClient) {}\n\n async getMe(): Promise<User> {\n const res = await this.http.request<Record<string, unknown>>({\n method: 'GET',\n path: '/me',\n });\n const u = (res['user'] ?? res) as Record<string, unknown>;\n return {\n id: String(u['id'] ?? ''),\n email: typeof u['email'] === 'string' ? u['email'] : undefined,\n name: typeof u['name'] === 'string' ? u['name'] : undefined,\n };\n }\n\n async getPlan(): Promise<Plan> {\n const res = await this.http.request<Record<string, unknown>>({\n method: 'GET',\n path: '/me/plan',\n });\n return {\n name: String(res['name'] ?? ''),\n planType: typeof res['planType'] === 'string' ? res['planType'] : undefined,\n };\n }\n}\n","import { PabiloHttpClient } from './infrastructure/pabilo-http-client.js';\nimport { BankAccountsResource } from './resources/bank-accounts.resource.js';\nimport { PaymentLinksResource } from './resources/payment-links.resource.js';\nimport { PaymentsResource } from './resources/payments.resource.js';\nimport { MeResource } from './resources/me.resource.js';\nimport type { IHttpClient } from './ports/http.js';\nimport type { IBankAccountsPort } from './ports/bank-accounts.js';\nimport type { IPaymentLinksPort } from './ports/payment-links.js';\nimport type { IPaymentsPort } from './ports/payments.js';\nimport type { IMePort } from './ports/me.js';\n\nexport interface PabiloClientOptions {\n apiKey: string;\n baseUrl?: string;\n httpClient?: IHttpClient;\n}\n\nexport class PabiloClient {\n readonly me: IMePort;\n readonly bankAccounts: IBankAccountsPort;\n readonly paymentLinks: IPaymentLinksPort;\n readonly payments: IPaymentsPort;\n\n constructor(options: PabiloClientOptions) {\n const http: IHttpClient = options.httpClient ?? new PabiloHttpClient({\n apiKey: options.apiKey,\n ...(options.baseUrl !== undefined ? { baseUrl: options.baseUrl } : {}),\n });\n\n this.me = new MeResource(http);\n this.bankAccounts = new BankAccountsResource(http);\n this.paymentLinks = new PaymentLinksResource(http);\n this.payments = new PaymentsResource(http);\n }\n}\n"]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
interface RequestOptions {
|
|
2
|
+
method: 'GET' | 'POST' | 'PATCH' | 'PUT' | 'DELETE';
|
|
3
|
+
path: string;
|
|
4
|
+
body?: unknown;
|
|
5
|
+
headers?: Record<string, string>;
|
|
6
|
+
}
|
|
7
|
+
interface IHttpClient {
|
|
8
|
+
request<T>(options: RequestOptions): Promise<T>;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
type BankProvider = 'BANESCO' | 'MERCANTIL' | 'BDV' | 'PROVINCIAL' | (string & Record<never, never>);
|
|
12
|
+
type AccountType = 'SAVINGS' | 'CHECKING' | (string & Record<never, never>);
|
|
13
|
+
type PaymentLinkStatus = 'PENDING' | 'PAID' | 'EXPIRED' | 'CANCELLED' | (string & Record<never, never>);
|
|
14
|
+
type PabiloErrorCode = 'BANK_NOT_AVAILABLE' | 'PAYMENT_NOT_FOUND' | 'BAD_REQUEST' | 'UNAUTHORIZED' | 'NOT_FOUND' | 'INTERNAL_SERVER_ERROR' | 'NETWORK_ERROR' | 'REQUEST_FAILED' | (string & Record<never, never>);
|
|
15
|
+
interface BankAccountEntry {
|
|
16
|
+
account_number: string;
|
|
17
|
+
account_type: AccountType;
|
|
18
|
+
}
|
|
19
|
+
interface UserBank {
|
|
20
|
+
id: string;
|
|
21
|
+
description: string;
|
|
22
|
+
provider: BankProvider;
|
|
23
|
+
bank_accounts: BankAccountEntry[];
|
|
24
|
+
payment_link?: boolean;
|
|
25
|
+
to_trash?: boolean;
|
|
26
|
+
}
|
|
27
|
+
interface User {
|
|
28
|
+
id: string;
|
|
29
|
+
email?: string;
|
|
30
|
+
name?: string;
|
|
31
|
+
}
|
|
32
|
+
interface Plan {
|
|
33
|
+
name: string;
|
|
34
|
+
planType?: string;
|
|
35
|
+
}
|
|
36
|
+
interface PaymentLink {
|
|
37
|
+
id: string;
|
|
38
|
+
url: string;
|
|
39
|
+
amount?: number;
|
|
40
|
+
status?: PaymentLinkStatus;
|
|
41
|
+
userId?: string;
|
|
42
|
+
}
|
|
43
|
+
interface PaymentData {
|
|
44
|
+
is_new: boolean;
|
|
45
|
+
[key: string]: unknown;
|
|
46
|
+
}
|
|
47
|
+
interface CreatePaymentLinkRequest {
|
|
48
|
+
amount: number;
|
|
49
|
+
description: string;
|
|
50
|
+
userBankId: string;
|
|
51
|
+
currency?: string;
|
|
52
|
+
redirectUrl?: string;
|
|
53
|
+
webhookUrl?: string;
|
|
54
|
+
name?: string;
|
|
55
|
+
isUsd?: boolean;
|
|
56
|
+
metadata?: Record<string, unknown>;
|
|
57
|
+
}
|
|
58
|
+
interface UpdatePaymentLinkRequest {
|
|
59
|
+
amount?: number;
|
|
60
|
+
description?: string;
|
|
61
|
+
redirectUrl?: string;
|
|
62
|
+
currency?: string;
|
|
63
|
+
}
|
|
64
|
+
interface VerifyPaymentRequest {
|
|
65
|
+
amount: number;
|
|
66
|
+
bankReference: string;
|
|
67
|
+
movementType?: string;
|
|
68
|
+
}
|
|
69
|
+
type VerifyPaymentResult = {
|
|
70
|
+
found: false;
|
|
71
|
+
reason: 'BANK_NOT_AVAILABLE' | 'PAYMENT_NOT_FOUND';
|
|
72
|
+
} | {
|
|
73
|
+
found: true;
|
|
74
|
+
isNew: boolean;
|
|
75
|
+
data: PaymentData;
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
interface IBankAccountsPort {
|
|
79
|
+
list(): Promise<UserBank[]>;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
interface IPaymentLinksPort {
|
|
83
|
+
create(req: CreatePaymentLinkRequest): Promise<PaymentLink>;
|
|
84
|
+
update(id: string, req: UpdatePaymentLinkRequest): Promise<PaymentLink>;
|
|
85
|
+
getInfo(id: string): Promise<PaymentLink>;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
interface IPaymentsPort {
|
|
89
|
+
verify(userBankId: string, req: VerifyPaymentRequest): Promise<VerifyPaymentResult>;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
interface IMePort {
|
|
93
|
+
getMe(): Promise<User>;
|
|
94
|
+
getPlan(): Promise<Plan>;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
interface PabiloClientOptions {
|
|
98
|
+
apiKey: string;
|
|
99
|
+
baseUrl?: string;
|
|
100
|
+
httpClient?: IHttpClient;
|
|
101
|
+
}
|
|
102
|
+
declare class PabiloClient {
|
|
103
|
+
readonly me: IMePort;
|
|
104
|
+
readonly bankAccounts: IBankAccountsPort;
|
|
105
|
+
readonly paymentLinks: IPaymentLinksPort;
|
|
106
|
+
readonly payments: IPaymentsPort;
|
|
107
|
+
constructor(options: PabiloClientOptions);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
declare class PabiloError extends Error {
|
|
111
|
+
readonly code: string;
|
|
112
|
+
readonly statusCode: number | undefined;
|
|
113
|
+
readonly raw: unknown;
|
|
114
|
+
constructor(opts: {
|
|
115
|
+
message: string;
|
|
116
|
+
code: string;
|
|
117
|
+
statusCode?: number;
|
|
118
|
+
raw?: unknown;
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
type FetchFn = typeof globalThis.fetch;
|
|
123
|
+
declare class FetchHttpClient implements IHttpClient {
|
|
124
|
+
private readonly fetchFn;
|
|
125
|
+
constructor(fetchImpl?: FetchFn);
|
|
126
|
+
request<T>(options: RequestOptions): Promise<T>;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
interface PabiloHttpClientOptions {
|
|
130
|
+
apiKey: string;
|
|
131
|
+
baseUrl?: string;
|
|
132
|
+
httpClient?: IHttpClient;
|
|
133
|
+
}
|
|
134
|
+
declare class PabiloHttpClient implements IHttpClient {
|
|
135
|
+
private readonly inner;
|
|
136
|
+
private readonly baseUrl;
|
|
137
|
+
private readonly apiKey;
|
|
138
|
+
constructor(options: PabiloHttpClientOptions);
|
|
139
|
+
request<T>(options: RequestOptions): Promise<T>;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export { type AccountType, type BankAccountEntry, type BankProvider, type CreatePaymentLinkRequest, FetchHttpClient, type IBankAccountsPort, type IHttpClient, type IMePort, type IPaymentLinksPort, type IPaymentsPort, PabiloClient, type PabiloClientOptions, PabiloError, type PabiloErrorCode, PabiloHttpClient, type PabiloHttpClientOptions, type PaymentData, type PaymentLink, type PaymentLinkStatus, type Plan, type RequestOptions, type UpdatePaymentLinkRequest, type User, type UserBank, type VerifyPaymentRequest, type VerifyPaymentResult };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
interface RequestOptions {
|
|
2
|
+
method: 'GET' | 'POST' | 'PATCH' | 'PUT' | 'DELETE';
|
|
3
|
+
path: string;
|
|
4
|
+
body?: unknown;
|
|
5
|
+
headers?: Record<string, string>;
|
|
6
|
+
}
|
|
7
|
+
interface IHttpClient {
|
|
8
|
+
request<T>(options: RequestOptions): Promise<T>;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
type BankProvider = 'BANESCO' | 'MERCANTIL' | 'BDV' | 'PROVINCIAL' | (string & Record<never, never>);
|
|
12
|
+
type AccountType = 'SAVINGS' | 'CHECKING' | (string & Record<never, never>);
|
|
13
|
+
type PaymentLinkStatus = 'PENDING' | 'PAID' | 'EXPIRED' | 'CANCELLED' | (string & Record<never, never>);
|
|
14
|
+
type PabiloErrorCode = 'BANK_NOT_AVAILABLE' | 'PAYMENT_NOT_FOUND' | 'BAD_REQUEST' | 'UNAUTHORIZED' | 'NOT_FOUND' | 'INTERNAL_SERVER_ERROR' | 'NETWORK_ERROR' | 'REQUEST_FAILED' | (string & Record<never, never>);
|
|
15
|
+
interface BankAccountEntry {
|
|
16
|
+
account_number: string;
|
|
17
|
+
account_type: AccountType;
|
|
18
|
+
}
|
|
19
|
+
interface UserBank {
|
|
20
|
+
id: string;
|
|
21
|
+
description: string;
|
|
22
|
+
provider: BankProvider;
|
|
23
|
+
bank_accounts: BankAccountEntry[];
|
|
24
|
+
payment_link?: boolean;
|
|
25
|
+
to_trash?: boolean;
|
|
26
|
+
}
|
|
27
|
+
interface User {
|
|
28
|
+
id: string;
|
|
29
|
+
email?: string;
|
|
30
|
+
name?: string;
|
|
31
|
+
}
|
|
32
|
+
interface Plan {
|
|
33
|
+
name: string;
|
|
34
|
+
planType?: string;
|
|
35
|
+
}
|
|
36
|
+
interface PaymentLink {
|
|
37
|
+
id: string;
|
|
38
|
+
url: string;
|
|
39
|
+
amount?: number;
|
|
40
|
+
status?: PaymentLinkStatus;
|
|
41
|
+
userId?: string;
|
|
42
|
+
}
|
|
43
|
+
interface PaymentData {
|
|
44
|
+
is_new: boolean;
|
|
45
|
+
[key: string]: unknown;
|
|
46
|
+
}
|
|
47
|
+
interface CreatePaymentLinkRequest {
|
|
48
|
+
amount: number;
|
|
49
|
+
description: string;
|
|
50
|
+
userBankId: string;
|
|
51
|
+
currency?: string;
|
|
52
|
+
redirectUrl?: string;
|
|
53
|
+
webhookUrl?: string;
|
|
54
|
+
name?: string;
|
|
55
|
+
isUsd?: boolean;
|
|
56
|
+
metadata?: Record<string, unknown>;
|
|
57
|
+
}
|
|
58
|
+
interface UpdatePaymentLinkRequest {
|
|
59
|
+
amount?: number;
|
|
60
|
+
description?: string;
|
|
61
|
+
redirectUrl?: string;
|
|
62
|
+
currency?: string;
|
|
63
|
+
}
|
|
64
|
+
interface VerifyPaymentRequest {
|
|
65
|
+
amount: number;
|
|
66
|
+
bankReference: string;
|
|
67
|
+
movementType?: string;
|
|
68
|
+
}
|
|
69
|
+
type VerifyPaymentResult = {
|
|
70
|
+
found: false;
|
|
71
|
+
reason: 'BANK_NOT_AVAILABLE' | 'PAYMENT_NOT_FOUND';
|
|
72
|
+
} | {
|
|
73
|
+
found: true;
|
|
74
|
+
isNew: boolean;
|
|
75
|
+
data: PaymentData;
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
interface IBankAccountsPort {
|
|
79
|
+
list(): Promise<UserBank[]>;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
interface IPaymentLinksPort {
|
|
83
|
+
create(req: CreatePaymentLinkRequest): Promise<PaymentLink>;
|
|
84
|
+
update(id: string, req: UpdatePaymentLinkRequest): Promise<PaymentLink>;
|
|
85
|
+
getInfo(id: string): Promise<PaymentLink>;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
interface IPaymentsPort {
|
|
89
|
+
verify(userBankId: string, req: VerifyPaymentRequest): Promise<VerifyPaymentResult>;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
interface IMePort {
|
|
93
|
+
getMe(): Promise<User>;
|
|
94
|
+
getPlan(): Promise<Plan>;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
interface PabiloClientOptions {
|
|
98
|
+
apiKey: string;
|
|
99
|
+
baseUrl?: string;
|
|
100
|
+
httpClient?: IHttpClient;
|
|
101
|
+
}
|
|
102
|
+
declare class PabiloClient {
|
|
103
|
+
readonly me: IMePort;
|
|
104
|
+
readonly bankAccounts: IBankAccountsPort;
|
|
105
|
+
readonly paymentLinks: IPaymentLinksPort;
|
|
106
|
+
readonly payments: IPaymentsPort;
|
|
107
|
+
constructor(options: PabiloClientOptions);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
declare class PabiloError extends Error {
|
|
111
|
+
readonly code: string;
|
|
112
|
+
readonly statusCode: number | undefined;
|
|
113
|
+
readonly raw: unknown;
|
|
114
|
+
constructor(opts: {
|
|
115
|
+
message: string;
|
|
116
|
+
code: string;
|
|
117
|
+
statusCode?: number;
|
|
118
|
+
raw?: unknown;
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
type FetchFn = typeof globalThis.fetch;
|
|
123
|
+
declare class FetchHttpClient implements IHttpClient {
|
|
124
|
+
private readonly fetchFn;
|
|
125
|
+
constructor(fetchImpl?: FetchFn);
|
|
126
|
+
request<T>(options: RequestOptions): Promise<T>;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
interface PabiloHttpClientOptions {
|
|
130
|
+
apiKey: string;
|
|
131
|
+
baseUrl?: string;
|
|
132
|
+
httpClient?: IHttpClient;
|
|
133
|
+
}
|
|
134
|
+
declare class PabiloHttpClient implements IHttpClient {
|
|
135
|
+
private readonly inner;
|
|
136
|
+
private readonly baseUrl;
|
|
137
|
+
private readonly apiKey;
|
|
138
|
+
constructor(options: PabiloHttpClientOptions);
|
|
139
|
+
request<T>(options: RequestOptions): Promise<T>;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export { type AccountType, type BankAccountEntry, type BankProvider, type CreatePaymentLinkRequest, FetchHttpClient, type IBankAccountsPort, type IHttpClient, type IMePort, type IPaymentLinksPort, type IPaymentsPort, PabiloClient, type PabiloClientOptions, PabiloError, type PabiloErrorCode, PabiloHttpClient, type PabiloHttpClientOptions, type PaymentData, type PaymentLink, type PaymentLinkStatus, type Plan, type RequestOptions, type UpdatePaymentLinkRequest, type User, type UserBank, type VerifyPaymentRequest, type VerifyPaymentResult };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
// src/domain/errors.ts
|
|
2
|
+
var PabiloError = class extends Error {
|
|
3
|
+
constructor(opts) {
|
|
4
|
+
super(opts.message);
|
|
5
|
+
this.name = "PabiloError";
|
|
6
|
+
this.code = opts.code;
|
|
7
|
+
this.statusCode = opts.statusCode;
|
|
8
|
+
this.raw = opts.raw;
|
|
9
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
function parsePabiloError(body, statusCode) {
|
|
13
|
+
if (statusCode === 401) {
|
|
14
|
+
return new PabiloError({ message: "Unauthorized", code: "UNAUTHORIZED", statusCode, raw: body });
|
|
15
|
+
}
|
|
16
|
+
if (statusCode === 404) {
|
|
17
|
+
return new PabiloError({ message: "Not found", code: "NOT_FOUND", statusCode, raw: body });
|
|
18
|
+
}
|
|
19
|
+
if (body !== null && typeof body === "object") {
|
|
20
|
+
const b = body;
|
|
21
|
+
const code2 = typeof b["error"] === "string" ? b["error"] : resolveCodeFromStatus(statusCode);
|
|
22
|
+
const message = typeof b["message"] === "string" ? b["message"] : code2;
|
|
23
|
+
return new PabiloError({ message, code: code2, statusCode, raw: body });
|
|
24
|
+
}
|
|
25
|
+
const code = resolveCodeFromStatus(statusCode);
|
|
26
|
+
return new PabiloError({ message: code, code, statusCode, raw: body });
|
|
27
|
+
}
|
|
28
|
+
function resolveCodeFromStatus(statusCode) {
|
|
29
|
+
if (statusCode >= 500) return "INTERNAL_SERVER_ERROR";
|
|
30
|
+
if (statusCode === 400) return "BAD_REQUEST";
|
|
31
|
+
return "REQUEST_FAILED";
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// src/infrastructure/fetch-http-client.ts
|
|
35
|
+
var FetchHttpClient = class {
|
|
36
|
+
constructor(fetchImpl) {
|
|
37
|
+
this.fetchFn = fetchImpl ?? globalThis.fetch.bind(globalThis);
|
|
38
|
+
}
|
|
39
|
+
async request(options) {
|
|
40
|
+
const { method, path, body, headers = {} } = options;
|
|
41
|
+
const init = { method, headers: { ...headers } };
|
|
42
|
+
if (body !== void 0) {
|
|
43
|
+
init.headers["content-type"] = "application/json";
|
|
44
|
+
init.body = JSON.stringify(body);
|
|
45
|
+
}
|
|
46
|
+
let response;
|
|
47
|
+
try {
|
|
48
|
+
response = await this.fetchFn(path, init);
|
|
49
|
+
} catch (cause) {
|
|
50
|
+
throw new PabiloError({
|
|
51
|
+
message: cause instanceof Error ? cause.message : "Network request failed",
|
|
52
|
+
code: "NETWORK_ERROR",
|
|
53
|
+
raw: cause
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
let responseBody;
|
|
57
|
+
try {
|
|
58
|
+
responseBody = await response.json();
|
|
59
|
+
} catch {
|
|
60
|
+
responseBody = null;
|
|
61
|
+
}
|
|
62
|
+
if (!response.ok) {
|
|
63
|
+
throw parsePabiloError(responseBody, response.status);
|
|
64
|
+
}
|
|
65
|
+
return responseBody;
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
// src/infrastructure/pabilo-http-client.ts
|
|
70
|
+
var DEFAULT_BASE_URL = "https://api.pabilo.app";
|
|
71
|
+
var PabiloHttpClient = class {
|
|
72
|
+
constructor(options) {
|
|
73
|
+
this.apiKey = options.apiKey;
|
|
74
|
+
this.baseUrl = (options.baseUrl ?? DEFAULT_BASE_URL).replace(/\/$/, "");
|
|
75
|
+
this.inner = options.httpClient ?? new FetchHttpClient();
|
|
76
|
+
}
|
|
77
|
+
request(options) {
|
|
78
|
+
const url = `${this.baseUrl}${options.path}`;
|
|
79
|
+
return this.inner.request({
|
|
80
|
+
...options,
|
|
81
|
+
path: url,
|
|
82
|
+
headers: {
|
|
83
|
+
...options.headers,
|
|
84
|
+
appKey: this.apiKey
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
// src/resources/bank-accounts.resource.ts
|
|
91
|
+
var BankAccountsResource = class {
|
|
92
|
+
constructor(http) {
|
|
93
|
+
this.http = http;
|
|
94
|
+
}
|
|
95
|
+
async list() {
|
|
96
|
+
const res = await this.http.request({
|
|
97
|
+
method: "GET",
|
|
98
|
+
path: "/me/usersbank"
|
|
99
|
+
});
|
|
100
|
+
const raw = Array.isArray(res["user_banks"]) ? res["user_banks"] : Array.isArray(res["data"]) ? res["data"] : [];
|
|
101
|
+
return raw.map(normalizeUserBank);
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
function normalizeUserBank(raw) {
|
|
105
|
+
const b = raw;
|
|
106
|
+
const bankAccounts = Array.isArray(b["bank_accounts"]) ? b["bank_accounts"].map(normalizeBankAccount) : [];
|
|
107
|
+
return {
|
|
108
|
+
id: String(b["id"] ?? ""),
|
|
109
|
+
description: String(b["description"] ?? ""),
|
|
110
|
+
provider: String(b["provider"] ?? ""),
|
|
111
|
+
bank_accounts: bankAccounts,
|
|
112
|
+
payment_link: typeof b["payment_link"] === "boolean" ? b["payment_link"] : void 0,
|
|
113
|
+
to_trash: typeof b["to_trash"] === "boolean" ? b["to_trash"] : void 0
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
function normalizeBankAccount(raw) {
|
|
117
|
+
const a = raw;
|
|
118
|
+
return {
|
|
119
|
+
account_number: String(a["account_number"] ?? ""),
|
|
120
|
+
account_type: String(a["account_type"] ?? a["type"] ?? "")
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// src/resources/payment-links.resource.ts
|
|
125
|
+
var PaymentLinksResource = class {
|
|
126
|
+
constructor(http) {
|
|
127
|
+
this.http = http;
|
|
128
|
+
}
|
|
129
|
+
async create(req) {
|
|
130
|
+
const body = {
|
|
131
|
+
amount: req.amount,
|
|
132
|
+
description: req.description,
|
|
133
|
+
userBankId: req.userBankId,
|
|
134
|
+
currency: req.currency ?? "VES"
|
|
135
|
+
};
|
|
136
|
+
if (req.redirectUrl !== void 0) body["redirect_url"] = req.redirectUrl;
|
|
137
|
+
if (req.webhookUrl !== void 0) body["webhook_url"] = req.webhookUrl;
|
|
138
|
+
if (req.name !== void 0) body["name"] = req.name;
|
|
139
|
+
if (req.isUsd !== void 0) body["is_usd"] = req.isUsd;
|
|
140
|
+
if (req.metadata !== void 0) body["metadata"] = req.metadata;
|
|
141
|
+
const res = await this.http.request({
|
|
142
|
+
method: "POST",
|
|
143
|
+
path: "/v1/paymentlink",
|
|
144
|
+
body
|
|
145
|
+
});
|
|
146
|
+
return normalizePaymentLink(res);
|
|
147
|
+
}
|
|
148
|
+
async update(id, req) {
|
|
149
|
+
const body = {};
|
|
150
|
+
if (req.amount !== void 0) body["amount"] = req.amount;
|
|
151
|
+
if (req.description !== void 0) body["description"] = req.description;
|
|
152
|
+
if (req.redirectUrl !== void 0) body["redirect_url"] = req.redirectUrl;
|
|
153
|
+
if (req.currency !== void 0) body["currency"] = req.currency;
|
|
154
|
+
const res = await this.http.request({
|
|
155
|
+
method: "PATCH",
|
|
156
|
+
path: `/paymentlink/${id}/patch`,
|
|
157
|
+
body
|
|
158
|
+
});
|
|
159
|
+
return normalizePaymentLink(res);
|
|
160
|
+
}
|
|
161
|
+
async getInfo(id) {
|
|
162
|
+
const res = await this.http.request({
|
|
163
|
+
method: "GET",
|
|
164
|
+
path: `/paymentlink/${id}/info`
|
|
165
|
+
});
|
|
166
|
+
const inner = res["data"]?.["payment_link"] ?? res["data"] ?? res;
|
|
167
|
+
return normalizePaymentLink(inner);
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
function normalizePaymentLink(raw) {
|
|
171
|
+
const src = raw["paymentlink"] ?? raw["data"] ?? raw;
|
|
172
|
+
return {
|
|
173
|
+
id: String(src["id"] ?? ""),
|
|
174
|
+
url: String(src["url"] ?? ""),
|
|
175
|
+
amount: typeof src["amount"] === "number" ? src["amount"] : void 0,
|
|
176
|
+
status: typeof src["status"] === "string" ? src["status"] : void 0,
|
|
177
|
+
userId: typeof src["user_id"] === "string" ? src["user_id"] : typeof src["userId"] === "string" ? src["userId"] : void 0
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// src/resources/payments.resource.ts
|
|
182
|
+
var PaymentsResource = class {
|
|
183
|
+
constructor(http) {
|
|
184
|
+
this.http = http;
|
|
185
|
+
}
|
|
186
|
+
async verify(userBankId, req) {
|
|
187
|
+
const res = await this.http.request({
|
|
188
|
+
method: "POST",
|
|
189
|
+
path: `/userbankpayment/${userBankId}/betaserio`,
|
|
190
|
+
body: {
|
|
191
|
+
amount: req.amount,
|
|
192
|
+
bank_reference: req.bankReference,
|
|
193
|
+
movement_type: req.movementType ?? "GENERIC"
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
if (res["error"] === "BANK_NOT_AVAILABLE") {
|
|
197
|
+
return { found: false, reason: "BANK_NOT_AVAILABLE" };
|
|
198
|
+
}
|
|
199
|
+
if (res["error"] === "PAYMENT_NOT_FOUND") {
|
|
200
|
+
return { found: false, reason: "PAYMENT_NOT_FOUND" };
|
|
201
|
+
}
|
|
202
|
+
const data = res["data"];
|
|
203
|
+
if (data !== void 0) {
|
|
204
|
+
return {
|
|
205
|
+
found: true,
|
|
206
|
+
isNew: data["is_new"] === true,
|
|
207
|
+
data
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
return { found: false, reason: "PAYMENT_NOT_FOUND" };
|
|
211
|
+
}
|
|
212
|
+
};
|
|
213
|
+
|
|
214
|
+
// src/resources/me.resource.ts
|
|
215
|
+
var MeResource = class {
|
|
216
|
+
constructor(http) {
|
|
217
|
+
this.http = http;
|
|
218
|
+
}
|
|
219
|
+
async getMe() {
|
|
220
|
+
const res = await this.http.request({
|
|
221
|
+
method: "GET",
|
|
222
|
+
path: "/me"
|
|
223
|
+
});
|
|
224
|
+
const u = res["user"] ?? res;
|
|
225
|
+
return {
|
|
226
|
+
id: String(u["id"] ?? ""),
|
|
227
|
+
email: typeof u["email"] === "string" ? u["email"] : void 0,
|
|
228
|
+
name: typeof u["name"] === "string" ? u["name"] : void 0
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
async getPlan() {
|
|
232
|
+
const res = await this.http.request({
|
|
233
|
+
method: "GET",
|
|
234
|
+
path: "/me/plan"
|
|
235
|
+
});
|
|
236
|
+
return {
|
|
237
|
+
name: String(res["name"] ?? ""),
|
|
238
|
+
planType: typeof res["planType"] === "string" ? res["planType"] : void 0
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
};
|
|
242
|
+
|
|
243
|
+
// src/client.ts
|
|
244
|
+
var PabiloClient = class {
|
|
245
|
+
constructor(options) {
|
|
246
|
+
const http = options.httpClient ?? new PabiloHttpClient({
|
|
247
|
+
apiKey: options.apiKey,
|
|
248
|
+
...options.baseUrl !== void 0 ? { baseUrl: options.baseUrl } : {}
|
|
249
|
+
});
|
|
250
|
+
this.me = new MeResource(http);
|
|
251
|
+
this.bankAccounts = new BankAccountsResource(http);
|
|
252
|
+
this.paymentLinks = new PaymentLinksResource(http);
|
|
253
|
+
this.payments = new PaymentsResource(http);
|
|
254
|
+
}
|
|
255
|
+
};
|
|
256
|
+
|
|
257
|
+
export { FetchHttpClient, PabiloClient, PabiloError, PabiloHttpClient };
|
|
258
|
+
//# sourceMappingURL=index.js.map
|
|
259
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/domain/errors.ts","../src/infrastructure/fetch-http-client.ts","../src/infrastructure/pabilo-http-client.ts","../src/resources/bank-accounts.resource.ts","../src/resources/payment-links.resource.ts","../src/resources/payments.resource.ts","../src/resources/me.resource.ts","../src/client.ts"],"names":["code"],"mappings":";AAAO,IAAM,WAAA,GAAN,cAA0B,KAAA,CAAM;AAAA,EAKrC,YAAY,IAAA,EAKT;AACD,IAAA,KAAA,CAAM,KAAK,OAAO,CAAA;AAClB,IAAA,IAAA,CAAK,IAAA,GAAO,aAAA;AACZ,IAAA,IAAA,CAAK,OAAO,IAAA,CAAK,IAAA;AACjB,IAAA,IAAA,CAAK,aAAa,IAAA,CAAK,UAAA;AACvB,IAAA,IAAA,CAAK,MAAM,IAAA,CAAK,GAAA;AAChB,IAAA,MAAA,CAAO,cAAA,CAAe,IAAA,EAAM,GAAA,CAAA,MAAA,CAAW,SAAS,CAAA;AAAA,EAClD;AACF;AAEO,SAAS,gBAAA,CAAiB,MAAe,UAAA,EAAiC;AAC/E,EAAA,IAAI,eAAe,GAAA,EAAK;AACtB,IAAA,OAAO,IAAI,WAAA,CAAY,EAAE,OAAA,EAAS,cAAA,EAAgB,MAAM,cAAA,EAAgB,UAAA,EAAY,GAAA,EAAK,IAAA,EAAM,CAAA;AAAA,EACjG;AACA,EAAA,IAAI,eAAe,GAAA,EAAK;AACtB,IAAA,OAAO,IAAI,WAAA,CAAY,EAAE,OAAA,EAAS,WAAA,EAAa,MAAM,WAAA,EAAa,UAAA,EAAY,GAAA,EAAK,IAAA,EAAM,CAAA;AAAA,EAC3F;AAEA,EAAA,IAAI,IAAA,KAAS,IAAA,IAAQ,OAAO,IAAA,KAAS,QAAA,EAAU;AAC7C,IAAA,MAAM,CAAA,GAAI,IAAA;AACV,IAAA,MAAMA,KAAAA,GAAO,OAA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M,QAAA,GAAW,CAAA,CAAE,MAAM,CAAA,GAAI;AAAA,KACpD;AAAA,EACF;AAAA,EAEA,MAAM,OAAA,GAAyB;AAC7B,IAAA,MAAM,GAAA,GAAM,MAAM,IAAA,CAAK,IAAA,CAAK,OAAA,CAAiC;AAAA,MAC3D,MAAA,EAAQ,KAAA;AAAA,MACR,IAAA,EAAM;AAAA,KACP,CAAA;AACD,IAAA,OAAO;AAAA,MACL,IAAA,EAAM,MAAA,CAAO,GAAA,CAAI,MAAM,KAAK,EAAE,CAAA;AAAA,MAC9B,QAAA,EAAU,OAAO,GAAA,CAAI,UAAU,MAAM,QAAA,GAAW,GAAA,CAAI,UAAU,CAAA,GAAI;AAAA,KACpE;AAAA,EACF;AACF,CAAA;;;ACbO,IAAM,eAAN,MAAmB;AAAA,EAMxB,YAAY,OAAA,EAA8B;AACxC,IAAA,MAAM,IAAA,GAAoB,OAAA,CAAQ,UAAA,IAAc,IAAI,gBAAA,CAAiB;AAAA,MACnE,QAAQ,OAAA,CAAQ,MAAA;AAAA,MAChB,GAAI,QAAQ,OAAA,KAAY,MAAA,GAAY,EAAE,OAAA,EAAS,OAAA,CAAQ,OAAA,EAAQ,GAAI;AAAC,KACrE,CAAA;AAED,IAAA,IAAA,CAAK,EAAA,GAAK,IAAI,UAAA,CAAW,IAAI,CAAA;AAC7B,IAAA,IAAA,CAAK,YAAA,GAAe,IAAI,oBAAA,CAAqB,IAAI,CAAA;AACjD,IAAA,IAAA,CAAK,YAAA,GAAe,IAAI,oBAAA,CAAqB,IAAI,CAAA;AACjD,IAAA,IAAA,CAAK,QAAA,GAAW,IAAI,gBAAA,CAAiB,IAAI,CAAA;AAAA,EAC3C;AACF","file":"index.js","sourcesContent":["export class PabiloError extends Error {\n readonly code: string;\n readonly statusCode: number | undefined;\n readonly raw: unknown;\n\n constructor(opts: {\n message: string;\n code: string;\n statusCode?: number;\n raw?: unknown;\n }) {\n super(opts.message);\n this.name = 'PabiloError';\n this.code = opts.code;\n this.statusCode = opts.statusCode;\n this.raw = opts.raw;\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\nexport function parsePabiloError(body: unknown, statusCode: number): PabiloError {\n if (statusCode === 401) {\n return new PabiloError({ message: 'Unauthorized', code: 'UNAUTHORIZED', statusCode, raw: body });\n }\n if (statusCode === 404) {\n return new PabiloError({ message: 'Not found', code: 'NOT_FOUND', statusCode, raw: body });\n }\n\n if (body !== null && typeof body === 'object') {\n const b = body as Record<string, unknown>;\n const code = typeof b['error'] === 'string' ? b['error'] : resolveCodeFromStatus(statusCode);\n const message = typeof b['message'] === 'string' ? b['message'] : code;\n return new PabiloError({ message, code, statusCode, raw: body });\n }\n\n const code = resolveCodeFromStatus(statusCode);\n return new PabiloError({ message: code, code, statusCode, raw: body });\n}\n\nfunction resolveCodeFromStatus(statusCode: number): string {\n if (statusCode >= 500) return 'INTERNAL_SERVER_ERROR';\n if (statusCode === 400) return 'BAD_REQUEST';\n return 'REQUEST_FAILED';\n}\n","import type { IHttpClient, RequestOptions } from '../ports/http.js';\nimport { PabiloError, parsePabiloError } from '../domain/errors.js';\n\ntype FetchFn = typeof globalThis.fetch;\n\nexport class FetchHttpClient implements IHttpClient {\n private readonly fetchFn: FetchFn;\n\n constructor(fetchImpl?: FetchFn) {\n this.fetchFn = fetchImpl ?? globalThis.fetch.bind(globalThis);\n }\n\n async request<T>(options: RequestOptions): Promise<T> {\n const { method, path, body, headers = {} } = options;\n\n const init: RequestInit = { method, headers: { ...headers } };\n\n if (body !== undefined) {\n (init.headers as Record<string, string>)['content-type'] = 'application/json';\n init.body = JSON.stringify(body);\n }\n\n let response: Response;\n try {\n response = await this.fetchFn(path, init);\n } catch (cause) {\n throw new PabiloError({\n message: cause instanceof Error ? cause.message : 'Network request failed',\n code: 'NETWORK_ERROR',\n raw: cause,\n });\n }\n\n let responseBody: unknown;\n try {\n responseBody = await response.json();\n } catch {\n responseBody = null;\n }\n\n if (!response.ok) {\n throw parsePabiloError(responseBody, response.status);\n }\n\n return responseBody as T;\n }\n}\n","import type { IHttpClient, RequestOptions } from '../ports/http.js';\nimport { FetchHttpClient } from './fetch-http-client.js';\n\nexport interface PabiloHttpClientOptions {\n apiKey: string;\n baseUrl?: string;\n httpClient?: IHttpClient;\n}\n\nconst DEFAULT_BASE_URL = 'https://api.pabilo.app';\n\nexport class PabiloHttpClient implements IHttpClient {\n private readonly inner: IHttpClient;\n private readonly baseUrl: string;\n private readonly apiKey: string;\n\n constructor(options: PabiloHttpClientOptions) {\n this.apiKey = options.apiKey;\n this.baseUrl = (options.baseUrl ?? DEFAULT_BASE_URL).replace(/\\/$/, '');\n this.inner = options.httpClient ?? new FetchHttpClient();\n }\n\n request<T>(options: RequestOptions): Promise<T> {\n const url = `${this.baseUrl}${options.path}`;\n return this.inner.request<T>({\n ...options,\n path: url,\n headers: {\n ...options.headers,\n appKey: this.apiKey,\n },\n });\n }\n}\n","import type { IHttpClient } from '../ports/http.js';\nimport type { IBankAccountsPort } from '../ports/bank-accounts.js';\nimport type { UserBank, BankAccountEntry } from '../domain/types.js';\n\nexport class BankAccountsResource implements IBankAccountsPort {\n constructor(private readonly http: IHttpClient) {}\n\n async list(): Promise<UserBank[]> {\n const res = await this.http.request<Record<string, unknown>>({\n method: 'GET',\n path: '/me/usersbank',\n });\n\n const raw =\n Array.isArray(res['user_banks']) ? res['user_banks'] :\n Array.isArray(res['data']) ? res['data'] :\n [];\n\n return (raw as unknown[]).map(normalizeUserBank);\n }\n}\n\nfunction normalizeUserBank(raw: unknown): UserBank {\n const b = raw as Record<string, unknown>;\n const bankAccounts = Array.isArray(b['bank_accounts'])\n ? (b['bank_accounts'] as unknown[]).map(normalizeBankAccount)\n : [];\n\n return {\n id: String(b['id'] ?? ''),\n description: String(b['description'] ?? ''),\n provider: String(b['provider'] ?? ''),\n bank_accounts: bankAccounts,\n payment_link: typeof b['payment_link'] === 'boolean' ? b['payment_link'] : undefined,\n to_trash: typeof b['to_trash'] === 'boolean' ? b['to_trash'] : undefined,\n };\n}\n\nfunction normalizeBankAccount(raw: unknown): BankAccountEntry {\n const a = raw as Record<string, unknown>;\n return {\n account_number: String(a['account_number'] ?? ''),\n account_type: String(a['account_type'] ?? a['type'] ?? ''),\n };\n}\n","import type { IHttpClient } from '../ports/http.js';\nimport type { IPaymentLinksPort } from '../ports/payment-links.js';\nimport type {\n PaymentLink,\n CreatePaymentLinkRequest,\n UpdatePaymentLinkRequest,\n} from '../domain/types.js';\n\nexport class PaymentLinksResource implements IPaymentLinksPort {\n constructor(private readonly http: IHttpClient) {}\n\n async create(req: CreatePaymentLinkRequest): Promise<PaymentLink> {\n const body: Record<string, unknown> = {\n amount: req.amount,\n description: req.description,\n userBankId: req.userBankId,\n currency: req.currency ?? 'VES',\n };\n if (req.redirectUrl !== undefined) body['redirect_url'] = req.redirectUrl;\n if (req.webhookUrl !== undefined) body['webhook_url'] = req.webhookUrl;\n if (req.name !== undefined) body['name'] = req.name;\n if (req.isUsd !== undefined) body['is_usd'] = req.isUsd;\n if (req.metadata !== undefined) body['metadata'] = req.metadata;\n\n const res = await this.http.request<Record<string, unknown>>({\n method: 'POST',\n path: '/v1/paymentlink',\n body,\n });\n\n return normalizePaymentLink(res);\n }\n\n async update(id: string, req: UpdatePaymentLinkRequest): Promise<PaymentLink> {\n const body: Record<string, unknown> = {};\n if (req.amount !== undefined) body['amount'] = req.amount;\n if (req.description !== undefined) body['description'] = req.description;\n if (req.redirectUrl !== undefined) body['redirect_url'] = req.redirectUrl;\n if (req.currency !== undefined) body['currency'] = req.currency;\n\n const res = await this.http.request<Record<string, unknown>>({\n method: 'PATCH',\n path: `/paymentlink/${id}/patch`,\n body,\n });\n\n return normalizePaymentLink(res);\n }\n\n async getInfo(id: string): Promise<PaymentLink> {\n const res = await this.http.request<Record<string, unknown>>({\n method: 'GET',\n path: `/paymentlink/${id}/info`,\n });\n\n // Shape: { data: { payment_link: {...} } } or { data: {...} } or root\n const inner =\n (res['data'] as Record<string, unknown> | undefined)?.['payment_link'] ??\n res['data'] ??\n res;\n\n return normalizePaymentLink(inner as Record<string, unknown>);\n }\n}\n\nfunction normalizePaymentLink(raw: Record<string, unknown>): PaymentLink {\n // Shape: { paymentlink: { id, url } } or { data: { id, url } } or root { id, url }\n const src =\n (raw['paymentlink'] as Record<string, unknown> | undefined) ??\n (raw['data'] as Record<string, unknown> | undefined) ??\n raw;\n\n return {\n id: String(src['id'] ?? ''),\n url: String(src['url'] ?? ''),\n amount: typeof src['amount'] === 'number' ? src['amount'] : undefined,\n status: typeof src['status'] === 'string' ? src['status'] : undefined,\n userId: typeof src['user_id'] === 'string' ? src['user_id'] :\n typeof src['userId'] === 'string' ? src['userId'] : undefined,\n };\n}\n","import type { IHttpClient } from '../ports/http.js';\nimport type { IPaymentsPort } from '../ports/payments.js';\nimport type { VerifyPaymentRequest, VerifyPaymentResult, PaymentData } from '../domain/types.js';\n\nexport class PaymentsResource implements IPaymentsPort {\n constructor(private readonly http: IHttpClient) {}\n\n async verify(userBankId: string, req: VerifyPaymentRequest): Promise<VerifyPaymentResult> {\n // This endpoint returns HTTP 200 even for domain errors (BANK_NOT_AVAILABLE, PAYMENT_NOT_FOUND).\n // We read the raw response and interpret it ourselves instead of letting the HTTP client throw.\n const res = await this.http.request<Record<string, unknown>>({\n method: 'POST',\n path: `/userbankpayment/${userBankId}/betaserio`,\n body: {\n amount: req.amount,\n bank_reference: req.bankReference,\n movement_type: req.movementType ?? 'GENERIC',\n },\n });\n\n if (res['error'] === 'BANK_NOT_AVAILABLE') {\n return { found: false, reason: 'BANK_NOT_AVAILABLE' };\n }\n\n if (res['error'] === 'PAYMENT_NOT_FOUND') {\n return { found: false, reason: 'PAYMENT_NOT_FOUND' };\n }\n\n const data = res['data'] as Record<string, unknown> | undefined;\n if (data !== undefined) {\n return {\n found: true,\n isNew: data['is_new'] === true,\n data: data as PaymentData,\n };\n }\n\n return { found: false, reason: 'PAYMENT_NOT_FOUND' };\n }\n}\n","import type { IHttpClient } from '../ports/http.js';\nimport type { IMePort } from '../ports/me.js';\nimport type { User, Plan } from '../domain/types.js';\n\nexport class MeResource implements IMePort {\n constructor(private readonly http: IHttpClient) {}\n\n async getMe(): Promise<User> {\n const res = await this.http.request<Record<string, unknown>>({\n method: 'GET',\n path: '/me',\n });\n const u = (res['user'] ?? res) as Record<string, unknown>;\n return {\n id: String(u['id'] ?? ''),\n email: typeof u['email'] === 'string' ? u['email'] : undefined,\n name: typeof u['name'] === 'string' ? u['name'] : undefined,\n };\n }\n\n async getPlan(): Promise<Plan> {\n const res = await this.http.request<Record<string, unknown>>({\n method: 'GET',\n path: '/me/plan',\n });\n return {\n name: String(res['name'] ?? ''),\n planType: typeof res['planType'] === 'string' ? res['planType'] : undefined,\n };\n }\n}\n","import { PabiloHttpClient } from './infrastructure/pabilo-http-client.js';\nimport { BankAccountsResource } from './resources/bank-accounts.resource.js';\nimport { PaymentLinksResource } from './resources/payment-links.resource.js';\nimport { PaymentsResource } from './resources/payments.resource.js';\nimport { MeResource } from './resources/me.resource.js';\nimport type { IHttpClient } from './ports/http.js';\nimport type { IBankAccountsPort } from './ports/bank-accounts.js';\nimport type { IPaymentLinksPort } from './ports/payment-links.js';\nimport type { IPaymentsPort } from './ports/payments.js';\nimport type { IMePort } from './ports/me.js';\n\nexport interface PabiloClientOptions {\n apiKey: string;\n baseUrl?: string;\n httpClient?: IHttpClient;\n}\n\nexport class PabiloClient {\n readonly me: IMePort;\n readonly bankAccounts: IBankAccountsPort;\n readonly paymentLinks: IPaymentLinksPort;\n readonly payments: IPaymentsPort;\n\n constructor(options: PabiloClientOptions) {\n const http: IHttpClient = options.httpClient ?? new PabiloHttpClient({\n apiKey: options.apiKey,\n ...(options.baseUrl !== undefined ? { baseUrl: options.baseUrl } : {}),\n });\n\n this.me = new MeResource(http);\n this.bankAccounts = new BankAccountsResource(http);\n this.paymentLinks = new PaymentLinksResource(http);\n this.payments = new PaymentsResource(http);\n }\n}\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@pabilo/sdk",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Official TypeScript SDK for the Pabilo payment platform",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"keywords": ["pabilo", "payments", "venezuela", "pago-movil", "sdk"],
|
|
7
|
+
"type": "module",
|
|
8
|
+
"main": "./dist/index.cjs",
|
|
9
|
+
"module": "./dist/index.js",
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"import": {
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"default": "./dist/index.js"
|
|
16
|
+
},
|
|
17
|
+
"require": {
|
|
18
|
+
"types": "./dist/index.d.cts",
|
|
19
|
+
"default": "./dist/index.cjs"
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
"files": ["dist"],
|
|
24
|
+
"sideEffects": false,
|
|
25
|
+
"scripts": {
|
|
26
|
+
"build": "tsup",
|
|
27
|
+
"dev": "tsup --watch",
|
|
28
|
+
"typecheck": "tsc --noEmit",
|
|
29
|
+
"test": "vitest run",
|
|
30
|
+
"test:watch": "vitest",
|
|
31
|
+
"clean": "rimraf dist"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"tsup": "^8.0.0",
|
|
35
|
+
"typescript": "^5.0.0",
|
|
36
|
+
"vitest": "^2.0.0",
|
|
37
|
+
"rimraf": "^5.0.0"
|
|
38
|
+
}
|
|
39
|
+
}
|