kobana 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/README.md +230 -0
- package/dist/index.d.mts +443 -0
- package/dist/index.d.ts +443 -0
- package/dist/index.js +863 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +843 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +65 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,863 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var axios = require('axios');
|
|
4
|
+
|
|
5
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
6
|
+
|
|
7
|
+
var axios__default = /*#__PURE__*/_interopDefault(axios);
|
|
8
|
+
|
|
9
|
+
// src/configuration.ts
|
|
10
|
+
var BASE_URLS = {
|
|
11
|
+
v1: {
|
|
12
|
+
sandbox: "https://api-sandbox.kobana.com.br/v1",
|
|
13
|
+
production: "https://api.kobana.com.br/v1"
|
|
14
|
+
},
|
|
15
|
+
v2: {
|
|
16
|
+
sandbox: "https://api-sandbox.kobana.com.br/v2",
|
|
17
|
+
production: "https://api.kobana.com.br/v2"
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
var Configuration = class {
|
|
21
|
+
apiToken;
|
|
22
|
+
environment;
|
|
23
|
+
apiVersion;
|
|
24
|
+
customHeaders;
|
|
25
|
+
debug;
|
|
26
|
+
constructor(options) {
|
|
27
|
+
this.apiToken = options.apiToken;
|
|
28
|
+
this.environment = options.environment || "sandbox";
|
|
29
|
+
this.apiVersion = options.apiVersion || "v1";
|
|
30
|
+
this.customHeaders = options.customHeaders || {};
|
|
31
|
+
this.debug = options.debug || false;
|
|
32
|
+
}
|
|
33
|
+
getBaseUrl() {
|
|
34
|
+
return BASE_URLS[this.apiVersion][this.environment];
|
|
35
|
+
}
|
|
36
|
+
getHeaders() {
|
|
37
|
+
return {
|
|
38
|
+
Authorization: `Bearer ${this.apiToken}`,
|
|
39
|
+
"Content-Type": "application/json",
|
|
40
|
+
Accept: "application/json",
|
|
41
|
+
...this.customHeaders
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
toString() {
|
|
45
|
+
return `Configuration { environment: ${this.environment}, apiVersion: ${this.apiVersion}, apiToken: [REDACTED] }`;
|
|
46
|
+
}
|
|
47
|
+
toJSON() {
|
|
48
|
+
return {
|
|
49
|
+
environment: this.environment,
|
|
50
|
+
apiVersion: this.apiVersion,
|
|
51
|
+
customHeaders: this.customHeaders,
|
|
52
|
+
debug: this.debug,
|
|
53
|
+
apiToken: "[REDACTED]"
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
// src/errors.ts
|
|
59
|
+
var KobanaError = class _KobanaError extends Error {
|
|
60
|
+
constructor(message) {
|
|
61
|
+
super(message);
|
|
62
|
+
this.name = "KobanaError";
|
|
63
|
+
Object.setPrototypeOf(this, _KobanaError.prototype);
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
var ConfigurationError = class _ConfigurationError extends KobanaError {
|
|
67
|
+
constructor(message) {
|
|
68
|
+
super(message);
|
|
69
|
+
this.name = "ConfigurationError";
|
|
70
|
+
Object.setPrototypeOf(this, _ConfigurationError.prototype);
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
var ConnectionError = class _ConnectionError extends KobanaError {
|
|
74
|
+
constructor(message) {
|
|
75
|
+
super(message);
|
|
76
|
+
this.name = "ConnectionError";
|
|
77
|
+
Object.setPrototypeOf(this, _ConnectionError.prototype);
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
var ResourceNotFoundError = class _ResourceNotFoundError extends KobanaError {
|
|
81
|
+
constructor(message = "Resource not found") {
|
|
82
|
+
super(message);
|
|
83
|
+
this.name = "ResourceNotFoundError";
|
|
84
|
+
Object.setPrototypeOf(this, _ResourceNotFoundError.prototype);
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
var UnauthorizedError = class _UnauthorizedError extends KobanaError {
|
|
88
|
+
constructor(message = "Unauthorized: Invalid or missing API token") {
|
|
89
|
+
super(message);
|
|
90
|
+
this.name = "UnauthorizedError";
|
|
91
|
+
Object.setPrototypeOf(this, _UnauthorizedError.prototype);
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
var ValidationError = class _ValidationError extends KobanaError {
|
|
95
|
+
errors;
|
|
96
|
+
constructor(message, errors = []) {
|
|
97
|
+
super(message);
|
|
98
|
+
this.name = "ValidationError";
|
|
99
|
+
this.errors = errors;
|
|
100
|
+
Object.setPrototypeOf(this, _ValidationError.prototype);
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
var APIError = class _APIError extends KobanaError {
|
|
104
|
+
status;
|
|
105
|
+
responseBody;
|
|
106
|
+
errors;
|
|
107
|
+
constructor(options) {
|
|
108
|
+
const message = options.message || `API request failed with status ${options.status}`;
|
|
109
|
+
super(message);
|
|
110
|
+
this.name = "APIError";
|
|
111
|
+
this.status = options.status;
|
|
112
|
+
this.responseBody = options.responseBody;
|
|
113
|
+
this.errors = options.errors || [];
|
|
114
|
+
Object.setPrototypeOf(this, _APIError.prototype);
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
// src/utils/string.ts
|
|
119
|
+
function toSnakeCase(str) {
|
|
120
|
+
return str.replace(/([A-Z])/g, "_$1").toLowerCase().replace(/^_/, "");
|
|
121
|
+
}
|
|
122
|
+
function toCamelCase(str) {
|
|
123
|
+
return str.replace(/_([a-z])/g, (_, letter) => letter.toUpperCase());
|
|
124
|
+
}
|
|
125
|
+
function interpolate(template, values) {
|
|
126
|
+
return template.replace(/:(\w+)/g, (_, key) => {
|
|
127
|
+
const value = values[key];
|
|
128
|
+
return value !== void 0 ? String(value) : `:${key}`;
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// src/utils/object.ts
|
|
133
|
+
function transformKeys(obj, transformer) {
|
|
134
|
+
if (obj === null || typeof obj !== "object") {
|
|
135
|
+
return obj;
|
|
136
|
+
}
|
|
137
|
+
if (Array.isArray(obj)) {
|
|
138
|
+
return obj.map(
|
|
139
|
+
(item) => typeof item === "object" && item !== null ? transformKeys(item, transformer) : item
|
|
140
|
+
);
|
|
141
|
+
}
|
|
142
|
+
const result = {};
|
|
143
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
144
|
+
const newKey = transformer(key);
|
|
145
|
+
if (typeof value === "object" && value !== null) {
|
|
146
|
+
result[newKey] = transformKeys(value, transformer);
|
|
147
|
+
} else {
|
|
148
|
+
result[newKey] = value;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
return result;
|
|
152
|
+
}
|
|
153
|
+
function keysToSnakeCase(obj) {
|
|
154
|
+
return transformKeys(obj, toSnakeCase);
|
|
155
|
+
}
|
|
156
|
+
function keysToCamelCase(obj) {
|
|
157
|
+
return transformKeys(obj, toCamelCase);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// src/resources/connection.ts
|
|
161
|
+
var Connection = class {
|
|
162
|
+
axiosInstance = null;
|
|
163
|
+
configuration;
|
|
164
|
+
constructor(configuration) {
|
|
165
|
+
this.configuration = configuration;
|
|
166
|
+
}
|
|
167
|
+
getAxiosInstance() {
|
|
168
|
+
if (this.axiosInstance && !this.configuration.debug) {
|
|
169
|
+
return this.axiosInstance;
|
|
170
|
+
}
|
|
171
|
+
this.axiosInstance = axios__default.default.create({
|
|
172
|
+
baseURL: this.configuration.getBaseUrl(),
|
|
173
|
+
headers: this.configuration.getHeaders(),
|
|
174
|
+
timeout: 3e4
|
|
175
|
+
});
|
|
176
|
+
return this.axiosInstance;
|
|
177
|
+
}
|
|
178
|
+
async request(method, url, data, options = {}) {
|
|
179
|
+
const config = {
|
|
180
|
+
method,
|
|
181
|
+
url
|
|
182
|
+
};
|
|
183
|
+
if (options.idempotencyKey) {
|
|
184
|
+
config.headers = {
|
|
185
|
+
...config.headers,
|
|
186
|
+
"X-Idempotency-Key": options.idempotencyKey
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
if (data) {
|
|
190
|
+
const transformedData = keysToSnakeCase(data);
|
|
191
|
+
if (method === "get") {
|
|
192
|
+
config.params = transformedData;
|
|
193
|
+
} else {
|
|
194
|
+
config.data = transformedData;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
try {
|
|
198
|
+
const response = await this.getAxiosInstance().request(config);
|
|
199
|
+
const responseData = response.data ? keysToCamelCase(response.data) : response.data;
|
|
200
|
+
return {
|
|
201
|
+
data: responseData,
|
|
202
|
+
status: response.status,
|
|
203
|
+
headers: response.headers
|
|
204
|
+
};
|
|
205
|
+
} catch (error) {
|
|
206
|
+
throw this.handleError(error);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
async get(url, params, options) {
|
|
210
|
+
return this.request("get", url, params, options);
|
|
211
|
+
}
|
|
212
|
+
async post(url, data, options) {
|
|
213
|
+
return this.request("post", url, data, options);
|
|
214
|
+
}
|
|
215
|
+
async put(url, data, options) {
|
|
216
|
+
return this.request("put", url, data, options);
|
|
217
|
+
}
|
|
218
|
+
async patch(url, data, options) {
|
|
219
|
+
return this.request("patch", url, data, options);
|
|
220
|
+
}
|
|
221
|
+
async delete(url, options) {
|
|
222
|
+
return this.request("delete", url, void 0, options);
|
|
223
|
+
}
|
|
224
|
+
handleError(error) {
|
|
225
|
+
if (axios__default.default.isAxiosError(error)) {
|
|
226
|
+
const axiosError = error;
|
|
227
|
+
if (!axiosError.response) {
|
|
228
|
+
return new ConnectionError(
|
|
229
|
+
axiosError.message || "Network error: Unable to connect to API"
|
|
230
|
+
);
|
|
231
|
+
}
|
|
232
|
+
const { status, data } = axiosError.response;
|
|
233
|
+
const errors = [];
|
|
234
|
+
if (data?.errors && Array.isArray(data.errors)) {
|
|
235
|
+
errors.push(...data.errors.map((e) => e.message || String(e)));
|
|
236
|
+
} else if (data?.error) {
|
|
237
|
+
errors.push(data.error);
|
|
238
|
+
} else if (data?.message) {
|
|
239
|
+
errors.push(data.message);
|
|
240
|
+
}
|
|
241
|
+
switch (status) {
|
|
242
|
+
case 401:
|
|
243
|
+
return new UnauthorizedError(errors[0]);
|
|
244
|
+
case 404:
|
|
245
|
+
return new ResourceNotFoundError(errors[0]);
|
|
246
|
+
default:
|
|
247
|
+
return new APIError({
|
|
248
|
+
status,
|
|
249
|
+
responseBody: data,
|
|
250
|
+
errors,
|
|
251
|
+
message: errors[0]
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
if (error instanceof Error) {
|
|
256
|
+
return new ConnectionError(error.message);
|
|
257
|
+
}
|
|
258
|
+
return new ConnectionError("An unknown error occurred");
|
|
259
|
+
}
|
|
260
|
+
};
|
|
261
|
+
|
|
262
|
+
// src/resources/base.ts
|
|
263
|
+
var BaseResource = class {
|
|
264
|
+
static resourceEndpoint = "";
|
|
265
|
+
static primaryKeyField = "id";
|
|
266
|
+
static _connection;
|
|
267
|
+
_connection;
|
|
268
|
+
_attributes;
|
|
269
|
+
_errors = [];
|
|
270
|
+
_created = false;
|
|
271
|
+
_updated = false;
|
|
272
|
+
constructor(attributes = {}, connection) {
|
|
273
|
+
this._attributes = { ...attributes };
|
|
274
|
+
this._connection = connection;
|
|
275
|
+
}
|
|
276
|
+
static withConnection(connection) {
|
|
277
|
+
const ParentClass = this;
|
|
278
|
+
const BoundClass = class extends ParentClass {
|
|
279
|
+
static _connection = connection;
|
|
280
|
+
constructor(attributes = {}) {
|
|
281
|
+
super(attributes, connection);
|
|
282
|
+
}
|
|
283
|
+
};
|
|
284
|
+
BoundClass.resourceEndpoint = this.resourceEndpoint;
|
|
285
|
+
BoundClass.primaryKeyField = this.primaryKeyField;
|
|
286
|
+
return BoundClass;
|
|
287
|
+
}
|
|
288
|
+
static getConnection() {
|
|
289
|
+
if (!this._connection) {
|
|
290
|
+
throw new Error(
|
|
291
|
+
"No connection available. Use withConnection() or create a client first."
|
|
292
|
+
);
|
|
293
|
+
}
|
|
294
|
+
return this._connection;
|
|
295
|
+
}
|
|
296
|
+
static getUri(attributes = {}) {
|
|
297
|
+
const endpoint = this.resourceEndpoint;
|
|
298
|
+
const id = attributes[this.primaryKeyField];
|
|
299
|
+
if (id !== void 0) {
|
|
300
|
+
return interpolate(`${endpoint}/:${this.primaryKeyField}`, {
|
|
301
|
+
[this.primaryKeyField]: id
|
|
302
|
+
});
|
|
303
|
+
}
|
|
304
|
+
return endpoint;
|
|
305
|
+
}
|
|
306
|
+
static async create(attributes, options) {
|
|
307
|
+
const connection = this.getConnection();
|
|
308
|
+
const response = await connection.post(
|
|
309
|
+
this.resourceEndpoint,
|
|
310
|
+
attributes,
|
|
311
|
+
options
|
|
312
|
+
);
|
|
313
|
+
const instance = new this(response.data, connection);
|
|
314
|
+
instance._created = true;
|
|
315
|
+
return instance;
|
|
316
|
+
}
|
|
317
|
+
static async find(id, params) {
|
|
318
|
+
const connection = this.getConnection();
|
|
319
|
+
const url = this.getUri({ [this.primaryKeyField]: id });
|
|
320
|
+
try {
|
|
321
|
+
const response = await connection.get(url, params);
|
|
322
|
+
return new this(response.data, connection);
|
|
323
|
+
} catch (error) {
|
|
324
|
+
if (error.name === "ResourceNotFoundError") {
|
|
325
|
+
return null;
|
|
326
|
+
}
|
|
327
|
+
throw error;
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
static async all(params) {
|
|
331
|
+
const connection = this.getConnection();
|
|
332
|
+
const response = await connection.get(
|
|
333
|
+
this.resourceEndpoint,
|
|
334
|
+
params
|
|
335
|
+
);
|
|
336
|
+
if (!Array.isArray(response.data)) {
|
|
337
|
+
return [];
|
|
338
|
+
}
|
|
339
|
+
return response.data.map((attrs) => new this(attrs, connection));
|
|
340
|
+
}
|
|
341
|
+
static async findBy(params) {
|
|
342
|
+
const results = await this.all(params);
|
|
343
|
+
return results.length > 0 ? results[0] : null;
|
|
344
|
+
}
|
|
345
|
+
static async findOrCreateBy(params, attributes, options) {
|
|
346
|
+
const existing = await this.findBy(params);
|
|
347
|
+
if (existing) {
|
|
348
|
+
return existing;
|
|
349
|
+
}
|
|
350
|
+
return this.create({ ...params, ...attributes }, options);
|
|
351
|
+
}
|
|
352
|
+
get attributes() {
|
|
353
|
+
return { ...this._attributes };
|
|
354
|
+
}
|
|
355
|
+
get errors() {
|
|
356
|
+
return [...this._errors];
|
|
357
|
+
}
|
|
358
|
+
get(key) {
|
|
359
|
+
return this._attributes[key];
|
|
360
|
+
}
|
|
361
|
+
set(key, value) {
|
|
362
|
+
this._attributes[key] = value;
|
|
363
|
+
}
|
|
364
|
+
get id() {
|
|
365
|
+
const Constructor = this.constructor;
|
|
366
|
+
return this._attributes[Constructor.primaryKeyField];
|
|
367
|
+
}
|
|
368
|
+
isNewRecord() {
|
|
369
|
+
return this.id === void 0;
|
|
370
|
+
}
|
|
371
|
+
isCreated() {
|
|
372
|
+
return this._created;
|
|
373
|
+
}
|
|
374
|
+
isUpdated() {
|
|
375
|
+
return this._updated;
|
|
376
|
+
}
|
|
377
|
+
isValid() {
|
|
378
|
+
return this._errors.length === 0;
|
|
379
|
+
}
|
|
380
|
+
getUri() {
|
|
381
|
+
const Constructor = this.constructor;
|
|
382
|
+
return Constructor.getUri(this._attributes);
|
|
383
|
+
}
|
|
384
|
+
getConnection() {
|
|
385
|
+
if (!this._connection) {
|
|
386
|
+
const Constructor = this.constructor;
|
|
387
|
+
return Constructor.getConnection();
|
|
388
|
+
}
|
|
389
|
+
return this._connection;
|
|
390
|
+
}
|
|
391
|
+
async save(options) {
|
|
392
|
+
const connection = this.getConnection();
|
|
393
|
+
const Constructor = this.constructor;
|
|
394
|
+
if (this.isNewRecord()) {
|
|
395
|
+
const response = await connection.post(
|
|
396
|
+
Constructor.resourceEndpoint,
|
|
397
|
+
this._attributes,
|
|
398
|
+
options
|
|
399
|
+
);
|
|
400
|
+
this._attributes = response.data;
|
|
401
|
+
this._created = true;
|
|
402
|
+
} else {
|
|
403
|
+
const response = await connection.put(
|
|
404
|
+
this.getUri(),
|
|
405
|
+
this._attributes,
|
|
406
|
+
options
|
|
407
|
+
);
|
|
408
|
+
this._attributes = response.data;
|
|
409
|
+
this._updated = true;
|
|
410
|
+
}
|
|
411
|
+
return this;
|
|
412
|
+
}
|
|
413
|
+
async update(newAttributes, options) {
|
|
414
|
+
this._attributes = { ...this._attributes, ...newAttributes };
|
|
415
|
+
const connection = this.getConnection();
|
|
416
|
+
const response = await connection.put(
|
|
417
|
+
this.getUri(),
|
|
418
|
+
this._attributes,
|
|
419
|
+
options
|
|
420
|
+
);
|
|
421
|
+
this._attributes = response.data;
|
|
422
|
+
this._updated = true;
|
|
423
|
+
return this;
|
|
424
|
+
}
|
|
425
|
+
async delete() {
|
|
426
|
+
const connection = this.getConnection();
|
|
427
|
+
try {
|
|
428
|
+
await connection.delete(this.getUri());
|
|
429
|
+
return true;
|
|
430
|
+
} catch {
|
|
431
|
+
return false;
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
toJSON() {
|
|
435
|
+
return this.attributes;
|
|
436
|
+
}
|
|
437
|
+
};
|
|
438
|
+
|
|
439
|
+
// src/resources/charge/pix.ts
|
|
440
|
+
var Pix = class extends BaseResource {
|
|
441
|
+
static resourceEndpoint = "/charge/pix";
|
|
442
|
+
get amount() {
|
|
443
|
+
return this.get("amount");
|
|
444
|
+
}
|
|
445
|
+
get expireAt() {
|
|
446
|
+
return this.get("expireAt");
|
|
447
|
+
}
|
|
448
|
+
get status() {
|
|
449
|
+
return this.get("status");
|
|
450
|
+
}
|
|
451
|
+
get customerPersonName() {
|
|
452
|
+
return this.get("customerPersonName");
|
|
453
|
+
}
|
|
454
|
+
get customerCnpjCpf() {
|
|
455
|
+
return this.get("customerCnpjCpf");
|
|
456
|
+
}
|
|
457
|
+
get customerEmail() {
|
|
458
|
+
return this.get("customerEmail");
|
|
459
|
+
}
|
|
460
|
+
get customerPhoneNumber() {
|
|
461
|
+
return this.get("customerPhoneNumber");
|
|
462
|
+
}
|
|
463
|
+
get description() {
|
|
464
|
+
return this.get("description");
|
|
465
|
+
}
|
|
466
|
+
get meta() {
|
|
467
|
+
return this.get("meta");
|
|
468
|
+
}
|
|
469
|
+
get qrCode() {
|
|
470
|
+
return this.get("qrCode");
|
|
471
|
+
}
|
|
472
|
+
get qrCodeUrl() {
|
|
473
|
+
return this.get("qrCodeUrl");
|
|
474
|
+
}
|
|
475
|
+
get copyPaste() {
|
|
476
|
+
return this.get("copyPaste");
|
|
477
|
+
}
|
|
478
|
+
get txid() {
|
|
479
|
+
return this.get("txid");
|
|
480
|
+
}
|
|
481
|
+
get paidAt() {
|
|
482
|
+
return this.get("paidAt");
|
|
483
|
+
}
|
|
484
|
+
get paidAmount() {
|
|
485
|
+
return this.get("paidAmount");
|
|
486
|
+
}
|
|
487
|
+
get createdAt() {
|
|
488
|
+
return this.get("createdAt");
|
|
489
|
+
}
|
|
490
|
+
get updatedAt() {
|
|
491
|
+
return this.get("updatedAt");
|
|
492
|
+
}
|
|
493
|
+
static async create(attributes, options) {
|
|
494
|
+
return super.create(attributes, options);
|
|
495
|
+
}
|
|
496
|
+
static async find(id, params) {
|
|
497
|
+
return super.find(id, params);
|
|
498
|
+
}
|
|
499
|
+
static async all(params) {
|
|
500
|
+
return super.all(params);
|
|
501
|
+
}
|
|
502
|
+
static async findBy(params) {
|
|
503
|
+
return super.findBy(params);
|
|
504
|
+
}
|
|
505
|
+
isPending() {
|
|
506
|
+
return this.status === "pending";
|
|
507
|
+
}
|
|
508
|
+
isPaid() {
|
|
509
|
+
return this.status === "paid";
|
|
510
|
+
}
|
|
511
|
+
isCanceled() {
|
|
512
|
+
return this.status === "canceled";
|
|
513
|
+
}
|
|
514
|
+
isExpired() {
|
|
515
|
+
return this.status === "expired";
|
|
516
|
+
}
|
|
517
|
+
};
|
|
518
|
+
|
|
519
|
+
// src/resources/charge/bank-billet.ts
|
|
520
|
+
var BankBillet = class extends BaseResource {
|
|
521
|
+
static resourceEndpoint = "/bank_billets";
|
|
522
|
+
get amount() {
|
|
523
|
+
return this.get("amount");
|
|
524
|
+
}
|
|
525
|
+
get expireAt() {
|
|
526
|
+
return this.get("expireAt");
|
|
527
|
+
}
|
|
528
|
+
get customerPersonName() {
|
|
529
|
+
return this.get("customerPersonName");
|
|
530
|
+
}
|
|
531
|
+
get customerCnpjCpf() {
|
|
532
|
+
return this.get("customerCnpjCpf");
|
|
533
|
+
}
|
|
534
|
+
get customerState() {
|
|
535
|
+
return this.get("customerState");
|
|
536
|
+
}
|
|
537
|
+
get customerCityName() {
|
|
538
|
+
return this.get("customerCityName");
|
|
539
|
+
}
|
|
540
|
+
get customerZipcode() {
|
|
541
|
+
return this.get("customerZipcode");
|
|
542
|
+
}
|
|
543
|
+
get customerAddress() {
|
|
544
|
+
return this.get("customerAddress");
|
|
545
|
+
}
|
|
546
|
+
get customerNeighborhood() {
|
|
547
|
+
return this.get("customerNeighborhood");
|
|
548
|
+
}
|
|
549
|
+
get customerAddressNumber() {
|
|
550
|
+
return this.get("customerAddressNumber");
|
|
551
|
+
}
|
|
552
|
+
get customerAddressComplement() {
|
|
553
|
+
return this.get("customerAddressComplement");
|
|
554
|
+
}
|
|
555
|
+
get customerPhoneNumber() {
|
|
556
|
+
return this.get("customerPhoneNumber");
|
|
557
|
+
}
|
|
558
|
+
get customerEmail() {
|
|
559
|
+
return this.get("customerEmail");
|
|
560
|
+
}
|
|
561
|
+
get bankBilletAccountId() {
|
|
562
|
+
return this.get("bankBilletAccountId");
|
|
563
|
+
}
|
|
564
|
+
get ourNumber() {
|
|
565
|
+
return this.get("ourNumber");
|
|
566
|
+
}
|
|
567
|
+
get status() {
|
|
568
|
+
return this.get("status");
|
|
569
|
+
}
|
|
570
|
+
get shippingStatus() {
|
|
571
|
+
return this.get("shippingStatus");
|
|
572
|
+
}
|
|
573
|
+
get meta() {
|
|
574
|
+
return this.get("meta");
|
|
575
|
+
}
|
|
576
|
+
get notes() {
|
|
577
|
+
return this.get("notes");
|
|
578
|
+
}
|
|
579
|
+
get instructions() {
|
|
580
|
+
return this.get("instructions");
|
|
581
|
+
}
|
|
582
|
+
get pixEnabled() {
|
|
583
|
+
return this.get("pixEnabled");
|
|
584
|
+
}
|
|
585
|
+
get createdAt() {
|
|
586
|
+
return this.get("createdAt");
|
|
587
|
+
}
|
|
588
|
+
get updatedAt() {
|
|
589
|
+
return this.get("updatedAt");
|
|
590
|
+
}
|
|
591
|
+
static async create(attributes, options) {
|
|
592
|
+
return super.create(attributes, options);
|
|
593
|
+
}
|
|
594
|
+
static async find(id, params) {
|
|
595
|
+
return super.find(id, params);
|
|
596
|
+
}
|
|
597
|
+
static async all(params) {
|
|
598
|
+
return super.all(params);
|
|
599
|
+
}
|
|
600
|
+
static async findBy(params) {
|
|
601
|
+
return super.findBy(params);
|
|
602
|
+
}
|
|
603
|
+
isPending() {
|
|
604
|
+
return this.status === "pending";
|
|
605
|
+
}
|
|
606
|
+
isOpened() {
|
|
607
|
+
return this.status === "opened";
|
|
608
|
+
}
|
|
609
|
+
isPaid() {
|
|
610
|
+
return this.status === "paid";
|
|
611
|
+
}
|
|
612
|
+
isCanceled() {
|
|
613
|
+
return this.status === "canceled";
|
|
614
|
+
}
|
|
615
|
+
isExpired() {
|
|
616
|
+
return this.status === "expired";
|
|
617
|
+
}
|
|
618
|
+
};
|
|
619
|
+
|
|
620
|
+
// src/resources/financial/bank-billet-account.ts
|
|
621
|
+
var BankBilletAccount = class extends BaseResource {
|
|
622
|
+
static resourceEndpoint = "/bank_billet_accounts";
|
|
623
|
+
get bankContractSlug() {
|
|
624
|
+
return this.get("bankContractSlug");
|
|
625
|
+
}
|
|
626
|
+
get nextOurNumber() {
|
|
627
|
+
return this.get("nextOurNumber");
|
|
628
|
+
}
|
|
629
|
+
get agencyNumber() {
|
|
630
|
+
return this.get("agencyNumber");
|
|
631
|
+
}
|
|
632
|
+
get agencyDigit() {
|
|
633
|
+
return this.get("agencyDigit");
|
|
634
|
+
}
|
|
635
|
+
get accountNumber() {
|
|
636
|
+
return this.get("accountNumber");
|
|
637
|
+
}
|
|
638
|
+
get accountDigit() {
|
|
639
|
+
return this.get("accountDigit");
|
|
640
|
+
}
|
|
641
|
+
get extra1() {
|
|
642
|
+
return this.get("extra1");
|
|
643
|
+
}
|
|
644
|
+
get extra1Digit() {
|
|
645
|
+
return this.get("extra1Digit");
|
|
646
|
+
}
|
|
647
|
+
get extra2() {
|
|
648
|
+
return this.get("extra2");
|
|
649
|
+
}
|
|
650
|
+
get extra2Digit() {
|
|
651
|
+
return this.get("extra2Digit");
|
|
652
|
+
}
|
|
653
|
+
get beneficiaryName() {
|
|
654
|
+
return this.get("beneficiaryName");
|
|
655
|
+
}
|
|
656
|
+
get beneficiaryCnpjCpf() {
|
|
657
|
+
return this.get("beneficiaryCnpjCpf");
|
|
658
|
+
}
|
|
659
|
+
get beneficiaryAddress() {
|
|
660
|
+
return this.get("beneficiaryAddress");
|
|
661
|
+
}
|
|
662
|
+
get name() {
|
|
663
|
+
return this.get("name");
|
|
664
|
+
}
|
|
665
|
+
get status() {
|
|
666
|
+
return this.get("status");
|
|
667
|
+
}
|
|
668
|
+
get homologatedAt() {
|
|
669
|
+
return this.get("homologatedAt");
|
|
670
|
+
}
|
|
671
|
+
get nextRemittanceNumber() {
|
|
672
|
+
return this.get("nextRemittanceNumber");
|
|
673
|
+
}
|
|
674
|
+
get configuration() {
|
|
675
|
+
return this.get("configuration");
|
|
676
|
+
}
|
|
677
|
+
get createdAt() {
|
|
678
|
+
return this.get("createdAt");
|
|
679
|
+
}
|
|
680
|
+
get updatedAt() {
|
|
681
|
+
return this.get("updatedAt");
|
|
682
|
+
}
|
|
683
|
+
static async create(attributes, options) {
|
|
684
|
+
return super.create(attributes, options);
|
|
685
|
+
}
|
|
686
|
+
static async find(id, params) {
|
|
687
|
+
return super.find(id, params);
|
|
688
|
+
}
|
|
689
|
+
static async all(params) {
|
|
690
|
+
return super.all(params);
|
|
691
|
+
}
|
|
692
|
+
static async findBy(params) {
|
|
693
|
+
return super.findBy(params);
|
|
694
|
+
}
|
|
695
|
+
async askHomologation() {
|
|
696
|
+
const connection = this.getConnection();
|
|
697
|
+
const response = await connection.get(
|
|
698
|
+
`${this.getUri()}/ask`
|
|
699
|
+
);
|
|
700
|
+
this._attributes = response.data;
|
|
701
|
+
return this;
|
|
702
|
+
}
|
|
703
|
+
async validate() {
|
|
704
|
+
const connection = this.getConnection();
|
|
705
|
+
const response = await connection.put(
|
|
706
|
+
`${this.getUri()}/validate`,
|
|
707
|
+
{}
|
|
708
|
+
);
|
|
709
|
+
this._attributes = response.data;
|
|
710
|
+
return this;
|
|
711
|
+
}
|
|
712
|
+
async setDefault() {
|
|
713
|
+
const connection = this.getConnection();
|
|
714
|
+
const response = await connection.put(
|
|
715
|
+
`${this.getUri()}/set_default`,
|
|
716
|
+
{}
|
|
717
|
+
);
|
|
718
|
+
this._attributes = response.data;
|
|
719
|
+
return this;
|
|
720
|
+
}
|
|
721
|
+
isPending() {
|
|
722
|
+
return this.status === "pending";
|
|
723
|
+
}
|
|
724
|
+
isHomologating() {
|
|
725
|
+
return this.status === "homologating";
|
|
726
|
+
}
|
|
727
|
+
isActive() {
|
|
728
|
+
return this.status === "active";
|
|
729
|
+
}
|
|
730
|
+
isHomologated() {
|
|
731
|
+
return this.homologatedAt !== void 0;
|
|
732
|
+
}
|
|
733
|
+
};
|
|
734
|
+
|
|
735
|
+
// src/client.ts
|
|
736
|
+
function createChargeProxy(connection) {
|
|
737
|
+
let pixResource = null;
|
|
738
|
+
let bankBilletResource = null;
|
|
739
|
+
return {
|
|
740
|
+
get pix() {
|
|
741
|
+
if (!pixResource) {
|
|
742
|
+
pixResource = Pix.withConnection(connection);
|
|
743
|
+
}
|
|
744
|
+
return pixResource;
|
|
745
|
+
},
|
|
746
|
+
get bankBillet() {
|
|
747
|
+
if (!bankBilletResource) {
|
|
748
|
+
bankBilletResource = BankBillet.withConnection(connection);
|
|
749
|
+
}
|
|
750
|
+
return bankBilletResource;
|
|
751
|
+
}
|
|
752
|
+
};
|
|
753
|
+
}
|
|
754
|
+
function createFinancialProxy(connection) {
|
|
755
|
+
let bankBilletAccountResource = null;
|
|
756
|
+
return {
|
|
757
|
+
get bankBilletAccount() {
|
|
758
|
+
if (!bankBilletAccountResource) {
|
|
759
|
+
bankBilletAccountResource = BankBilletAccount.withConnection(
|
|
760
|
+
connection
|
|
761
|
+
);
|
|
762
|
+
}
|
|
763
|
+
return bankBilletAccountResource;
|
|
764
|
+
}
|
|
765
|
+
};
|
|
766
|
+
}
|
|
767
|
+
var KobanaClient = class {
|
|
768
|
+
_configuration;
|
|
769
|
+
_connection;
|
|
770
|
+
_chargeProxy = null;
|
|
771
|
+
_financialProxy = null;
|
|
772
|
+
constructor(options) {
|
|
773
|
+
this._configuration = new Configuration(options);
|
|
774
|
+
this._connection = new Connection(this._configuration);
|
|
775
|
+
}
|
|
776
|
+
get configuration() {
|
|
777
|
+
return this._configuration;
|
|
778
|
+
}
|
|
779
|
+
configure(options) {
|
|
780
|
+
if (options.apiToken !== void 0) {
|
|
781
|
+
this._configuration.apiToken = options.apiToken;
|
|
782
|
+
}
|
|
783
|
+
if (options.environment !== void 0) {
|
|
784
|
+
this._configuration.environment = options.environment;
|
|
785
|
+
}
|
|
786
|
+
if (options.apiVersion !== void 0) {
|
|
787
|
+
this._configuration.apiVersion = options.apiVersion;
|
|
788
|
+
}
|
|
789
|
+
if (options.customHeaders !== void 0) {
|
|
790
|
+
this._configuration.customHeaders = options.customHeaders;
|
|
791
|
+
}
|
|
792
|
+
if (options.debug !== void 0) {
|
|
793
|
+
this._configuration.debug = options.debug;
|
|
794
|
+
}
|
|
795
|
+
this._connection = new Connection(this._configuration);
|
|
796
|
+
this._chargeProxy = null;
|
|
797
|
+
this._financialProxy = null;
|
|
798
|
+
}
|
|
799
|
+
get charge() {
|
|
800
|
+
if (!this._chargeProxy) {
|
|
801
|
+
this._chargeProxy = createChargeProxy(this._connection);
|
|
802
|
+
}
|
|
803
|
+
return this._chargeProxy;
|
|
804
|
+
}
|
|
805
|
+
get financial() {
|
|
806
|
+
if (!this._financialProxy) {
|
|
807
|
+
this._financialProxy = createFinancialProxy(this._connection);
|
|
808
|
+
}
|
|
809
|
+
return this._financialProxy;
|
|
810
|
+
}
|
|
811
|
+
};
|
|
812
|
+
var globalConfiguration = null;
|
|
813
|
+
var globalConnection = null;
|
|
814
|
+
var globalChargeProxy = null;
|
|
815
|
+
var globalFinancialProxy = null;
|
|
816
|
+
function getGlobalConnection() {
|
|
817
|
+
if (!globalConnection) {
|
|
818
|
+
throw new Error("Kobana not configured. Call Kobana.configure() first.");
|
|
819
|
+
}
|
|
820
|
+
return globalConnection;
|
|
821
|
+
}
|
|
822
|
+
var Kobana = {
|
|
823
|
+
configure(options) {
|
|
824
|
+
globalConfiguration = new Configuration(options);
|
|
825
|
+
globalConnection = new Connection(globalConfiguration);
|
|
826
|
+
globalChargeProxy = null;
|
|
827
|
+
globalFinancialProxy = null;
|
|
828
|
+
},
|
|
829
|
+
get configuration() {
|
|
830
|
+
return globalConfiguration;
|
|
831
|
+
},
|
|
832
|
+
get charge() {
|
|
833
|
+
if (!globalChargeProxy) {
|
|
834
|
+
globalChargeProxy = createChargeProxy(getGlobalConnection());
|
|
835
|
+
}
|
|
836
|
+
return globalChargeProxy;
|
|
837
|
+
},
|
|
838
|
+
get financial() {
|
|
839
|
+
if (!globalFinancialProxy) {
|
|
840
|
+
globalFinancialProxy = createFinancialProxy(getGlobalConnection());
|
|
841
|
+
}
|
|
842
|
+
return globalFinancialProxy;
|
|
843
|
+
},
|
|
844
|
+
Client: KobanaClient
|
|
845
|
+
};
|
|
846
|
+
|
|
847
|
+
exports.APIError = APIError;
|
|
848
|
+
exports.BankBillet = BankBillet;
|
|
849
|
+
exports.BankBilletAccount = BankBilletAccount;
|
|
850
|
+
exports.BaseResource = BaseResource;
|
|
851
|
+
exports.Configuration = Configuration;
|
|
852
|
+
exports.ConfigurationError = ConfigurationError;
|
|
853
|
+
exports.Connection = Connection;
|
|
854
|
+
exports.ConnectionError = ConnectionError;
|
|
855
|
+
exports.Kobana = Kobana;
|
|
856
|
+
exports.KobanaClient = KobanaClient;
|
|
857
|
+
exports.KobanaError = KobanaError;
|
|
858
|
+
exports.Pix = Pix;
|
|
859
|
+
exports.ResourceNotFoundError = ResourceNotFoundError;
|
|
860
|
+
exports.UnauthorizedError = UnauthorizedError;
|
|
861
|
+
exports.ValidationError = ValidationError;
|
|
862
|
+
//# sourceMappingURL=index.js.map
|
|
863
|
+
//# sourceMappingURL=index.js.map
|